Files
khosra/scripts/hooks/pre-commit
T
bdeshiandClaude Opus 5 07cf655d09 fix the pre-commit hook's path, missed by the rename
ADR-0082 moved docs/ to harness/ and left scripts/hooks/pre-commit staging
docs/surface.md. The hook runs on every commit, so the very commit that did the
rename hit it: `git add docs/surface.md` failed with a fatal, the commit
otherwise succeeded, and surface.md went in only because it had been staged by
hand beforehand.

The sweep missed it because the file has no extension and the grep that found
every other reference was filtered by --include='*.sh'. HARNESS.md now says so
where the hook is described, since the next rename will make the same mistake for
the same reason.

Verified by this commit: the hook ran, regenerated harness/surface.md, and staged
it without error.

2 files.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-02 20:12:12 +06:00

29 lines
1.4 KiB
Bash
Executable File

#!/usr/bin/env bash
# Makes the gate non-optional. Enable once per clone:
# git config core.hooksPath scripts/hooks
# Bypass deliberately with `git commit --no-verify` — and say why in the commit body.
set -uo pipefail
cd "$(git rev-parse --show-toplevel)" || exit 1
# Anything mechanically derived from the code is regenerated and staged here, not remembered. A
# generated file that only fails a gate teaches nothing — the commit should simply carry the current
# one. `verify.sh` still compares, because a clone without core.hooksPath set has no hook at all.
#
# The generated file describes the working tree, so a partly-staged .go file would put a surface in the
# commit for code the commit does not contain — the same failure the staged-tree gate exists for.
# Checked before generating, because a staged deletion also breaks the generator.
unstaged=$(git diff --name-only -- '*.go')
if [ -n "$unstaged" ]; then
printf 'FAIL unstaged .go changes — harness/surface.md would describe code this commit lacks:\n'
printf ' %s\n' $unstaged
printf ' stage them, stash them, or commit with --no-verify and say why in the body.\n'
exit 1
fi
# One generated artifact, so one call. A second one makes this a two-line list; it does not make it a
# registry (CLAUDE.md rule 1).
./scripts/surface.sh --write >/dev/null || exit 1
git add harness/surface.md
exec ./scripts/verify.sh --quiet