Repository navigation
fix(pre-push): stop the hook's GIT_DIR from reaching the gate's children - #13850
Conversation
Git exports GIT_DIR to hooks; from a linked worktree it is the absolute path of .git/worktrees/<name>. scripts/pre-push passed it to every check it ran, so agents-md-lean's self-test `git init <fixture>` reinitialized the real repository instead: git guessed it bare and wrote core.bare=true into the config every worktree shares. With extensions.worktreeConfig on, that shared value also applies to linked worktrees, so the fixture's ls-files failed and the push of BasedHardware#11183 was refused with "ignored worktree copies must not be discovered". Four earlier fixes scrubbed the variable one caller at a time (BasedHardware#11413, BasedHardware#11709, BasedHardware#11795, BasedHardware#12564). Clear it once at the top of the gate, after it changes to the work tree root, and drop the two Flutter-phase copies it makes redundant. test-pre-push-worktree-fallback.sh ran the gate with a bogus bare GIT_DIR and relied on the gate still using it to fail at the base-ref lookup. The gate now uses the work tree, which has origin/main, so the harness names a base branch no repository has to keep failing fast at the same step. Verification: - Real `git push` from a disposable linked worktree, real pre-push hook, the checker from origin/main: hook env GIT_DIR=<sbx>/main/.git/worktrees/wt; shared core.bare false -> true; with extensions.worktreeConfig=true the exact BasedHardware#11183 AssertionError. A push from the main worktree exports no GIT_DIR and is unaffected. - scripts/test-pre-push-git-env.sh passes with the fix and fails with the gate from origin/main and with only the new unset removed (core.bare=false -> core.bare=true in the fixture's shared config). - All 13 manifest checks triggered by scripts/pre-push pass through run_checks.py --lane local; pre-push-worktree-fallback is Windows-only in the manifest and passes when run directly on macOS. Failure-Class: new Co-Authored-By: Claude Opus 5 <[email protected]>
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
There was a problem hiding this comment.
No issues found across 5 files
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
You’re at about 92% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact [email protected].
|
@Git-on-my-level need human response — ready for review and merge: the gate-level fix for the hook |
|
Verified this end to end against both gates. File by file:
Nice diagnosis and a clean structural fix — centralizing the scrub in the gate instead of patching caller after caller, pinned by a regression test that fails loudly on the exact corruption, is how this class of bug gets closed for good. Since this changes the push gate's environment contract for every child process and registers a new CI check, it needs maintainer sign-off on the gate behavior before merge. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
kodjima33
left a comment
There was a problem hiding this comment.
Clear root-cause fix with strong reproduction evidence: GIT_DIR leaking from a linked worktree into pre-push's children caused git init in check self-tests to reinitialize the real repo and set core.bare=true (breaking every worktree via extensions.worktreeConfig) — the #11183 failure. Scrubs GIT_DIR/GIT_WORK_TREE once at the top of scripts/pre-push instead of per-caller. New scripts/test-pre-push-git-env.sh reproduces and asserts the fix; trusted recurring author (aryanorastar), CI green.
What changed and why
Git exports
GIT_DIRto hooks, and from a linked worktree it is the absolute path of.git/worktrees/<name>.scripts/pre-pushpassed it to every child, so agit init <fixture>inside any check reinitialized the real repository instead and wrotecore.bare=trueinto the config every worktree shares. Withextensions.worktreeConfigon, that value applies to every linked worktree as well. That is what refused the push of #11183: agents-md-lean's self-test failed withignored worktree copies must not be discovered.The gate now drops
GIT_DIRandGIT_WORK_TREEonce, right after it changes to the work tree root. The two Flutter-phase copies of thatunsetbecome redundant and are removed.Product invariants affected
none
How it was verified
Reproduction in disposable repos only: a real
git pushfrom a linked worktree to a local bare remote, with a real pre-push hook runningcheck_agents_md_lean.pyfrommain..git/configafter the hookGIT_DIR=<sbx>/main/.git/worktrees/wtcore.barefalse → true; the main worktree then fails withfatal: this operation must be run in a work treeextensions.worktreeConfig=trueAssertionError: ignored worktree copies must not be discovered, the #11183 failurecore.bare→ true; every worktree fails the same wayGIT_DIRbash scripts/test-pre-push-git-env.shpasses with the fix. It fails against the gate frommainand against this gate with only the newunsetdeleted, both times showingcore.bare=false→core.bare=true.scripts/pre-pushpass throughpython3 .github/scripts/run_checks.py --lane local --check-id <id>.pre-push-worktree-fallbackis Windows-only in the manifest; it also passes when run directly on macOS.--no-verify. The bounded gate passed, including PR preflight (24 checks,pre-push-hook-git-envamong them). The only change to the shared.git/configwas this branch's own upstream entry, written bygit push -u.Tests
scripts/test-pre-push-git-env.sh(manifest idpre-push-hook-git-env, local and ci lanes). It runs the realscripts/pre-pushfrom a disposable linked worktree with the hook-shapedGIT_DIRexported, has its first childgit inita fixture, and asserts that the shared config is unchanged and that the fixture became its own repository.scripts/test-pre-push-worktree-fallback.shran the gate with a bogus bareGIT_DIRand relied on the gate still using it to fail at the base-ref lookup. The gate now resolves refs from the work tree, which hasorigin/main. The harness therefore names a base branch that no repository has, so it still fails fast at the same step with the samecannot findassertion.Failure class (fixes)
Failure-Class: new
Failure-class transition narrative (only when needed)
Violated contract: a child the hook launches that runs git against any other directory must not inherit the hook's exported repository location. Canonical guard: clear it once at the hook entry (
scripts/pre-push), pinned byscripts/test-pre-push-git-env.sh, instead of each caller scrubbing its own environment. Evidence: four earlier per-caller fixes of this leak, listed in the definition'sevidence_prs— #11413 (Flutter version probe), #11709 (admin push-range fixtures), #11795 (traffic-regression gate), #12564 (desktop-backend drift self-test) — plus the #11183 push.New guards (only when adding a check or ratchet)
It would have caught the #11183 push failure and each of #11413, #11709, #11795 and #12564. It is the shared primitive: one
unsetat the gate entry covers every child, where each of those fixes covered a single caller.🤖 Generated with Claude Code