Skip to content

fix: clear GIT_DIR for nested git commands in scoped scans - #1502

Draft
skoshx wants to merge 2 commits into
mainfrom
cursor/triage-1501-e641
Draft

fix: clear GIT_DIR for nested git commands in scoped scans#1502
skoshx wants to merge 2 commits into
mainfrom
cursor/triage-1501-e641

Conversation

@skoshx

@skoshx skoshx commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Git hooks export GIT_DIR, which causes nested git commands to ignore the scoped cwd and return repository-root paths instead. This results in ENOENT errors when scanning subdirectories from within git hooks.

Root Cause

When React Doctor is invoked from a Git hook (e.g., pre-commit, pre-push), the GIT_DIR environment variable is set. This variable is inherited by nested git commands spawned by React Doctor. When these nested commands run with a scoped cwd (e.g., webapp/), git ignores the cwd and resolves paths relative to GIT_DIR instead, returning repository-root paths that don't exist relative to the scan directory.

Fix

Explicitly clear GIT_DIR in the environment when spawning git commands, while preserving other git-related environment variables like GIT_INDEX_FILE. This ensures that nested git commands respect the provided cwd parameter.

Scope

The fix is minimal and surgical:

  • Clears only GIT_DIR when spawning git commands (not other commands)
  • Preserves all other environment variables including GIT_INDEX_FILE
  • No behavior change for scans outside of git hooks

Testing

Added regression test in issue-1501-git-dir-scoped-scan.test.ts covering:

  • Scoped scans returning relative paths when GIT_DIR is set
  • Preventing repository-root paths in subdirectory scans
  • Preserving GIT_INDEX_FILE when clearing GIT_DIR

Closes #1501

Open in Web Open in Cursor 

cursoragent and others added 2 commits July 29, 2026 18:59
Git hooks export GIT_DIR, which causes nested git commands to ignore
the scoped cwd and return repository-root paths. This fix explicitly
clears GIT_DIR when spawning git commands while preserving other
environment variables like GIT_INDEX_FILE.

Adds regression test for issue #1501 covering:
- Scoped scans returning relative paths when GIT_DIR is set
- Preventing repository-root paths in subdirectory scans
- Preserving GIT_INDEX_FILE when clearing GIT_DIR

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 Jul 29, 2026

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 2a14939

@github-actions

Copy link
Copy Markdown
Contributor

Interactive terminal E2E

React Doctor interactive terminal recording

Recorded from the built CLI at 2a14939 in a real terminal. The fixture holds Git busy for three seconds, so Scanning... must appear immediately after project selection, then exercises the compact interactive report.

Download the GIF and MP4 artifact

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: scoped scans fail inside Git hooks

2 participants