From 86ccf2c47a4eb471ea56985441af44132e9dea52 Mon Sep 17 00:00:00 2001 From: Michal Pemcak Date: Mon, 19 Oct 2026 18:39:31 +0200 Subject: [PATCH] build: add commit hooks --- .githooks/check-large-files.sh | 14 ++++++++++++++ .githooks/commit-msg-check.sh | 27 +++++++++++++++++++++++++++ lefthook.yml | 22 ++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100755 .githooks/check-large-files.sh create mode 100755 .githooks/commit-msg-check.sh create mode 100644 lefthook.yml diff --git a/.githooks/check-large-files.sh b/.githooks/check-large-files.sh new file mode 100755 index 0000000..94502de --- /dev/null +++ b/.githooks/check-large-files.sh @@ -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 diff --git a/.githooks/commit-msg-check.sh b/.githooks/commit-msg-check.sh new file mode 100755 index 0000000..129be43 --- /dev/null +++ b/.githooks/commit-msg-check.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# Conventional Commits with a short subject; no AI attribution. +# Called by lefthook as: commit-msg-check.sh +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 '(): '" >&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 diff --git a/lefthook.yml b/lefthook.yml new file mode 100644 index 0000000..9c94bfa --- /dev/null +++ b/lefthook.yml @@ -0,0 +1,22 @@ +# Commit checks. Generated by project-bootstrap; coding agents may not edit it. +# Remove the sections for languages the project doesn't use. +# Formatter (biome) intentionally not enforced repo-wide: the codebase is +# pre-existing, unformatted (spaces), and has no config — it gets formatted +# file by file as files are touched, not in a mass reformat. +pre-commit: + parallel: true + commands: + gitleaks: + run: gitleaks git --pre-commit --staged --no-banner --redact + large-files: + run: .githooks/check-large-files.sh {staged_files} + + # --- shell --- + shellcheck: + glob: "*.sh" + run: shellcheck {staged_files} + +commit-msg: + commands: + conventional: + run: .githooks/commit-msg-check.sh {1}