[PATCH 3/3] templates: detect messages that contain a separator line
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Feb 7, 2026, 14:58 UTC
- Message-ID
- <83c100a73ec722bf72a15b7b40b0c82bf8829168.1770476279.git.phillip.wood@dunelm.org.uk>
- In-Reply-To
- <cover.1770476279.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>
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> --- templates/hooks/commit-msg.sample | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/templates/hooks/commit-msg.sample b/templates/hooks/commit-msg.sample index 099cc58c303..c7a9db88cb9 100755 --- a/templates/hooks/commit-msg.sample +++ b/templates/hooks/commit-msg.sample @@ -39,9 +39,16 @@ comment_re="$( }' )" line="$(sed -n -e "/^${comment_re} -\{8,\} >8 -\{8,\}\$/q + /^${comment_re}.*/d + /^---\$/{p;q;} /^diff -/{p;q;} /^Index: /{p;q;}" "$1")" -if test -n "$line" +if test "$line" = "---" +then + echo >&2 "Message contains a '---' separator line that will confuse" + echo >&2 "'git am'. To fix this indent the '---' line." + ret=1 +elif test -n "$line" then echo >&2 "Message contains a diff that will confuse 'git am'." echo >&2 "To fix this indent the diff."
-- 2.52.0.362.g884e03848a9