Skip to content

Commit

Permalink
fix(commit): don't try to process and add changelog if skipped (#318)
Browse files Browse the repository at this point in the history
  • Loading branch information
georgiee authored and bcoe committed May 10, 2019
1 parent f586844 commit 3e4fdec
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
25 changes: 21 additions & 4 deletions lib/lifecycles/commit.js
Expand Up @@ -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) {
Expand All @@ -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) + '"')
})
}
18 changes: 18 additions & 0 deletions test.js
Expand Up @@ -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 () {
Expand Down

0 comments on commit 3e4fdec

Please sign in to comment.