Skip to content

Commit 0fda24f

Browse files
committed
tests: set GIT_CEILING_DIRECTORIES to prevent repo discovery
When running `npm test` from a Git worktree, test-spawned git processes that happened to operate at or above `.test-dir/` would walk up the directory tree and discover the enclosing real repository. In a worktree setup this is particularly dangerous because the `.git/config` is shared across all worktrees, so any accidental config write (e.g. `core.bare`) affects every checkout. Prevent this by setting `GIT_CEILING_DIRECTORIES` to every ancestor of the `.test-dir/` temporary directory. The temp dir itself is excluded so that git can still discover the test repositories created inside it. Assisted-by: Claude Opus 4.6 Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent 810cb3d commit 0fda24f

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

tests/test-lib.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,13 @@ export async function testCreateRepo(name: string, suffix?: string): Promise<Tes
141141
delete process.env.GIT_DIR;
142142
delete process.env.GIT_WORK_TREE;
143143

144+
// Prevent git from discovering the enclosing repository
145+
const ceilings = [];
146+
for (let dir = tmp, parent; (parent = path.dirname(dir)) !== dir; dir = parent) {
147+
ceilings.push(parent);
148+
}
149+
process.env.GIT_CEILING_DIRECTORIES = ceilings.join(path.delimiter);
150+
144151
// eslint-disable-next-line security/detect-unsafe-regex
145152
const match = name.match(/^(.*[\\/])?(.*?)(\.test)?\.ts$/);
146153
if (match) {

0 commit comments

Comments
 (0)