You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Prevent git rebase --exec test runs from corrupting the enclosing worktree (gitgitgadget#2157)
Running `git rebase -x 'npm test'` from a worktree wreaked havoc on my
real repository: `core.bare = true` and test `url.*.insteadOf` settings
ended up in the shared `.git/config`, test commits landed on the real
HEAD, and a bogus `refs/notes/gitgitgadget` ref appeared out of nowhere.
For a terrifying moment I thought I had lost actual work.
The root cause turned out to be `git rebase --exec` setting `GIT_DIR` in
the environment. This leaked into the Node.js test processes, causing
`git init <target>` to silently reinitialize the *real* repository
instead of creating a fresh one in the target directory -- git simply
ignores the target argument when `GIT_DIR` is set.
Diagnosing this was a bit trickier than I hoped for. Adding
`GIT_CEILING_DIRECTORIES` alone did not help because `GIT_DIR` takes
precedence over repository discovery, making ceiling directories
irrelevant. A secondary leak hid in `misc-helper.test.ts` which
captured `process.env` at module load time, before `testCreateRepo` had
a chance to clear the offending variables.
This series clears `GIT_DIR`/`GIT_WORK_TREE` early, adds
`GIT_CEILING_DIRECTORIES` as defense-in-depth, introduces a
`validateWorkDir()` safety net that fails loudly if git would operate
outside the test directory, and fixes a pre-existing test that
accidentally depended on the enclosing repo's config. It also tells Jest
to ignore `.test-dir/` so stale files from corrupted runs don't cause
confusing failures on the next run.
0 commit comments