fix(git_bridge): strip inherited git-context env in run_git (kills pre-push hook race)#1009
Merged
Merged
Conversation
3 tasks
Root cause for the pre-push hook's git_bridge::tests cluster failure:
When `cargo test --lib` is invoked by the pre-push hook (which is
itself invoked by `git push`), git sets context env vars (GIT_DIR,
GIT_PREFIX, etc.) on the hook process. Those env vars propagate to
every child — including cargo, including the test binary, including
the tempdir `git init`/`git commit` calls inside the tests.
So when a test does `git commit` in its tempdir, git inherits
GIT_DIR=/Users/joelteply/.../continuum/.git, runs the parent
worktree's pre-commit hook (which itself shells `<repo>/src/scripts/
git-precommit.sh`), and panics because that script's path doesn't
exist relative to the tempdir.
Surface symptom: 9-of-9 git_bridge tests fail when run via the
pre-push hook with errors like:
- "could not lock config file <bare>/.git/config: File exists"
- "Unable to create '<bare>/.git/worktrees/<x>/index.lock'"
- "<bare>/.git/hooks/pre-commit: <tmp>/src/scripts/git-precommit.sh:
No such file or directory"
All three are symptoms of the same upstream cause: GIT_DIR pinning
git to the parent worktree regardless of cwd.
Fix: strip GIT_DIR / GIT_WORK_TREE / GIT_COMMON_DIR / GIT_INDEX_FILE
/ GIT_PREFIX from the environment when invoking git via run_git.
Also set GIT_CEILING_DIRECTORIES=workspace_root as defense-in-depth
against future git env vars.
This makes run_git context-clean: git discovers from current_dir
only, no parent contamination.
## Tests
Reproduces previously-failing case: simulate hook env by exporting
GIT_DIR before cargo test:
Before: GIT_DIR=<continuum>/.git cargo test --lib code::git_bridge
→ 9 failures with "could not lock config file"
After: same command → 9 passed; 0 failed
Caught by continuum-b69f's pre-push run on 2026-05-02. Unblocks any
PR (PowerShell-only, docs-only, TS-only) from the spurious pre-push
fail. Also makes run_git production-safer: hooks invoking continuum-
core's git_bridge functions get a clean context.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
de8f46c to
ff96c64
Compare
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The pre-push hook's Phase 3 (Rust tests) was reliably failing 9-of-9
code::git_bridge::tests::*whenever invoked, even though the same tests passed in isolation. Root cause is git env inheritance, not parallelism.Root cause
git pushsetsGIT_DIR,GIT_PREFIX, etc. on the pre-push hook's environment. Those env vars propagate through every child — includingcargo test, including the test binary, including each test's tempdirgit init/git commit. So a test'sgit commitin its tempdir inheritsGIT_DIR=/Users/.../continuum/.git, runs the parent worktree'spre-commithook (which can't find its target script in the tempdir context), and panics.Three different surface symptoms, all from the same upstream cause:
<bare>/.git/config: File exists"<bare>/.git/worktrees/<x>/index.lock'"<bare>/.git/hooks/pre-commit:<tmp>/src/scripts/git-precommit.sh: No such file or directory"Fix
In
run_git:env_removeforGIT_DIR,GIT_WORK_TREE,GIT_COMMON_DIR,GIT_INDEX_FILE,GIT_PREFIXGIT_CEILING_DIRECTORIES=workspace_rootas defense-in-depth against future env varsrun_gitis now context-clean: git discovers fromcurrent_dir(workspace_root)only, no parent contamination. Production callers get a small safety improvement (continuum-core's git_bridge invoked from any process won't accidentally inherit the caller's git context); test callers get reliable isolation.Tests
Reproduces the previously-failing case by simulating the hook environment:
cargo test --lib code::git_bridgeGIT_DIR=<continuum>/.git cargo test --lib code::git_bridgecargo test --lib(full suite, normal env)cargo test --lib(full suite, via pre-push)Why this PR matters beyond itself
The pre-push hook's Phase 3 false-positive was blocking ANY PR whose change is non-Rust (PowerShell-only, docs-only, TS-only) from passing through. Two such PRs were blocked tonight — b69f's #1005 (Carl-OOTB Windows fix #1) and my unpushed install.ps1 networking-probe (Carl-OOTB Windows fix #2). With this fix, the hook stops false-positive blocking on the inherited-env race.
Test plan
GIT_DIR=$(git rev-parse --git-dir) cargo test --lib --features metal,accelerate code::git_bridge— should pass on this branch, fail on canary🤖 Generated with Claude Code