Skip to content

Commit ea61922

Browse files
SunkenInTimeclaude
andcommitted
fix(server): keep git's launcher swap out of the resolution cache
A Git upgrade moves the real git.exe but never the launcher, so a cached real path could fail every git command for up to 30 seconds. The swap now runs after the cache. The driver also keeps Node's own lookup when git resolves to a .cmd wrapper, since cmd.exe would cut multi-line commit messages at the first newline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent f20fd98 commit ea61922

3 files changed

Lines changed: 27 additions & 24 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -979,15 +979,15 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
979979
...trace2Monitor.env,
980980
};
981981
const spawnEnv = { ...env, ...windowsLongPathConfigEnv(hostPlatform, env) };
982-
const spawnCommand = yield* resolveSpawnCommand("git", commandInput.args, {
983-
env: spawnEnv,
984-
});
982+
const resolved = yield* resolveSpawnCommand("git", [], { env: spawnEnv });
983+
// A git.cmd wrapper would need cmd.exe, which cuts multi-line commit
984+
// messages at the first newline; leave that case to Node's lookup.
985+
const executable = resolved.shell ? "git" : resolved.command;
985986
const child = yield* commandSpawner
986987
.spawn(
987-
ChildProcess.make(spawnCommand.command, spawnCommand.args, {
988+
ChildProcess.make(executable, commandInput.args, {
988989
cwd: commandInput.cwd,
989990
env: spawnEnv,
990-
shell: spawnCommand.shell,
991991
}),
992992
)
993993
.pipe(

‎packages/shared/src/shell.test.ts‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,10 @@ describe("preferGitForWindowsBinary", () => {
519519
paths.includes(filePath);
520520

521521
it("runs the git.exe Git for Windows' launcher would start", () => {
522-
// 2.56+ on x64, including an upgraded install that kept mingw64.
522+
// 2.56+ on x64. The PATHEXT scan returns the extension in PATHEXT's case.
523523
expect(
524524
preferGitForWindowsBinary(
525-
"C:\\Program Files\\Git\\cmd\\git.exe",
525+
"C:\\Program Files\\Git\\cmd\\git.EXE",
526526
{},
527527
files(
528528
"C:\\Program Files\\Git\\ucrt64\\bin\\git.exe",
@@ -559,12 +559,14 @@ describe("preferGitForWindowsBinary", () => {
559559
).toBe("C:\\Program Files\\Git\\cmd\\git.exe");
560560
});
561561

562+
it("keeps the launcher when no git.exe sits beside it", () => {
563+
expect(preferGitForWindowsBinary("C:\\Program Files\\Git\\cmd\\git.exe", {}, () => false)).toBe(
564+
"C:\\Program Files\\Git\\cmd\\git.exe",
565+
);
566+
});
567+
562568
it("leaves other gits and other launchers alone", () => {
563569
const everything = () => true;
564-
const nothing = () => false;
565-
expect(
566-
preferGitForWindowsBinary("C:\\ProgramData\\chocolatey\\bin\\git.exe", {}, nothing),
567-
).toBe("C:\\ProgramData\\chocolatey\\bin\\git.exe");
568570
expect(preferGitForWindowsBinary("C:\\Users\\me\\scoop\\shims\\git.exe", {}, everything)).toBe(
569571
"C:\\Users\\me\\scoop\\shims\\git.exe",
570572
);

‎packages/shared/src/shell.ts‎

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,8 @@ export const resolveCommandPath = Effect.fn("shell.resolveCommandPath")(function
693693
});
694694
});
695695

696-
// Newest layout first: Git for Windows 2.56 moved x64 builds from mingw64 to
697-
// ucrt64, and an upgraded install can keep the old folder.
696+
// Git for Windows 2.56 moved x64 builds from mingw64 to ucrt64; ARM64 builds
697+
// live in clangarm64 and 32-bit ones in mingw32.
698698
const GIT_FOR_WINDOWS_BUILDS = ["ucrt64", "clangarm64", "mingw64", "mingw32"] as const;
699699

700700
function isFileSync(filePath: string): boolean {
@@ -706,13 +706,14 @@ function isFileSync(filePath: string): boolean {
706706
}
707707

708708
/**
709-
* Swaps Git for Windows' launcher (`<Git>\cmd\git.exe` or `<Git>\bin\git.exe`,
710-
* the only git the installer puts on PATH by default) for the git.exe it
711-
* starts. The launcher costs a second process on every git command, and each
712-
* launch leaks a kernel token reference that slows process creation
713-
* machine-wide until reboot. The real binary sets MSYSTEM, HOME and its own
714-
* PATH entries for hooks, ssh and credential helpers, but only when MSYSTEM is
715-
* unset, so the launcher stays when it is set. Anything else is returned as is.
709+
* Swaps Git for Windows' launcher (`<Git>\cmd\git.exe`, the only git its
710+
* installer puts on PATH, or the portable build's `<Git>\bin\git.exe`) for the
711+
* git.exe it starts. The launcher costs a second process on every git command,
712+
* and each launch leaks a kernel token reference that slows process creation
713+
* machine-wide until reboot. The real binary sets HOME itself, but adds its own
714+
* folders to PATH for hooks, ssh and credential helpers only when MSYSTEM is
715+
* unset, so the launcher stays when MSYSTEM is set. Anything else is returned
716+
* as is.
716717
*/
717718
export function preferGitForWindowsBinary(
718719
executable: string,
@@ -764,7 +765,6 @@ export const resolveSpawnCommand = Effect.fnUntraced(function* (
764765
platform,
765766
resolvePathEnvironmentVariable(env),
766767
resolveWindowsPathExtensions(env).join(";"),
767-
env.MSYSTEM ? "msystem" : "",
768768
command,
769769
].join(COMMAND_RESOLUTION_CACHE_KEY_SEPARATOR);
770770
const nowNanos = yield* Clock.currentTimeNanos;
@@ -773,13 +773,14 @@ export const resolveSpawnCommand = Effect.fnUntraced(function* (
773773
if (cached !== undefined && cached.expiresAtNanos > nowNanos) {
774774
resolvedExecutable = cached.resolvedPath;
775775
} else {
776-
const found = resolveExecutable(command, platform, env);
777-
resolvedExecutable = found === undefined ? null : preferGitForWindowsBinary(found, env);
776+
resolvedExecutable = resolveExecutable(command, platform, env) ?? null;
778777
if (!explicitPath && resolvedExecutable !== null) {
779778
cacheCommandResolution(cache, cacheKey, resolvedExecutable, nowNanos);
780779
}
781780
}
782-
const resolvedCommand = resolvedExecutable ?? command;
781+
// Outside the cache: a Git upgrade moves the real binary, never the launcher.
782+
const resolvedCommand =
783+
resolvedExecutable === null ? command : preferGitForWindowsBinary(resolvedExecutable, env);
783784
const extension = NodePath.win32.extname(resolvedCommand).toLowerCase();
784785
if (extension !== ".cmd" && extension !== ".bat") {
785786
return { command: resolvedCommand, args: [...args], shell: false };

0 commit comments

Comments
 (0)