Skip to content

Commit d850cf4

Browse files
krishna63Kent C. Dodds
authored and
Kent C. Dodds
committed
Commit message not throwing error while commit from git gui (conventional-changelog-archived-repos#79)
* fix(git gui): read commit message from gitgui_editmsg, if required * addressed review comment, so that user can pass the file name from package.json instead of hard quoting here
1 parent 8311d14 commit d850cf4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/cli.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ var getGitFolder = require('./getGitFolder');
1818
// hacky start if not run by mocha :-D
1919
// istanbul ignore next
2020
if (process.argv.join('').indexOf('mocha') === -1) {
21-
var commitMsgFileOrText = process.argv[2] || getGitFolder() + '/COMMIT_EDITMSG';
21+
var commitMsgFileOrText,
22+
gitFolder = getGitFolder() + '/',
23+
//GIT GUI stores commit msg @GITGUI_EDITMSG file, so user can pass file name has argument
24+
//if it doesn't exist then we are considering "/COMMIT_EDITMSG" file
25+
filename = (process.argv[2] && fs.existsSync(gitFolder + process.argv[2])) ? process.argv[2] : 'COMMIT_EDITMSG';
2226

2327
var bufferToString = function (buffer) {
2428
return hasToString(buffer) && buffer.toString();
@@ -28,11 +32,11 @@ if (process.argv.join('').indexOf('mocha') === -1) {
2832
return x && typeof x.toString === 'function';
2933
};
3034

31-
var validate = function (msg, isFile) {
35+
var validate = function (msg, isFile, filename) {
3236
if (!validateMessage(msg)) {
3337
var incorrectLogFile = (
3438
isFile
35-
? commitMsgFileOrText.replace('COMMIT_EDITMSG', 'logs/incorrect-commit-msgs')
39+
? commitMsgFileOrText.replace(filename, 'logs/incorrect-commit-msgs')
3640
: (getGitFolder() + '/logs/incorrect-commit-msgs')
3741
);
3842

@@ -44,6 +48,8 @@ if (process.argv.join('').indexOf('mocha') === -1) {
4448
}
4549
};
4650

51+
commitMsgFileOrText = gitFolder + filename;
52+
4753
fs.readFile(commitMsgFileOrText, function readFile(err, buffer) {
4854
if(err && err.code !== 'ENOENT') {
4955
throw err;
@@ -56,6 +62,6 @@ if (process.argv.join('').indexOf('mocha') === -1) {
5662
: commitMsgFileOrText
5763
);
5864

59-
validate(msg, isFile);
65+
validate(msg, isFile, filename);
6066
});
6167
}

0 commit comments

Comments
 (0)