Skip to content

Commit e84f8ca

Browse files
committed
fix(session): forward env so a bad GIT_DIR fails rev-parse
Bun 1.3 keeps the startup environ unless execFileSync is given env, so GIT_DIR and GIT_TRACE2_EVENT never reached git on CI. Pass process.env, and point GIT_DIR at a real non-git file so rev-parse exits non-zero instead of discovering the work tree.
1 parent 34056f9 commit e84f8ca

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

‎src/session/project-key.test.ts‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,15 @@ test("projectRootFor retries a nested dir after git was unavailable", async () =
9797
const nested = join(root, "nested");
9898
await mkdir(nested);
9999
const parent = realpathSync(root);
100-
// Bun resolves execFileSync("git") from the startup PATH, so emptying PATH
101-
// does not hide git. A missing GIT_DIR is forwarded and makes rev-parse fail.
102-
const missingGitDir = join(root, "missing-git-dir");
100+
// Bun 1.3 ignores PATH rewrites and does not forward process.env mutations
101+
// unless the child is given `env`. A missing GIT_DIR is not enough: git may
102+
// keep discovering the work tree. An existing file that is not a git dir
103+
// makes rev-parse exit non-zero.
104+
const notGitDir = join(root, "not-a-git-dir");
105+
await writeFile(notGitDir, "not a git dir\n");
103106

104107
const previousGitDir = process.env.GIT_DIR;
105-
process.env.GIT_DIR = missingGitDir;
108+
process.env.GIT_DIR = notGitDir;
106109
try {
107110
expect(projectRootFor(nested)).toBe(realpathSync(nested));
108111
} finally {

‎src/session/project-key.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,15 @@ function resolvedCwd(cwd: string): string {
4444

4545
function gitToplevel(cwd: string): string | undefined {
4646
try {
47+
// Pass `env` explicitly. Bun 1.3's execFileSync otherwise keeps the
48+
// startup environ, so later process.env changes never reach git.
4749
const toplevelRaw = execFileSync(
4850
"git",
4951
["rev-parse", "--path-format=absolute", "--show-toplevel"],
5052
{
5153
cwd,
5254
encoding: "utf8",
55+
env: process.env,
5356
stdio: ["ignore", "pipe", "ignore"],
5457
},
5558
).trim();

0 commit comments

Comments
 (0)