Skip to content

Commit 292d3ac

Browse files
authored
fix: modify commit-msg hook to work with verbose commits (#782)
Small suggestion for the commit-msg hook to strip everything below the scissor line (added by [`git commit -v`](https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---verbose)) before stripping all of the comments. If this doesn't get stripped the commit message will never be detected as empty because of the diff below the scissor line (which are not comments). This change is merely a suggestion, feel free to take it and modify it as you see fit. Preferably it would also check the `--cleanup`/`git config commit.cleanup` option and only strip as much as that specifies but that's maybe something for in the future. Tested `git commit` with and without `-v`, and with and without a commit message.
1 parent 90d3adf commit 292d3ac

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

mergify_cli/stack/hooks/commit-msg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ dest="$1.tmp.${random}"
3939

4040
trap 'rm -f "${dest}"' EXIT
4141

42-
if ! git stripspace --strip-comments < "$1" > "${dest}" ; then
42+
# cut everything from the scissor marker downwards, then strip comments/whitespace
43+
if ! (sed '/^# -\{24\} >8 -\{24\}$/,$d' | git stripspace --strip-comments) < "$1" > "${dest}" ; then
4344
echo "cannot strip comments from $1"
4445
exit 1
4546
fi

0 commit comments

Comments
 (0)