Skip to content

Commit d8662b0

Browse files
phillipwoodgitster
authored andcommitted
templates: detect messages that contain a separator line
Messages that contain "---" separator lines will be truncated by "git am". This often surprises users so add a check to the sample "commit-msg" hook to reject such messages. As it's conceivable that someone is using "---" as their comment string we delete any commented lines before checking for a separator. The trailing ".*" when matching commented lines ensures that if the comment string ends with a "$" it is not treated as an anchor. Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 76cba32 commit d8662b0

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

templates/hooks/commit-msg.sample

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,16 @@ comment_re="$(
3939
}'
4040
)"
4141
line="$(sed -n -e "/^${comment_re} -\{8,\} >8 -\{8,\}\$/q
42+
/^${comment_re}.*/d
43+
/^---\$/{p;q;}
4244
/^diff -/{p;q;}
4345
/^Index: /{p;q;}" "$1")"
44-
if test -n "$line"
46+
if test "$line" = "---"
47+
then
48+
echo >&2 "Message contains a '---' separator line that will confuse"
49+
echo >&2 "'git am'. To fix this indent the '---' line."
50+
ret=1
51+
elif test -n "$line"
4552
then
4653
echo >&2 "Message contains a diff that will confuse 'git am'."
4754
echo >&2 "To fix this indent the diff."

0 commit comments

Comments
 (0)