Skip to content

Commit 6da7206

Browse files
author
Alexander Lisianoi
committed
Suggest old commit message only when absolutely sure
If the user does a squash/a merge/an inline commit, do not overwrite their message at all, just use it and remove our old message, if any Closes #95
1 parent 7b596fe commit 6da7206

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

prepare-commit-msg-hook.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,18 @@ try {
1515
var mtime = new Date(fs.statSync(oldMessagePath).mtime)
1616

1717
// Date.now() - mtime.getTime() is milliseconds, convert to seconds
18-
if ((Date.now() - mtime.getTime()) / 1000 < oldMessageSeconds) {
18+
var fresh = (Date.now() - mtime.getTime()) / 1000 < oldMessageSeconds
19+
20+
// There are many scenarios that trigger the prepare-commit-msg hook
21+
// These scenarios pass different console parameters, see here:
22+
// https://www.kernel.org/pub/software/scm/git/docs/githooks.html
23+
//
24+
// A plain `git commit` is the only scenario that passes 3 entries
25+
// For all other scenarios (like `git commit -m`, squash or merge)
26+
// just delete oldMessagePath, do not actually suggest it to user
27+
var plain = process.argv === 3
28+
29+
if (plain && fresh) {
1930
fs.writeFileSync(process.argv[2], fs.readFileSync(oldMessagePath))
2031
}
2132

0 commit comments

Comments
 (0)