Skip to content

Commit eb70783

Browse files
feat: introduced githooks to strip --trailers in commit messages
1 parent 744447d commit eb70783

3 files changed

Lines changed: 68 additions & 0 deletions

File tree

.githooks/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## Repo git hooks
2+
3+
This repository keeps git hooks in `.githooks/`.
4+
5+
### Enable
6+
7+
Run this once in the repo:
8+
9+
```bash
10+
git config core.hooksPath .githooks
11+
```
12+
13+
### What it does
14+
15+
- `commit-msg`: removes any `Co-authored-by: Cursor ...` trailer lines from commit messages.
16+
- `prepare-commit-msg`: same removal earlier in the flow (best-effort).
17+

.githooks/commit-msg

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
# Strip Cursor co-author trailer(s) from commit message.
5+
# Runs after the message is composed, before the commit is finalized.
6+
#
7+
# Usage: enable repo hooks with:
8+
# git config core.hooksPath .githooks
9+
10+
MSG_FILE="${1:-}"
11+
if [ -z "$MSG_FILE" ] || [ ! -f "$MSG_FILE" ]; then
12+
exit 0
13+
fi
14+
15+
tmp="${MSG_FILE}.tmp.$$"
16+
17+
# Remove any "Co-authored-by: Cursor ..." trailer lines (case-insensitive).
18+
# Keep all other co-authors intact.
19+
awk '
20+
BEGIN { IGNORECASE = 1 }
21+
/^[[:space:]]*Co-authored-by:[[:space:]]*Cursor([[:space:]]|<|$)/ { next }
22+
/^[[:space:]]*Co-Authored-By:[[:space:]]*Cursor([[:space:]]|<|$)/ { next }
23+
{ print }
24+
' "$MSG_FILE" > "$tmp"
25+
26+
mv "$tmp" "$MSG_FILE"
27+
28+
exit 0

.githooks/prepare-commit-msg

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
set -eu
3+
4+
# Also strip Cursor trailer during message preparation (helps with templates/squash).
5+
# This is a best-effort duplicate of commit-msg; commit-msg is the final gate.
6+
7+
MSG_FILE="${1:-}"
8+
if [ -z "$MSG_FILE" ] || [ ! -f "$MSG_FILE" ]; then
9+
exit 0
10+
fi
11+
12+
tmp="${MSG_FILE}.tmp.$$"
13+
14+
awk '
15+
BEGIN { IGNORECASE = 1 }
16+
/^[[:space:]]*Co-authored-by:[[:space:]]*Cursor([[:space:]]|<|$)/ { next }
17+
/^[[:space:]]*Co-Authored-By:[[:space:]]*Cursor([[:space:]]|<|$)/ { next }
18+
{ print }
19+
' "$MSG_FILE" > "$tmp"
20+
21+
mv "$tmp" "$MSG_FILE"
22+
23+
exit 0

0 commit comments

Comments
 (0)