Skip to content

Commit

Permalink
fix(commit): fix windows by separating add and commit exec (#55)
Browse files Browse the repository at this point in the history
Windows cmd doesn't support separating commands with ';'. Fix by separating
the execution of the 'git add' and 'git commit' commands. Added separate
test for git add.

Fixes #49
  • Loading branch information
Tapppi authored and nexdrew committed Jun 8, 2016
1 parent 5e56185 commit f361c46
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
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)
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

0 comments on commit f361c46

Please sign in to comment.