Skip to content

fix(cli): clear GIT_DIR in staged divergence check for linked worktrees - #1631

Open
skoshx wants to merge 2 commits into
mainfrom
cursor/triage-1630-7e88
Open

fix(cli): clear GIT_DIR in staged divergence check for linked worktrees#1631
skoshx wants to merge 2 commits into
mainfrom
cursor/triage-1630-7e88

Conversation

@skoshx

@skoshx skoshx commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Root cause

When GIT_DIR is set (as git exports it automatically in hooks from linked worktrees), git status resolves paths incorrectly, causing false divergence reports that block --staged scans.

The issue reproduces in any linked worktree (git worktree add) when GIT_DIR points to .git/worktrees/<name> rather than a real .git directory. Git exports this variable to all hook invocations, so it affects every pre-commit hook run from a linked worktree.

Scope

Applied the same GIT_DIR: undefined fix from #1516 (which cleared it for scoped scans in core/services/git.ts) to runGitRaw in cli/utils/git-hook-shared.ts, which is used by the staged divergence check (findStagedSnapshotDivergences).

The fix:

  • Only affects the --staged divergence check path
  • Does not change any diagnostic logic or output
  • Mirrors the existing worktree fix in core

Testing

Added a regression test in find-staged-snapshot-divergences.test.ts that:

  1. Creates a linked worktree
  2. Stages a file
  3. Sets GIT_DIR (as git would in a hook)
  4. Verifies the divergence check returns an empty array (no false positives)

All existing tests pass, including:

  • ✅ React Doctor CI (100/100, 0 errors, 0 warnings)
  • ✅ All platform tests (Ubuntu 20/22/24/25/26, macOS, Windows)
  • ✅ Lint, typecheck, CodeQL

Parity

Expected: zero diagnostic changes, as this fix only affects environment setup for git commands (clearing GIT_DIR before running git 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

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 11, 2026 14:58
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>
@pkg-pr-new

pkg-pr-new Bot commented Aug 11, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/eslint-plugin-react-doctor@1631
npm i https://pkg.pr.new/oxlint-plugin-react-doctor@1631
npm i https://pkg.pr.new/react-doctor@1631

commit: 92c65f3

@github-actions

Copy link
Copy Markdown
Contributor

React Doctor found no new issues. 🎉

Reviewed by React Doctor for commit 92c65f3.

@github-actions

Copy link
Copy Markdown
Contributor

Interactive terminal E2E

Terminal Control verified the built CLI at 92c65f3 in a real PTY:

  • selected a project interactively and observed Scanning... before the three-second Git delay completed
  • waited for the clean result and exercised the compact report
  • opened copy context and the GitHub Actions confirmation, then cancelled safely

Download the edited MP4 and PNG evidence

@skoshx
skoshx marked this pull request as ready for review August 11, 2026 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants