Skip to content

Commit f361c46

Browse files
Tapppinexdrew
authored andcommitted
fix(commit): fix windows by separating add and commit exec (#55)
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
1 parent 5e56185 commit f361c46

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,21 @@ function commit (argv, newVersion, cb) {
121121
args.unshift('package.json')
122122
}
123123
checkpoint(msg, args)
124-
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) {
125-
var errMessage = null
126-
if (err) errMessage = err.message
127-
if (stderr) errMessage = stderr
124+
125+
function handleExecError (err, stderr) {
126+
// If exec returns an error or content in stderr, log it and exit with return code 1
127+
var errMessage = stderr || (err && err.message)
128128
if (errMessage) {
129129
console.log(chalk.red(errMessage))
130130
process.exit(1)
131131
}
132-
return cb()
132+
}
133+
exec('git add package.json ' + argv.infile, function (err, stdout, stderr) {
134+
handleExecError(err, stderr)
135+
exec('git commit ' + verify + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
136+
handleExecError(err, stderr)
137+
return cb()
138+
})
133139
})
134140
}
135141

test.js

+14
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,20 @@ describe('cli', function () {
118118
})
119119
})
120120

121+
it('exits with error code if git add fails', function () {
122+
// mock git by throwing on attempt to add
123+
return mockGit('console.error("addition is hard"); process.exit(128);', 'add')
124+
.then(function (unmock) {
125+
writePackageJson('1.0.0')
126+
127+
var result = shell.exec(cliPath)
128+
result.code.should.equal(1)
129+
result.stdout.should.match(/addition is hard/)
130+
131+
unmock()
132+
})
133+
})
134+
121135
it('exits with error code if git tag fails', function () {
122136
// mock git by throwing on attempt to commit
123137
return mockGit('console.error("tag, you\'re it"); process.exit(128);', 'tag')

0 commit comments

Comments
 (0)