Skip to content

fix(pre-push): stop the hook's GIT_DIR from reaching the gate's children - #13850

Merged
kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/pre-push-hook-git-env
Sep 15, 2026
Merged

kodjima33 merged 1 commit into
BasedHardware:mainfrom
aryanorastar:fix/pre-push-hook-git-env

Conversation

@aryanorastar

@aryanorastar aryanorastar commented Sep 14, 2026 •

Copy link
Copy Markdown
Collaborator

What changed and why

Git exports GIT_DIR to hooks, and from a linked worktree it is the absolute path of .git/worktrees/<name>. scripts/pre-push passed it to every child, so a git init <fixture> inside any check reinitialized the real repository instead and wrote core.bare=true into the config every worktree shares. With extensions.worktreeConfig on, that value applies to every linked worktree as well. That is what refused the push of #11183: agents-md-lean's self-test failed with ignored worktree copies must not be discovered.

The gate now drops GIT_DIR and GIT_WORK_TREE once, right after it changes to the work tree root. The two Flutter-phase copies of that unset become redundant and are removed.

Product invariants affected

none

How it was verified

Reproduction in disposable repos only: a real git push from a linked worktree to a local bare remote, with a real pre-push hook running check_agents_md_lean.py from main.

Case Hook env agents-md-lean Shared .git/config after the hook
Push from linked worktree GIT_DIR=<sbx>/main/.git/worktrees/wt self-test passes core.bare false → true; the main worktree then fails with fatal: this operation must be run in a work tree
Same, with extensions.worktreeConfig=true same AssertionError: ignored worktree copies must not be discovered, the #11183 failure core.bare → true; every worktree fails the same way
Same, git env scrubbed before the checker same passes unchanged
Push from the main worktree no GIT_DIR passes unchanged
  • bash scripts/test-pre-push-git-env.sh passes with the fix. It fails against the gate from main and against this gate with only the new unset deleted, both times showing core.bare=false → core.bare=true.
  • All 13 manifest checks triggered by scripts/pre-push pass through python3 .github/scripts/run_checks.py --lane local --check-id <id>. pre-push-worktree-fallback is Windows-only in the manifest; it also passes when run directly on macOS.
  • Real path: this branch was pushed through the real pre-push hook from a linked worktree, without --no-verify. The bounded gate passed, including PR preflight (24 checks, pre-push-hook-git-env among them). The only change to the shared .git/config was this branch's own upstream entry, written by git push -u.

Tests

  • New scripts/test-pre-push-git-env.sh (manifest id pre-push-hook-git-env, local and ci lanes). It runs the real scripts/pre-push from a disposable linked worktree with the hook-shaped GIT_DIR exported, has its first child git init a fixture, and asserts that the shared config is unchanged and that the fixture became its own repository.
  • scripts/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 resolves refs from the work tree, which has origin/main. The harness therefore names a base branch that no repository has, so it still fails fast at the same step with the same cannot find assertion.

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 by scripts/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's evidence_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 unset at the gate entry covers every child, where each of those fixes covered a single caller.

🤖 Generated with Claude Code

Review in cubic

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]>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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].

Re-trigger cubic

@aryanorastar

Copy link
Copy Markdown
Collaborator Author

@Git-on-my-level need human response — ready for review and merge: the gate-level fix for the hook GIT_DIR leak that rewrote the shared git config during the #11183 push. 19 checks green; the two macOS Swift lanes are still queued.

@Git-on-my-level Git-on-my-level added workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior positive-signal Automation verified a genuine fix/quality contribution docs-tooling Layer: Documentation, examples, dev tools labels Sep 14, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this end to end against both gates. File by file:

  • scripts/pre-push — the new unset GIT_DIR GIT_WORK_TREE (line 16) lands exactly where it should: after the cd "$(git rev-parse --show-toplevel ...)" on line 8 but before _resolve_python.sh is sourced, so every child of the gate sees a clean environment. Removing the two per-subshell copies in the Flutter build_runner and gen-l10n phases is right — they were narrower duplicates of the same scrub and are now subsumed by the gate-level one.
  • scripts/test-pre-push-git-env.sh — a real reproduction, not a mock-heavy one: it builds a fixture repo with a linked worktree, copies the actual gate in, replaces _resolve_python.sh with a stand-in child that runs git init $FIXTURE_REPO, invokes the gate with the hook-shaped GIT_DIR exported, and asserts both that the shared config is unchanged and that the fixture became its own repository. I ran it against main's gate: it fails with exactly the documented corruption (core.bare=false → core.bare=true). Against this PR's gate it passes and the shared config is untouched.
  • scripts/test-pre-push-worktree-fallback.sh — the PRE_PUSH_BASE_BRANCH=omi-missing-base-for-fallback-test adaptation is necessary and correct: once the gate drops the inherited GIT_DIR, base-ref resolution runs against the working-tree repository (where origin/main exists), so the old "bare repo has no origin/main" fail-fast no longer holds. The test still proves the gate gets past root resolution and aborts on the base-ref failure rather than the work-tree fatal.
  • .github/checks-manifest.yaml — the new pre-push-hook-git-env entry (local + ci lanes, triggered by the gate, its test, and the manifest) follows the sibling entries' shape and parses cleanly.
  • .github/failure-classes/FC-hook-git-env-reaches-child-git.json — key set matches the existing failure-class files exactly; the violated-contract text matches the mechanism reproduced above, and evidence_prs correctly credits the four earlier one-caller fixes (fix(hooks): stop the unpinned-formatter rewrites, register a web/frontend test lane, unblock web/admin/AGENTS.md #11413, SCA-313: Scope-gate admin deploys and retarget omi-tv activation #11709, Retire the cloud Agent VM: tombstone the broker endpoints, delete the control plane #11795, SCA-403: Record serving-backend provenance on desktop stable pointer #12564).

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 need human response.

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kodjima33
kodjima33 merged commit 19afe22 into BasedHardware:main Sep 15, 2026
42 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs-tooling Layer: Documentation, examples, dev tools positive-signal Automation verified a genuine fix/quality contribution workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants