From 3e4fdecdb8e30b3e59c8682be64b7c18d3ff4175 Mon Sep 17 00:00:00 2001 From: Georgios Kaleadis Date: Fri, 10 May 2019 17:28:15 +0200 Subject: [PATCH] fix(commit): don't try to process and add changelog if skipped (#318) --- lib/lifecycles/commit.js | 25 +++++++++++++++++++++---- test.js | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/lifecycles/commit.js b/lib/lifecycles/commit.js index 86d443203..fe4c015ce 100644 --- a/lib/lifecycles/commit.js +++ b/lib/lifecycles/commit.js @@ -19,15 +19,26 @@ module.exports = function (args, newVersion) { function execCommit (args, newVersion) { let msg = 'committing %s' - let paths = [args.infile] + let paths = [] let verify = args.verify === false || args.n ? '--no-verify ' : '' let toAdd = '' + + // only start with a pre-populated paths list when CHANGELOG processing is not skipped + if (!args.skip.changelog) { + paths = [args.infile] + toAdd += ' ' + args.infile + } + // commit any of the config files that we've updated // the version # for. Object.keys(bump.getUpdatedConfigs()).forEach(function (p) { - msg += ' and %s' paths.unshift(p) toAdd += ' ' + path.relative(process.cwd(), p) + + // account for multiple files in the output message + if (paths.length > 1) { + msg += ' and %s' + } }) if (args.commitAll) { @@ -36,8 +47,14 @@ function execCommit (args, newVersion) { } checkpoint(args, msg, paths) - return runExec(args, 'git add' + toAdd + ' ' + args.infile) + + // nothing to do, exit without commit anything + if (args.skip.changelog && args.skip.bump && toAdd.length === 0) { + return Promise.resolve() + } + + return runExec(args, 'git add' + toAdd) .then(() => { - return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (args.infile + toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"') + return runExec(args, 'git commit ' + verify + (args.sign ? '-S ' : '') + (args.commitAll ? '' : (toAdd)) + ' -m "' + formatCommitMessage(args.message, newVersion) + '"') }) } diff --git a/test.js b/test.js index 2aac18a1f..370e658cc 100644 --- a/test.js +++ b/test.js @@ -149,6 +149,24 @@ describe('cli', function () { content.should.match(/first commit/) shell.exec('git tag').stdout.should.match(/1\.0\.1/) }) + + it('skipping changelog will not create a changelog file', function () { + writePackageJson('1.0.0') + + commit('feat: first commit') + return execCliAsync('--skip.changelog true') + .then(function () { + getPackageVersion().should.equal('1.1.0') + let fileNotFound = false + try { + fs.readFileSync('CHANGELOG.md', 'utf-8') + } catch (err) { + fileNotFound = true + } + + fileNotFound.should.equal(true) + }) + }) }) describe('CHANGELOG.md exists', function () {