The best way to control Claude Code, Codex and more from any computer or phone
fix(server): selected-file commits work again with Git older than 2.25 (#28850)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 07:28 UTC
e53417b2d49b73a2e2467d2e6f0118c3891caab1
2 files changed
+74
-3
apps/server/src/vcs/GitVcsDriverCore.test.ts
+47
@@ -1560,6 +1560,53 @@ it.effect("reads worktrees from git that rejects worktree list -z", () =>
1560
),
1561
);
1562
1563
+it.effect("commits selected files with git that rejects --pathspec-from-file", () =>
1564
+ Effect.scoped(
1565
+ Effect.gen(function* () {
1566
+ const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
1567
+ // Git before 2.25 has no `add --pathspec-from-file` and exits with a usage error.
1568
+ const oldGitSpawner = ChildProcessSpawner.make((command) => {
1569
+ if (!ChildProcess.isStandardCommand(command)) {
1570
+ return Effect.die("expected a standard Git command");
1571
+ }
1572
+ if (command.args.at(-1) === "version") {
1573
+ return Effect.succeed(makeSuccessfulHandle("git version 2.24.4\n"));
1574
+ }
1575
+ if (command.args.some((arg) => String(arg).startsWith("--pathspec-from-file"))) {
1576
+ return Effect.succeed(makeFailedHandle("error: unknown option `pathspec-from-file=-'"));
1577
+ }
1578
+ return delegate.spawn(command);
1579
+ });
1580
+ const driver = yield* makeGitVcsDriverCore().pipe(
1581
+ Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, oldGitSpawner),
1582
+ );
1583
+ yield* Effect.gen(function* () {
1584
+ const cwd = yield* makeTmpDir();
1585
+ yield* initRepoWithCommit(cwd);
1586
+ const selected = ["selected[1].txt", "-dash.txt", "with space.txt"];
1587
+ for (const file of selected) yield* writeTextFile(cwd, file, "selected\n");
1588
+ yield* writeTextFile(cwd, "left.txt", "left\n");
1589
+
1590
+ yield* driver.commit(cwd, "Selected", "", { stage: { filePaths: selected } });
1591
+
1592
+ assert.sameMembers(
1593
+ (yield* git(cwd, ["show", "--pretty=", "--name-only", "-z", "HEAD"]))
1594
+ .split("\0")
1595
+ .filter(Boolean),
1596
+ selected,
1597
+ );
1598
+ assert.equal(yield* git(cwd, ["status", "--porcelain"]), "?? left.txt");
1599
+ }).pipe(Effect.provideService(GitVcsDriver.GitVcsDriver, driver));
1600
+ }),
1601
+ ).pipe(
1602
+ Effect.provide(
1603
+ layerServerConfig.pipe(
1604
+ Layer.provideMerge(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer)),
1605
+ ),
1606
+ ),
1607
+ ),
1608
+);
1609
+
1610
it.effect("does not report a separate git dir as the worktree of its branch", () =>
1611
Effect.scoped(
1612
Effect.gen(function* () {
apps/server/src/vcs/GitVcsDriverCore.ts
+27
-3
@@ -334,6 +334,14 @@ function splitNullSeparatedPaths(input: string, truncated: boolean): string[] {
334
return parts.filter((value) => value.length > 0);
335
}
336
337
+// Parses "git version 2.24.3 (Apple Git-128)" or "git version 2.45.1.windows.1".
338
+const gitSupportsPathspecFromFile = (versionOutput: string): boolean => {
339
+ const match = /^git version (\d+)\.(\d+)/.exec(versionOutput);
340
+ if (match === null) return false;
341
+ const major = Number(match[1]);
342
+ return major > 2 || (major === 2 && Number(match[2]) >= 25);
343
+};
344
+
345
export function splitNullSeparatedGitStdoutPaths(
346
result: Pick<GitVcsDriver.ExecuteGitResult, "stdout" | "stdoutTruncated">,
347
): string[] {
@@ -2518,6 +2526,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2526
})),
2527
);
2528
2529
+ // git add takes --pathspec-from-file from Git 2.25; older Git keeps the argument form.
2530
+ let pathspecFromFileSupported: boolean | undefined;
2531
+ const supportsPathspecFromFile = Effect.fn("GitVcsDriver.supportsPathspecFromFile")(function* (
2532
+ cwd: string,
2533
+ ) {
2534
+ if (pathspecFromFileSupported !== undefined) return pathspecFromFileSupported;
2535
+ const version = yield* executeGit("GitVcsDriver.version", cwd, ["version"]).pipe(Effect.option);
2536
+ if (Option.isNone(version)) return false;
2537
+ pathspecFromFileSupported = gitSupportsPathspecFromFile(version.value.stdout);
2538
+ return pathspecFromFileSupported;
2539
+ });
2540
+
2541
const stageCommitChanges = Effect.fnUntraced(function* (
2542
cwd: string,
2543
filePaths?: readonly string[],
@@ -2604,14 +2624,18 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2624
}
2625
yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset", "--quiet"]);
2626
}
2627
+ // Status paths are repository-relative, while cwd can be a subdirectory.
2628
+ const pathspecs = filePaths.map((file) => `:(top,literal)${file}`);
2629
+ const fromStdin = yield* supportsPathspecFromFile(cwd);
2630
yield* runGit(
2631
"GitVcsDriver.commit.addSelected",
2632
cwd,
2610
- [...config, "add", "-A", "--pathspec-from-file=-", "--pathspec-file-nul"],
2633
+ fromStdin
2634
+ ? [...config, "add", "-A", "--pathspec-from-file=-", "--pathspec-file-nul"]
2635
+ : [...config, "add", "-A", "--", ...pathspecs],
2636
{
2637
...(env ? { env } : {}),
2613
- // Status paths are repository-relative, while cwd can be a subdirectory.
2614
- stdin: filePaths.map((file) => `:(top,literal)${file}\0`).join(""),
2638
+ ...(fromStdin ? { stdin: pathspecs.map((pathspec) => `${pathspec}\0`).join("") } : {}),
2639
},
2640
);
2641
} else {