fix(hook): recognise a CRLF blank line when slicing the body - #159
Merged
Conversation
`/^$/` 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 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Kody Review CompleteGreat news! 🎉 Keep up the excellent work! 🚀 Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #144, which merged one commit before this fix reached it.
Root cause
#144 taught the hook's already-attributed guard to read only the body, so it looks at the same slice the engine does (
%b, the message minus its first paragraph):/^$/matches only a truly empty line. On a CRLF message the separator line is\r, so sed finds no separator, deletes through to EOF, and the guard sees no body at all. It then misses anAssisted-by:(orMade-with:) that is already there, and the hook appends a redundantCo-Authored-By.Direction is benign — a duplicated trailer, never a missing one — but it puts the hook back out of step with the engine, which handles CRLF fine (
f35641ain #144 trims the trailing\rfrom the captured value).Fix
[[:space:]]covers carriage return, so widening the address closes the gap with no extra process in the pipe and nothing outside POSIX ERE:It also tolerates a separator line carrying stray spaces. The grep pattern is byte-for-byte unchanged.
Verification
Guard behaviour across both line endings, driving the real hook with
env -u AI_AGENT CLAUDE_CODE=1 sh iris/hooks/prepare_commit_msg.sh <file> ""and comparing the file before/after:Assisted-by: Claude CodeCo-Authored-By: Claude CodeCo-Authored-By: Claudemir SantosAssisted-by: Claude CodeMade-with: CursorCo-Authored-By: Claudemir SantosConfirmed the bug first by reinstating
/^$/in a copy of the hook: the CRLF case ended with both the originalAssisted-by:and an appendedCo-Authored-By:.Also:
sh -nclean,pytest tests/ -q286 passed,python scripts/check_analysis_chain.pyOK, and realgit commitruns in a scratch repo (-m, and editor withcommit.verbose=true) still produce exactly one trailer, inserted above the scissors line.Note on how this got separated
#144 was merged at 18:10 UTC with head
6fd7d79; this commit was pushed to that branch about an hour later, so it never entered the PR — the branch had already been merged, which is also why nopull_requestevent fired for the push. Nothing was lost, it just needs its own PR. Everything else from #144 and #145 is onmain.Follow-up worth its own issue
Nothing in
tests/exercisesprepare_commit_msg.sh— the suite covers the Python side only. Across #144 the guard changed five times and every change either introduced or exposed a bug (indentation mismatch,_as a word character,\boutside POSIX ERE, a value glued to the colon, the scissors append, and now CRLF). All six were caught by review, none by a test. A table of message shapes driving the.shvia subprocess, plus an assertion that the shell alternation and_AI_TOOL_PATTERNScarry the same tool list, would cover the lot. Happy to open it if you want it.This PR fixes the
prepare-commit-msghook so it correctly slices off the subject paragraph when the commit message uses CRLF line endings.What changed
iris/hooks/prepare_commit_msg.sh, thesedexpression that extracts the commit-message body was changed from:sed '1,/^$/d' …sed '1,/^[[:space:]]*$/d' …\rleft by CRLF line endings.Functional impact
\ron the blank line between the subject and body, so/^$/did not match it. The hook then treated the entire message as the subject, discarded it, and failed to see an existing AI tool trailer in the body. As a result, it could wrongly append an AI attribution line to commits that already had one.Co-Authored-By,Assisted-by, orMade-withtrailers regardless of line ending style.