Skip to content

Commit 327605c

Browse files
committed
fix: skip WSL System32 bash.exe in Windows Git Bash detection
1 parent 3328d6e commit 327605c

2 files changed

Lines changed: 28 additions & 7 deletions

File tree

src/common/shell-utils.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -175,13 +175,17 @@ function findAllWindowsExecutableCandidates(executable: string): string[] {
175175
stdio: ["ignore", "pipe", "ignore"],
176176
windowsHide: true,
177177
});
178-
return filterWindowsExecutableCandidates([
179-
...output
180-
.split(/\r?\n/)
181-
.map((line) => line.trim())
182-
.filter(Boolean),
183-
...extraCandidates,
184-
]);
178+
let whereResults = output
179+
.split(/\r?\n/)
180+
.map((line) => line.trim())
181+
.filter(Boolean);
182+
if (executable === "bash") {
183+
// Skip WSL's deprecated bash.exe launcher (C:\Windows\System32\bash.exe).
184+
// It would start commands inside the Linux distro instead of the Windows host,
185+
// breaking all path translations and tool invocations.
186+
whereResults = whereResults.filter((candidate) => !/system32[\\/]bash\.exe$/i.test(candidate));
187+
}
188+
return filterWindowsExecutableCandidates([...whereResults, ...extraCandidates]);
185189
} catch {
186190
return filterWindowsExecutableCandidates(extraCandidates);
187191
}

src/tests/shell-utils.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,23 @@ test("Windows Git Bash detection derives bash.exe from git.exe candidates", () =
7272
assert.equal(resolved, bashPath);
7373
});
7474

75+
test("Windows Git Bash detection skips WSL System32 bash.exe in PATH results", () => {
76+
// When WSL1 is enabled on older Windows 10, C:\Windows\System32\bash.exe
77+
// appears in PATH. That launcher would execute commands inside the Linux
78+
// distro instead of the Windows host, breaking all tool invocations.
79+
// The PATH bash strategy should ignore it and fall through.
80+
const system32Bash = "C:\\Windows\\System32\\bash.exe";
81+
const gitBash = "D:\\Tools\\Git\\bin\\bash.exe";
82+
const resolved = resolveWindowsGitBashPath({
83+
findExecutableCandidates: (executable) =>
84+
executable === "bash" ? [system32Bash] : executable === "git" ? ["D:\\Tools\\Git\\cmd\\git.exe"] : [],
85+
findGitExecPath: () => null,
86+
existsSync: (candidate) => candidate === gitBash,
87+
});
88+
89+
assert.equal(resolved, gitBash);
90+
});
91+
7592
test("File tool path normalization converts Git Bash drive paths on Windows", () => {
7693
assert.equal(
7794
normalizeFilePath("/d/IdeaProjects/guesswho-api/API_DOCUMENTATION.md", "win32"),

0 commit comments

Comments
 (0)