Skip to content

Commit 2f5efc2

Browse files
committed
chore: harden co-author stripping hooks and gitignore lefthook wrappers
Use portable sed in prepare-commit-msg (macOS-safe), add lefthook prepare-commit-msg strip, and ignore lefthook-generated hook wrappers.
1 parent 26d4372 commit 2f5efc2

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

.githooks/prepare-commit-msg

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,9 @@ if [ "$COMMIT_SOURCE" = "merge" ] || [ "$COMMIT_SOURCE" = "squash" ]; then
88
exit 0
99
fi
1010

11-
# Strip Co-authored-by lines
12-
sed -i.bak "/^Co-authored-by:/d" "$COMMIT_MSG_FILE" 2>/dev/null || \
13-
sed -i "/^Co-authored-by:/d" "$COMMIT_MSG_FILE"
11+
# Strip Co-authored-by lines (portable sed — works on macOS and Linux).
12+
sed '/^[Cc]o-[Aa]uthored-[Bb]y:/d' "$COMMIT_MSG_FILE" > "${COMMIT_MSG_FILE}.tmp" && mv "${COMMIT_MSG_FILE}.tmp" "$COMMIT_MSG_FILE"
1413

15-
# Remove trailing blank lines
16-
sed -i.bak -e :a -e "/^
17-
*$/{$d;N;ba" -e "}" "$COMMIT_MSG_FILE" 2>/dev/null || \
18-
sed -i -e :a -e "/^
19-
*$/{$d;N;ba" -e "}" "$COMMIT_MSG_FILE"
20-
21-
# Clean up backup files
22-
rm -f "${COMMIT_MSG_FILE}.bak"
14+
# Remove trailing blank lines.
15+
sed -e :a -e '/^\n*$/{$d;N;ba' -e '}' "$COMMIT_MSG_FILE" > "${COMMIT_MSG_FILE}.tmp" 2>/dev/null && mv "${COMMIT_MSG_FILE}.tmp" "$COMMIT_MSG_FILE" || true
2316

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,8 @@ dist/
2424
.commandcode/
2525
.DS_Store
2626
coverage.out
27+
28+
# Lefthook-generated wrappers (tracked .githooks/prepare-commit-msg is canonical)
29+
.githooks/commit-msg
30+
.githooks/pre-push
31+
.githooks/pre-commit.old

lefthook.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,12 @@ commit-msg:
116116
# Strip Co-authored-by: trailers that AI tools (Claude, Cursor, etc.) add.
117117
# This enforces the rule that commits list only the human author.
118118
sed '/^[Cc]o-[Aa]uthored-[Bb]y:/d' "{1}" > "{1}.tmp" && mv "{1}.tmp" "{1}"
119+
120+
# ---------------------------------------------------------------------------
121+
# prepare-commit-msg — strip AI co-author trailers after tools inject them.
122+
# ---------------------------------------------------------------------------
123+
prepare-commit-msg:
124+
commands:
125+
strip-co-authored-by:
126+
run: |
127+
sed '/^[Cc]o-[Aa]uthored-[Bb]y:/d' "{1}" > "{1}.tmp" && mv "{1}.tmp" "{1}"

0 commit comments

Comments
 (0)