fix(cli): clear GIT_DIR in staged divergence check for linked worktrees - #1631
Open
skoshx wants to merge 2 commits into
Open
fix(cli): clear GIT_DIR in staged divergence check for linked worktrees#1631skoshx wants to merge 2 commits into
skoshx wants to merge 2 commits into
Conversation
When GIT_DIR is set (as git exports it in hooks from linked worktrees), git status resolves paths incorrectly, causing false divergence reports on config files. Clear GIT_DIR in runGitRaw (mirroring the fix in #1516 for core/services/git.ts) so the divergence check sees the correct state. Fixes #1630 Co-authored-by: Skosh <skoshx@users.noreply.github.com>
Co-authored-by: Skosh <skoshx@users.noreply.github.com>
commit: |
Contributor
|
React Doctor found no new issues. 🎉 Reviewed by React Doctor for commit |
Contributor
Interactive terminal E2ETerminal Control verified the built CLI at
|
skoshx
marked this pull request as ready for review
August 11, 2026 15:17
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.
Root cause
When
GIT_DIRis set (as git exports it automatically in hooks from linked worktrees),git statusresolves paths incorrectly, causing false divergence reports that block--stagedscans.The issue reproduces in any linked worktree (
git worktree add) whenGIT_DIRpoints to.git/worktrees/<name>rather than a real.gitdirectory. Git exports this variable to all hook invocations, so it affects everypre-commithook run from a linked worktree.Scope
Applied the same
GIT_DIR: undefinedfix from #1516 (which cleared it for scoped scans incore/services/git.ts) torunGitRawincli/utils/git-hook-shared.ts, which is used by the staged divergence check (findStagedSnapshotDivergences).The fix:
--stageddivergence check pathTesting
Added a regression test in
find-staged-snapshot-divergences.test.tsthat:GIT_DIR(as git would in a hook)All existing tests pass, including:
Parity
Expected: zero diagnostic changes, as this fix only affects environment setup for git commands (clearing
GIT_DIRbefore runninggit status).The React Doctor CI scan confirms no new diagnostics were introduced. Full corpus parity can be validated if needed, but given the focused nature of the fix (identical to #1516's approach), diagnostic regressions are not expected.
Closes #1630