Skip to content

Fix: Harden commit-msg hook (trap cleanup, pattern, blank line)#18

Merged
rubambiza merged 2 commits into
kagenti:mainfrom
rubambiza:fix/commit-msg-hook-trap
Jun 23, 2026
Merged

Fix: Harden commit-msg hook (trap cleanup, pattern, blank line)#18
rubambiza merged 2 commits into
kagenti:mainfrom
rubambiza:fix/commit-msg-hook-trap

Conversation

@rubambiza

Copy link
Copy Markdown
Contributor

Summary

Hardens scripts/hooks/commit-msg, mirroring fixes reviewed on the ported copy in kagenti/agent-skills#14:

  • Temp-file cleanup via traptrap 'rm -f "$TEMP_FILE"' EXIT so the temp file is removed on any exit path (including early exit under set -euo pipefail).
  • Simplify strip pattern — drop the redundant cursor alternate; grep -i already matches Cursor case-insensitively in (Claude|Cursor|anthropic).
  • Guard double blank line — only prepend a blank before the Assisted-By trailer when the message does not already end with one.

Verified: a message containing Co-authored-by: Claude converts to a single-blank-separated Assisted-By trailer; a message with no AI trailer is left untouched.

Fixes #17

Assisted-By: Claude Code

Add trap 'rm -f "$TEMP_FILE"' EXIT after mktemp so the temp file is
removed on any exit path, including early exit under set -euo pipefail.
The explicit rm at the end is now redundant and removed.

Mirrors the fix applied to the replicated copy in kagenti/agent-skills
(PR kagenti#14) to keep the hook in sync across repos.

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>

Signed-off-by: Gloire Rubambiza <gloire@ibm.com>
- Drop redundant `cursor` alternate; `grep -i` already matches it
  case-insensitively in the `(Claude|Cursor|anthropic)` pattern
- Only prepend a blank line before the Assisted-By trailer when the
  message does not already end with one, avoiding a double blank

Assisted-By: Claude (Anthropic AI) <noreply@anthropic.com>

Signed-off-by: Gloire Rubambiza <gloire@ibm.com>
@rubambiza rubambiza self-assigned this Jun 22, 2026
@rubambiza rubambiza added the ready-for-ai-review Request automated AI code review from clawgenti label Jun 22, 2026

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR cleanly hardens the commit-msg hook with three well-scoped fixes. All checks pass. Ready for human review.


Reviewed by clawgenti using github:pr-review

Comment thread scripts/hooks/commit-msg
@rubambiza rubambiza added ready-for-human-review AI review passed, ready for human reviewer and removed ready-for-ai-review Request automated AI code review from clawgenti labels Jun 22, 2026

@mrsabath mrsabath left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Clean, correct hardening of the commit-msg hook. I verified all three fixes by running the reconstructed hook against representative messages:

  1. trap cleanuptrap 'rm -f "$TEMP_FILE"' EXIT replaces the trailing rm, so the temp file is removed on every exit path under set -euo pipefail (including an early exit between mktemp and the old rm). $TEMP_FILE is set before the trap and properly quoted. ✓
  2. simplified strip pattern — dropping the redundant |cursor is safe: grep -i already matches lowercase cursor via Cursor. Confirmed directly — no behavior change. ✓
  3. double-blank guard — exactly one blank line precedes the Assisted-By trailer. Verified the three cases: Co-authored-by: Claude → single-blank-separated Assisted-By; no-AI-trailer message left untouched; body already ending in a blank line does not produce a double blank. ✓

Properly quoted, idiomatic, and consistent with the file's style; the inline comment explaining the guard is helpful. All checks pass (DCO, PR title, add-to-project). The clawgenti bot already completed its automated pass — this adds the human-review approval.

Areas reviewed: Shell, Security, Commit conventions
Author: rubambiza (MEMBER)
Commits: 2, signed-off (DCO ✓)
CI: passing

@rubambiza rubambiza merged commit 1bffcb5 into kagenti:main Jun 23, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human-review AI review passed, ready for human reviewer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix: commit-msg hook redundant pattern and double-blank before Assisted-By

3 participants