From 400ace25445be9fd3953d12051f237241449ba6d Mon Sep 17 00:00:00 2001 From: Lucas Tribioli Date: Thu, 13 Aug 2026 16:19:57 -0300 Subject: [PATCH] fix(hook): recognise a CRLF blank line when slicing the body MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `/^$/` only matches a truly empty line, so on a CRLF message — where the separator line is `\r` — sed found no separator and deleted the whole file. The guard then saw no body, missed an `Assisted-by:` already present, and the hook appended a duplicate `Co-Authored-By`. `[[:space:]]` covers carriage return, so the address closes the gap with no extra process in the pipe and nothing outside POSIX. It also tolerates a separator line carrying stray spaces. Verified across 12 message shapes in both line endings, including the single-paragraph cases that must still be appended to, and the scissors path. Assisted-by: Claude Code --- iris/hooks/prepare_commit_msg.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iris/hooks/prepare_commit_msg.sh b/iris/hooks/prepare_commit_msg.sh index dcc8944..846d804 100644 --- a/iris/hooks/prepare_commit_msg.sh +++ b/iris/hooks/prepare_commit_msg.sh @@ -76,6 +76,9 @@ fi # Only the body is scanned — the same slice the engine reads (`%b`, the message # minus its first paragraph): a trailer glued to the subject is folded into # `%s`, so the engine would see no attribution and the hook must append one. +# The separator address tolerates blanks so a line carrying only whitespace +# still ends the first paragraph — including the lone `\r` of a CRLF message, +# where a bare `/^$/` would find no separator and drop the whole file. # # Tool names are bounded by a non-alphanumeric class instead of \b: POSIX ERE # leaves \b undefined, so BSD/macOS grep may read it as a literal `b` (and @@ -89,7 +92,7 @@ fi # by the pattern, so without that branch a value glued to the colon # (`Made-with:Cursor`) would have no boundary left to match. -if sed '1,/^$/d' "$COMMIT_MSG_FILE" 2>/dev/null | grep -qiE "^(Co-Authored-By|Assisted-by|Made-with):([[:space:]]*|.*[^[:alnum:]])(claude|anthropic|cursor|windsurf|copilot|codeium|tabnine|amazon-q|gemini|devin[- ]?ai)([^[:alnum:]]|$)"; then +if sed '1,/^[[:space:]]*$/d' "$COMMIT_MSG_FILE" 2>/dev/null | grep -qiE "^(Co-Authored-By|Assisted-by|Made-with):([[:space:]]*|.*[^[:alnum:]])(claude|anthropic|cursor|windsurf|copilot|codeium|tabnine|amazon-q|gemini|devin[- ]?ai)([^[:alnum:]]|$)"; then exit 0 fi