Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(commit): don't try to process or to add changelog if it's skipped #318

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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