#!/usr/bin/env bash # Installed as .git/hooks/pre-push by `make install-hooks`. It never needs re-installing. # # The real gate is the TRACKED scripts/hooks/pre-push. Installing a COPY freezes whatever # version was current on install day — in pdac-analysis-orchestrator that silently disabled a # gate for six days (the installed copy predated it). This shim instead runs the tracked hook # as it is on `dev` (the integration branch), so an edited gate is live on the next push from # any checkout or worktree, including one parked on an older branch. The gate LOGIC comes from # `dev`; the CODE it judges is still the pushed commit (the hook scans each pushed sha). # Falls back to this checkout's copy if `dev` has none. set -euo pipefail hook="$(mktemp)" refs="$(mktemp)" trap 'rm -f "$hook" "$refs"' EXIT if ! git show dev:scripts/hooks/pre-push > "$hook" 2>/dev/null; then cp "$(git rev-parse --show-toplevel)/scripts/hooks/pre-push" "$hook" fi # Capture git's ref lines BEFORE backgrounding the gate. Not optional plumbing: POSIX gives an # asynchronous command's stdin /dev/null in a non-interactive shell, so a backgrounded gate reads # NO ref lines, concludes "no commits to scan" and exits 0 — a gate that passes every push while # checking nothing. Found in DecoupleRpy_Agent on 2026-09-23 while adding the forwarding below, # and only because the test asserted the gate had SCANNED rather than that the hook exited 0. cat > "$refs" # Run the gate as a background job and FORWARD signals to it. The shim is the process git starts, # so it is the one a terminating session signals — and the gate's own cleanup traps cannot help if # the shim dies and leaves the gate reparented to init with a scan worktree open, which is the # 2026-09-23 leak one layer up. (Ctrl-C alone is fine: the terminal signals the whole foreground # group. A plain TERM to the hook is not.) `wait` is interruptible, so the forward is immediate. bash "$hook" "$@" < "$refs" & # "$@" is git's remote name + URL gate=$! forward() { kill -TERM "$gate" 2>/dev/null || true; } trap forward INT TERM HUP rc=0 wait "$gate" || rc=$? exit "$rc"