Skip to content

Commit

Permalink
Shorten getCommitsSinceLatestTag + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 1, 2019
1 parent f40804a commit add2e1e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/plugin/git/Git.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,7 @@ class Git extends GitBase {

async getCommitsSinceLatestTag() {
const latestTagName = await this.getLatestTagName();
if (latestTagName === null) {
return this.exec(`git rev-list HEAD --count`, { options }).then(Number);
} else {
return this.exec(`git rev-list ${latestTagName}..HEAD --count`, { options }).then(Number);
}
return this.exec(`git rev-list ${latestTagName ? `${latestTagName}..` : ''}HEAD --count`, { options }).then(Number);
}

stage(file) {
Expand Down
7 changes: 7 additions & 0 deletions test/git.init.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ test.serial('should not throw if there are commits', async t => {
await t.notThrowsAsync(gitClient.init());
});

test.serial('should not throw if there are no tags', async t => {
const options = { git: { requireCommits: true } };
const gitClient = factory(Git, { options });
gitAdd('line', 'file', 'Add file');
await t.notThrowsAsync(gitClient.init());
});

test.serial('should get the latest tag after fetch', async t => {
const log = new Log();
const shell = new Shell({ container: { log } });
Expand Down

0 comments on commit add2e1e

Please sign in to comment.