Skip to content

Commit 3e4fdec

Browse files
georgieebcoe
authored andcommitted
fix(commit): don't try to process and add changelog if skipped (#318)
1 parent f586844 commit 3e4fdec

File tree

2 files changed

+39
-4
lines changed

2 files changed

+39
-4
lines changed

lib/lifecycles/commit.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,26 @@ module.exports = function (args, newVersion) {
1919

2020
function execCommit (args, newVersion) {
2121
let msg = 'committing %s'
22-
let paths = [args.infile]
22+
let paths = []
2323
let verify = args.verify === false || args.n ? '--no-verify ' : ''
2424
let toAdd = ''
25+
26+
// only start with a pre-populated paths list when CHANGELOG processing is not skipped
27+
if (!args.skip.changelog) {
28+
paths = [args.infile]
29+
toAdd += ' ' + args.infile
30+
}
31+
2532
// commit any of the config files that we've updated
2633
// the version # for.
2734
Object.keys(bump.getUpdatedConfigs()).forEach(function (p) {
28-
msg += ' and %s'
2935
paths.unshift(p)
3036
toAdd += ' ' + path.relative(process.cwd(), p)
37+
38+
// account for multiple files in the output message
39+
if (paths.length > 1) {
40+
msg += ' and %s'
41+
}
3142
})
3243

3344
if (args.commitAll) {
@@ -36,8 +47,14 @@ function execCommit (args, newVersion) {
3647
}
3748

3849
checkpoint(args, msg, paths)
39-
return runExec(args, 'git add' + toAdd + ' ' + args.infile)
50+
51+
// nothing to do, exit without commit anything
52+
if (args.skip.changelog && args.skip.bump && toAdd.length === 0) {
53+
return Promise.resolve()
54+
}
55+
56+
return runExec(args, 'git add' + toAdd)
4057
.then(() => {
41-
return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (args.infile + toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"')
58+
return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"')
4259
})
4360
}

test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,24 @@ describe('cli', function () {
149149
content.should.match(/first commit/)
150150
shell.exec('git tag').stdout.should.match(/1\.0\.1/)
151151
})
152+
153+
it('skipping changelog will not create a changelog file', function () {
154+
writePackageJson('1.0.0')
155+
156+
commit('feat: first commit')
157+
return execCliAsync('--skip.changelog true')
158+
.then(function () {
159+
getPackageVersion().should.equal('1.1.0')
160+
let fileNotFound = false
161+
try {
162+
fs.readFileSync('CHANGELOG.md', 'utf-8')
163+
} catch (err) {
164+
fileNotFound = true
165+
}
166+
167+
fileNotFound.should.equal(true)
168+
})
169+
})
152170
})
153171

154172
describe('CHANGELOG.md exists', function () {

0 commit comments

Comments
 (0)