Skip to content

Commit

Permalink
Check if tag exists before creating changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed May 18, 2016
1 parent 4097257 commit c0f3b9e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ function isGitRepo() {
return run('!git', 'rev-parse --git-dir');
}

function tagExists(tag) {
return run('!git', 'show-ref --tags --quiet --verify -- "refs/tags/' + tag + '"').then(function() {
return true;
}, function() {
return false;
});
}

function getRemoteUrl() {
return run('!git', 'config --get remote.origin.url').then(function(result) {
if(result && result.output) {
Expand Down Expand Up @@ -173,11 +181,14 @@ function getGithubToken(tokenRef) {

function getChangelog(options) {
if(options.changelogCommand) {
var prevTag = config.process.get('prevVersion') || options.prevVersion,
command = options.changelogCommand.replace(/\[REV_RANGE\]/, prevTag + '...HEAD');
return run(command).then(function(result) {
config.process.set('changelog', result.output);
return options;
var prevTag = config.process.get('prevVersion') || options.prevVersion;
return tagExists(prevTag).then(function(hasTag) {
var command = options.changelogCommand.replace(/\[REV_RANGE\]/, hasTag ? prevTag + '...HEAD' : '');
return run(command).then(function(result) {
process.stdout.write('\n');
config.process.set('changelog', result.output);
return options;
})
}).catch(function(err) {
log.warn('Probably the current version in package.json is not a known tag in the repository.');
throw new Error('Could not create changelog from latest tag (' + prevTag + ') to HEAD.');
Expand Down

0 comments on commit c0f3b9e

Please sign in to comment.