mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 15:47:43 +01:00
This suite runs from the husky PRE-PUSH hook, so it is armed on every push from
every session. Today its fixtures fell through to the real checkout, and because
pre-push runs BEFORE the transfer, git then pushed what the fixture had just
mangled: `refs/heads/main` on GitHub ended up pointing at a fixture commit whose
tree is a single file named `f`. It also wrote `core.hooksPath=/dev/null` into
the SHARED .git/config, silently disabling every hook for every worktree until
someone noticed.
The mechanism is `git -C <dir>`: when <dir> is not a repo, git WALKS UP the
directory tree and operates on whatever repo it finds. `setup_repo` then ran
`git branch -M main` and `git push origin main` against the real one.
I wrote the guard that was supposed to prevent this, and it was theatre:
case "$root" in "$TMP"/*) ;; *) fail ... ;; esac
`$root` is constructed as "$TMP/a", so the pattern can never fail. It reads like
containment and enforces nothing. Test 6 did not even go through setup_repo — a
bare `git init "$TMP/e"` with no guard at all, which is why its failure ("gate
blocked a checkout with no origin/main") was the first visible symptom: the gate
resolved the REAL origin/main because it was operating on the real repo.
Rebuilt so that no single failure can reach a real repo:
1. GIT_CEILING_DIRECTORIES="$TMP" — git will not search for a repository above
the temp dir, so the walk-up that caused this cannot physically happen.
2. Every git call goes through `g`, which asserts the target resolves to
exactly that fixture path (physical paths, so a symlinked TMPDIR is not a
false mismatch). There are no bare `git -C` calls left.
3. Pushes name an explicit PATH, never the remote `origin` — a fallthrough now
has nowhere to publish. The fixture's own origin URL is asserted too.
4. Identity and hook suppression come from ENV, never `git config`. A config
write is what corrupted the shared config; env cannot leak.
5. $TMP is refused outright if it sits inside a git repo.
Test 8 is new and pins the property that was missing: `g` must REFUSE a
directory that is not its own repo rather than letting git walk up. Without the
ceiling that call resolves to the surrounding worktree; with it, git says
"fatal: not a git repository".
Verified after the rewrite that the real repo is untouched by a run — HEAD,
branch, reflog and core.hooksPath all unchanged.
Scope note: scripts/test/not-behind-gate.sh inherited the same false guard and
is being fixed separately in #299 by its author, so it is deliberately not
touched here.
Co-authored-by: t <t@t.t>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>