Skip to content

Commit

Permalink
feat: added support for commitAll option in CLI (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
benmonro authored and bcoe committed Oct 6, 2016
1 parent 0ee080f commit a903f4d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ var argv = require('yargs')
default: defaults.noVerify,
global: true
})
.option('commit-all', {
alias: 'a',
describe: 'Commit all staged changes, not just files affected by standard-version',
type: 'boolean',
default: defaults.commitAll,
global: true
})
.option('silent', {
describe: 'Don\'t print logs and errors',
type: 'boolean',
Expand Down
1 change: 1 addition & 0 deletions defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
"firstRelease": false,
"sign": false,
"noVerify": false,
"commitAll": false,
"silent": false
}
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ function outputChangelog (argv, cb) {

function handledExec (argv, cmd, errorCb, successCb) {
// Exec given cmd and handle possible errors

exec(cmd, function (err, stdout, stderr) {
// If exec returns content in stderr, but no error, print it as a warning
// If exec returns an error, print it and exit with return code 1
Expand All @@ -103,7 +104,7 @@ function commit (argv, newVersion, cb) {
checkpoint(argv, msg, args)

handledExec(argv, 'git add package.json ' + argv.infile, cb, function () {
handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : ('package.json ' + argv.infile)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
cb()
})
})
Expand Down
23 changes: 23 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ describe('cli', function () {
content.should.match(/1\.0\.1/)
content.should.not.match(/legacy header format/)
})

it('commits all staged files', function () {
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')

commit('feat: first commit')
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
commit('fix: patch release')

fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8')

shell.exec('git add STUFF.md')

execCli('--commit-all').code.should.equal(0)

var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
var status = shell.exec('git status')

status.should.match(/On branch master\nnothing to commit, working directory clean\n/)
status.should.not.match(/STUFF.md/)

content.should.match(/1\.0\.1/)
content.should.not.match(/legacy header format/)
})
})

describe('with mocked git', function () {
Expand Down

0 comments on commit a903f4d

Please sign in to comment.