fix: clear GIT_DIR for nested git commands in scoped scans - #1502
Draft
skoshx wants to merge 2 commits into
Draft
Conversation
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>
commit: |
Contributor
Interactive terminal E2ERecorded from the built CLI at |
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.

Problem
Git hooks export
GIT_DIR, which causes nested git commands to ignore the scopedcwdand return repository-root paths instead. This results inENOENTerrors 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_DIRenvironment variable is set. This variable is inherited by nested git commands spawned by React Doctor. When these nested commands run with a scopedcwd(e.g.,webapp/), git ignores thecwdand resolves paths relative toGIT_DIRinstead, returning repository-root paths that don't exist relative to the scan directory.Fix
Explicitly clear
GIT_DIRin the environment when spawning git commands, while preserving other git-related environment variables likeGIT_INDEX_FILE. This ensures that nested git commands respect the providedcwdparameter.Scope
The fix is minimal and surgical:
GIT_DIRwhen spawning git commands (not other commands)GIT_INDEX_FILETesting
Added regression test in
issue-1501-git-dir-scoped-scan.test.tscovering:GIT_DIRis setGIT_INDEX_FILEwhen clearingGIT_DIRCloses #1501