Skip to content

Commit a903f4d

Browse files
benmonrobcoe
authored andcommitted
feat: added support for commitAll option in CLI (#121)
1 parent 0ee080f commit a903f4d

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

cli.js

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ var argv = require('yargs')
3838
default: defaults.noVerify,
3939
global: true
4040
})
41+
.option('commit-all', {
42+
alias: 'a',
43+
describe: 'Commit all staged changes, not just files affected by standard-version',
44+
type: 'boolean',
45+
default: defaults.commitAll,
46+
global: true
47+
})
4148
.option('silent', {
4249
describe: 'Don\'t print logs and errors',
4350
type: 'boolean',

defaults.json

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"firstRelease": false,
55
"sign": false,
66
"noVerify": false,
7+
"commitAll": false,
78
"silent": false
89
}

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ function outputChangelog (argv, cb) {
7979

8080
function handledExec (argv, cmd, errorCb, successCb) {
8181
// Exec given cmd and handle possible errors
82+
8283
exec(cmd, function (err, stdout, stderr) {
8384
// If exec returns content in stderr, but no error, print it as a warning
8485
// If exec returns an error, print it and exit with return code 1
@@ -103,7 +104,7 @@ function commit (argv, newVersion, cb) {
103104
checkpoint(argv, msg, args)
104105

105106
handledExec(argv, 'git add package.json ' + argv.infile, cb, function () {
106-
handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
107+
handledExec(argv, 'git commit ' + verify + (argv.sign ? '-S ' : '') + (argv.commitAll ? '' : ('package.json ' + argv.infile)) + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', cb, function () {
107108
cb()
108109
})
109110
})

test.js

+23
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,29 @@ describe('cli', function () {
9292
content.should.match(/1\.0\.1/)
9393
content.should.not.match(/legacy header format/)
9494
})
95+
96+
it('commits all staged files', function () {
97+
fs.writeFileSync('CHANGELOG.md', 'legacy header format<a name="1.0.0">\n', 'utf-8')
98+
99+
commit('feat: first commit')
100+
shell.exec('git tag -a v1.0.0 -m "my awesome first release"')
101+
commit('fix: patch release')
102+
103+
fs.writeFileSync('STUFF.md', 'stuff\n', 'utf-8')
104+
105+
shell.exec('git add STUFF.md')
106+
107+
execCli('--commit-all').code.should.equal(0)
108+
109+
var content = fs.readFileSync('CHANGELOG.md', 'utf-8')
110+
var status = shell.exec('git status')
111+
112+
status.should.match(/On branch master\nnothing to commit, working directory clean\n/)
113+
status.should.not.match(/STUFF.md/)
114+
115+
content.should.match(/1\.0\.1/)
116+
content.should.not.match(/legacy header format/)
117+
})
95118
})
96119

97120
describe('with mocked git', function () {

0 commit comments

Comments
 (0)