Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
fix(CLI): correctly exit with 1 when validation fails
Browse files Browse the repository at this point in the history
Addresses a bug introduces with the PR #92 where the CLI wasn't exiting the process anymore in case of error
  • Loading branch information
nickbalestra authored and Garbee committed Jul 23, 2017
1 parent 6d23bbc commit 888617b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
12 changes: 4 additions & 8 deletions lib/cli.js
Expand Up @@ -87,14 +87,10 @@ if (process.argv.join('').indexOf('mocha') === -1) {
var validate = function (commit) {
if (!validateMessage(commit.message) && commit.errorLog) {
fs.appendFileSync(commit.errorLog, commit.message + '\n');
process.exit(1);
} else {
process.exit(0);
}
};

try {
validate(getCommit());
process.exit(0);
} catch (err) {
console.error(err);
process.exit(1);
}
validate(getCommit());
}
6 changes: 3 additions & 3 deletions test/cli.test.js
Expand Up @@ -73,7 +73,7 @@ describe('cli', function() {
var result = executeCliBySource(cliSource, commitMessage);
expect(result.stdout.toString()).to.eql('Aborting commit due to empty commit message.\n');
expect(result.stderr.toString()).to.eql('');
expect(result.status).to.eql(0);
expect(result.status).to.eql(1);
});
});
}
Expand All @@ -87,7 +87,7 @@ describe('cli', function() {
'Please fix your commit message (and consider using http://npm.im/commitizen)\n\n'
].join(''));
expect(result.stderr.toString()).to.eql('INVALID COMMIT MSG: does not match "<type>(<scope>): <subject>" !\n');
expect(result.status).to.eql(0);
expect(result.status).to.eql(1);
});
});

Expand All @@ -103,7 +103,7 @@ describe('cli', function() {
'INVALID COMMIT MSG: "patch" is not allowed type ! ',
'Valid types are: feat, fix, docs, style, refactor, perf, test, chore, revert, custom\n'
].join(''));
expect(result.status).to.eql(0);
expect(result.status).to.eql(1);
});
});
});
Expand Down

0 comments on commit 888617b

Please sign in to comment.