build: add commit hooks

This commit is contained in:
2026-10-19 18:39:31 +02:00
parent b04e70e261
commit 86ccf2c47a
3 changed files with 63 additions and 0 deletions

14
.githooks/check-large-files.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/sh
# Block staged files over the limit: checkpoints, datasets and binaries stay out of git.
# Called by lefthook as: check-large-files.sh {staged_files}
limit_mb="${MAX_FILE_MB:-5}"
limit=$((limit_mb * 1024 * 1024))
status=0
for file in "$@"; do
size=$(git cat-file -s ":$file" 2>/dev/null) || continue
if [ "$size" -gt "$limit" ]; then
echo "large file: $file is $((size / 1024 / 1024)) MB (limit ${limit_mb} MB). Add it to .gitignore." >&2
status=1
fi
done
exit $status

27
.githooks/commit-msg-check.sh Executable file
View File

@@ -0,0 +1,27 @@
#!/bin/sh
# Conventional Commits with a short subject; no AI attribution.
# Called by lefthook as: commit-msg-check.sh <message-file>
msg_file="$1"
subject=$(sed -n '1p' "$msg_file")
case "$subject" in
Merge\ * | Revert\ * | fixup!\ * | squash!\ * | amend!\ *) exit 0 ;;
esac
types='feat|fix|refactor|perf|docs|test|build|ci|chore|style|revert|exp'
if ! printf '%s\n' "$subject" | grep -Eq "^($types)(\([a-z0-9._/-]+\))?!?: [^ ].*$"; then
echo "commit-msg: subject must be '<type>(<scope>): <summary>'" >&2
echo " types: ${types}" >&2
echo " got: $subject" >&2
exit 1
fi
if [ "${#subject}" -gt 72 ]; then
echo "commit-msg: subject is ${#subject} chars, keep it at 72 or less (aim for ~50)" >&2
exit 1
fi
if grep -Eiq 'co-authored-by:[[:space:]]*claude|noreply@anthropic\.com|generated with \[?claude code' "$msg_file"; then
echo "commit-msg: no AI attribution lines in commit messages" >&2
exit 1
fi