Skip to content

Commit

Permalink
fix(previousTag): incase there is no commits in the first release
Browse files Browse the repository at this point in the history
  • Loading branch information
stevemao committed Aug 3, 2015
1 parent c4b20b1 commit 8d9f363
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
4 changes: 2 additions & 2 deletions index.js
Expand Up @@ -184,9 +184,9 @@ function conventinalChangelog(options, context, gitRawCommitsOpts, parserOpts, w

if (!previousTag) {
if (options.append) {
context.previousTag = context.previousTag || commits[0].hash;
context.previousTag = context.previousTag || commits[0] ? commits[0].hash : null;
} else {
context.previousTag = context.previousTag || commits[commits.length - 1].hash;
context.previousTag = context.previousTag || commits[commits.length - 1] ? commits[commits.length - 1].hash : null;
}
}
} else {
Expand Down
67 changes: 67 additions & 0 deletions test/test.js
Expand Up @@ -399,6 +399,73 @@ describe('conventionalChangelog', function() {
done();
}));
});

it('should still work if first release has no commits (prepend)', function(done) {
shell.exec('git tag v0.0.1 ' + tail);
var i = 0;

conventionalChangelog({
releaseCount: 0
}, {
version: '3.0.0'
}, {}, {}, {
mainTemplate: '{{previousTag}}...{{currentTag}}',
transform: function() {
return null;
}
})
.pipe(through(function(chunk, enc, cb) {
chunk = chunk.toString();

if (i === 0) {
expect(chunk).to.equal('v2.0.0...v3.0.0');
} else if (i === 1) {
expect(chunk).to.equal('v0.0.1...v2.0.0');
} else if (i === 2) {
expect(chunk).to.equal('...v0.0.1');
}

i++;
cb();
}, function() {
expect(i).to.equal(3);
done();
}));
});

it('should still work if first release has no commits (append)', function(done) {
shell.exec('git tag v0.0.1 ' + tail);
var i = 0;

conventionalChangelog({
releaseCount: 0,
append: true
}, {
version: '3.0.0'
}, {}, {}, {
mainTemplate: '{{previousTag}}...{{currentTag}}',
transform: function() {
return null;
}
})
.pipe(through(function(chunk, enc, cb) {
chunk = chunk.toString();

if (i === 0) {
expect(chunk).to.equal('...v0.0.1');
} else if (i === 1) {
expect(chunk).to.equal('v0.0.1...v2.0.0');
} else if (i === 2) {
expect(chunk).to.equal('v2.0.0...v3.0.0');
}

i++;
cb();
}, function() {
expect(i).to.equal(3);
done();
}));
});
});

it('should warn if preset is not found', function(done) {
Expand Down

0 comments on commit 8d9f363

Please sign in to comment.