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

feat: added support for commitAll option in CLI #121

Merged
merged 5 commits into from
Oct 6, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems a bit unnecessary to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it wasn't intentional. I'll remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I readded the whitespace, not sure why but it's not showing up in the diff here.


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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is a bit messy. I'd like to use a variable. But doesn't have to be in this PR :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can refactor this in a separate PR.

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 () {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the test, thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks :)

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