#!/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
