Skip to content

Commit

Permalink
fix(conventional-changelog-core): fix duplicated commits when from
Browse files Browse the repository at this point in the history
…is specified (#573)


fixes #567
  • Loading branch information
tommywo committed Dec 15, 2019
1 parent 490cda6 commit 287a801
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 21 deletions.
37 changes: 16 additions & 21 deletions packages/conventional-changelog-core/index.js
Expand Up @@ -27,6 +27,15 @@ function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts,

var reverseTags = context.gitSemverTags.slice(0).reverse()
reverseTags.push('HEAD')

if (gitRawCommitsOpts.from) {
if (reverseTags.indexOf(gitRawCommitsOpts.from) !== -1) {
reverseTags = reverseTags.slice(reverseTags.indexOf(gitRawCommitsOpts.from))
} else {
reverseTags = [gitRawCommitsOpts.from, 'HEAD']
}
}

var commitsErrorThrown = false

var commitsStream = new stream.Readable({
Expand All @@ -47,31 +56,17 @@ function conventionalChangelog (options, context, gitRawCommitsOpts, parserOpts,
})
}

const streams = reverseTags.map((to, i) => {
var streams = reverseTags.map((to, i) => {
const from = i > 0
? reverseTags[i - 1]
: gitRawCommitsOpts.from || ''
if (gitRawCommitsOpts.from) {
let hasData = false
return commitsRange(gitRawCommitsOpts.from, to)
.on('data', function () {
hasData = true
})
.pipe(addStream(() => {
if (!hasData) {
const s = new stream.Readable()
s._read = function () { }
s.push(null)
return s
} else {
return commitsRange(from, to)
}
}))
} else {
return commitsRange(from, to)
}
: ''
return commitsRange(from, to)
})

if (gitRawCommitsOpts.from) {
streams = streams.splice(1)
}

if (gitRawCommitsOpts.reverse) {
streams.reverse()
}
Expand Down
22 changes: 22 additions & 0 deletions packages/conventional-changelog-core/test/test.js
Expand Up @@ -803,6 +803,28 @@ describe('conventionalChangelogCore', function () {
}))
})

it('should read each commit range exactly once', function (done) {
preparing(9)

conventionalChangelogCore({
preset: {
compareUrlFormat: '/compare/{{previousTag}}...{{currentTag}}'
}
}, {}, {}, {}, {
headerPartial: '',
commitPartial: '* {{header}}\n'
})
.pipe(through(function (chunk, enc, cb) {
chunk = chunk.toString()

expect(chunk).to.equal('\n* test8\n* test8\n* test9\n\n\n\n')

cb()
}, function () {
done()
}))
})

it('should recreate the changelog from scratch', function (done) {
preparing(10)

Expand Down

0 comments on commit 287a801

Please sign in to comment.