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): fix windows by separating add and commit exec #55

Merged
merged 1 commit into from
Jun 8, 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
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,21 @@ function commit (argv, newVersion, cb) {
args.unshift('package.json')
}
checkpoint(msg, args)
exec('git add package.json ' + argv.infile + ';git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr

function handleExecError (err, stderr) {
// If exec returns an error or content in stderr, log it and exit with return code 1
var errMessage = stderr || (err && err.message)
if (errMessage) {
console.log(chalk.red(errMessage))
process.exit(1)
}
return cb()
}
exec('git add package.json ' + argv.infile, function (err, stdout, stderr) {
handleExecError(err, stderr)
Copy link
Member

Choose a reason for hiding this comment

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

Now that git add is executed separately from git commit, it would be nice to add a unit test for a git add failure scenario.

exec('git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
handleExecError(err, stderr)
return cb()
})
})
}

Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ describe('cli', function () {
})
})

it('exits with error code if git add fails', function () {
// mock git by throwing on attempt to add
return mockGit('console.error("addition is hard"); process.exit(128);', 'add')
.then(function (unmock) {
writePackageJson('1.0.0')

var result = shell.exec(cliPath)
result.code.should.equal(1)
result.stdout.should.match(/addition is hard/)

unmock()
})
})

it('exits with error code if git tag fails', function () {
// mock git by throwing on attempt to commit
return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag')
Expand Down