fix(devkit): scrub git repo-location env vars in spawned processes#400
Open
crs48 wants to merge 1 commit into
Open
fix(devkit): scrub git repo-location env vars in spawned processes#400crs48 wants to merge 1 commit into
crs48 wants to merge 1 commit into
Conversation
Running devkit (or its tests) inside a git hook broke every spawned git: 'git commit' exports GIT_INDEX_FILE into the hook environment, so temp-repo tests and 'git worktree add' were silently redirected at the hook's repo and died with '.git/index: index file open failed: Not a directory'. NodeCommandRunner now drops GIT_DIR/GIT_WORK_TREE/GIT_INDEX_FILE and friends from the inherited env (explicit options.env still wins), and the pre-commit hook scrubs them for the vitest step as defense for other suites. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Contributor
|
This PR needs a changelog entry. Add a fragment file to the PR (it lands with the merge — nothing is node scripts/changelog/new.mjs --title "Short, benefit-first headline" \
--summary "One sentence on what the user can now do." \
--tags app,ai --highlight "A specific user-visible point"No user-facing change? Add the |
Contributor
|
Preview: https://xnet.fyi/pr/400/app/ |
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
The
.husky/pre-commitfinal steppnpm vitest run --changed HEAD --passWithNoTestsfailed falsely whenever the changed-file set pulled inpackages/devkittests (bridge.test.ts,dev-loop.test.ts,git.test.ts). Those tests create real temp git repos and rungit worktree add, which died with:git commitexportsGIT_INDEX_FILE(and related repo-location vars) into the hook environment;NodeCommandRunnerspreadprocess.envinto every child, so the tests' spawned git processes were silently redirected at the outer repo instead of their temp-repocwd. The same tests pass outside the hook.Fix
packages/devkit/src/command-runner.ts(the robust fix):NodeCommandRunnerdrops the git repo-location vars (GIT_DIR,GIT_WORK_TREE,GIT_INDEX_FILE,GIT_OBJECT_DIRECTORY,GIT_ALTERNATE_OBJECT_DIRECTORIES,GIT_COMMON_DIR,GIT_PREFIX) from the inherited env before spawning. An explicit value viaoptions.envstill wins. This covers both theGitclass and the tests' directrunner.run('git', …)setup calls, and protects any devkit consumer that runs inside a hook..husky/pre-commit: the vitest step runs underenv -u GIT_INDEX_FILE -u GIT_DIR -u GIT_WORK_TREEas defense for any other suite that spawns git.command-runner.test.tspinning the scrub + override-wins behavior.@xnetjs/devkitpatch.Verification
GIT_INDEX_FILE/GIT_DIRpointed at the repo, all 5git.test.tstests failed with the reported error; after the fix, the full devkit suite (54 tests) passes under the same polluted env.git.test.ts(incl.worktree add) inside the real hook environment and passed.🤖 Generated with Claude Code