Repository navigation
Commit bd6662e
fix(hooks): run pre-commit audit and tests without git's hook environment
Git exports GIT_DIR, GIT_INDEX_FILE and related repo-local variables to
hooks. When a commit is made from a linked worktree, GIT_DIR points at the
worktree's gitdir. The pre-commit hook then runs `make test`, and test
fixtures that call `git -C <tmpdir> init/add/commit/config` inherit those
variables. Their commands act on the repository being committed to instead
of the fixture repo:
- fixture commits ("init", "artifact", "head-only change") land on the
branch checked out in the worktree, sweeping up whatever is staged;
- fixture `git config` writes user.name/user.email and core.bare=true
into the shared .git/config, which breaks the main checkout;
- a fixture `git commit` runs this same hook again, recursing.
This happened in practice on 2026-09-29 while committing review fixes from
agent-workflow worktrees: several local branches picked up fixture commits
and .git/config gained core.bare=true plus a fixture identity.
Unset `git rev-parse --local-env-vars` after the formatting and lint steps
(which need GIT_INDEX_FILE to see the staged index) and before the
security audit and test run.
Verified with a throwaway repo plus linked worktree whose pre-commit hook
runs a fixture-style `git -C <tmp>` init/commit/config: without the unset,
the fixture commit replaced the worktree commit and the shared config got
[email protected]; with it, the real commit landed, the shared config was
unchanged and the fixture got its own repository. Committed with
--no-verify because the hook being fixed is the thing under test.
Co-Authored-By: Claude Opus 5.5 <[email protected]>1 parent 72faa8c commit bd6662e
1 file changed
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
40 | 47 | | |
41 | 48 | | |
42 | 49 | | |
| |||
0 commit comments