The best way to control Claude Code, Codex and more from any computer or phone
fix(server): selected-file commits keep a conflicted multi-commit cherry-pick and reftable cherry-picks (#28912)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Victor committed
Nov 14, 2026 at 06:49 UTC
0e250fa6f6c0154e7fbe82265efaf0c2d44a75e6
2 files changed
+127
-28
apps/server/src/vcs/GitVcsDriverCore.test.ts
+99
-26
@@ -1,4 +1,5 @@
1
// @effect-diagnostics nodeBuiltinImport:off - realpathSync.native resolves Windows 8.3 short names, which the Effect realPath does not.
2
+import * as NodeChildProcess from "node:child_process";
3
import * as NodeFS from "node:fs";
4
import * as NodePath from "node:path";
5
import * as NodeURL from "node:url";
@@ -342,6 +343,11 @@ const git = (
343
return result.stdout.trim();
344
});
345
346
+const [, gitMajor, gitMinor] =
347
+ /(\d+)\.(\d+)/u.exec(NodeChildProcess.execFileSync("git", ["--version"], { encoding: "utf8" })) ??
348
+ [];
349
+const gitHasReftable = Number(gitMajor) > 2 || (Number(gitMajor) === 2 && Number(gitMinor) >= 45);
350
+
351
const gitWithStdin = (
352
cwd: string,
353
args: ReadonlyArray<string>,
@@ -388,11 +394,11 @@ const initRepoWithCommit = (
394
return { initialBranch: head.trim().replace(/^ref: refs\/heads\//, "") };
395
});
396
391
-const commitInitialRepo = (cwd: string) =>
397
+const commitInitialRepo = (cwd: string, initArgs: ReadonlyArray<string> = []) =>
398
Effect.gen(function* () {
399
const fileSystem = yield* FileSystem.FileSystem;
400
const pathService = yield* Path.Path;
395
- yield* git(cwd, ["init"]);
401
+ yield* git(cwd, ["init", ...initArgs]);
402
yield* fileSystem.writeFileString(
403
pathService.join(cwd, ".git", "config"),
404
"[user]\n\temail = test@test.com\n\tname = Test\n",
@@ -7174,41 +7180,108 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7180
);
7181
7182
it.effect.each([
7177
- { operation: "cherry-pick", head: "CHERRY_PICK_HEAD" },
7178
- { operation: "revert", head: "REVERT_HEAD" },
7179
- ])("rejects selected-file commits during a $operation", ({ operation, head }) =>
7183
+ { operation: "cherry-pick", head: "CHERRY_PICK_HEAD", refs: "files" },
7184
+ { operation: "revert", head: "REVERT_HEAD", refs: "files" },
7185
+ // Reftable keeps CHERRY_PICK_HEAD and REVERT_HEAD as refs with no file under .git.
7186
+ { operation: "cherry-pick", head: "CHERRY_PICK_HEAD", refs: "reftable" },
7187
+ { operation: "revert", head: "REVERT_HEAD", refs: "reftable" },
7188
+ ])(
7189
+ "rejects selected-file commits during a $operation ($refs)",
7190
+ ({ operation, head, refs }, ctx) =>
7191
+ Effect.gen(function* () {
7192
+ if (refs === "reftable" && !gitHasReftable)
7193
+ return ctx.skip("Needs Git 2.45 or later for reftable.");
7194
+ const cwd = yield* makeTmpDir();
7195
+ if (refs === "reftable") yield* commitInitialRepo(cwd, ["--ref-format=reftable"]);
7196
+ else yield* initRepoWithCommit(cwd);
7197
+ // Reftable leaves .git/HEAD as a stub, so ask Git for the branch.
7198
+ const initialBranch = yield* git(cwd, ["symbolic-ref", "--short", "HEAD"]);
7199
+ const driver = yield* GitVcsDriver.GitVcsDriver;
7200
+ yield* git(cwd, ["checkout", "-b", "other"]);
7201
+ yield* writeTextFile(cwd, "README.md", "other version\n");
7202
+ yield* writeTextFile(cwd, "picked.txt", "picked\n");
7203
+ yield* git(cwd, ["add", "."]);
7204
+ yield* git(cwd, ["commit", "-m", "Other"]);
7205
+ if (operation === "cherry-pick") yield* git(cwd, ["checkout", initialBranch]);
7206
+ yield* writeTextFile(cwd, "README.md", "main version\n");
7207
+ yield* git(cwd, ["commit", "-am", "Main"]);
7208
+ const originalHead = yield* git(cwd, ["rev-parse", "HEAD"]);
7209
+ yield* git(cwd, ["branch", head]);
7210
+ const result = yield* driver.execute({
7211
+ operation: `test.${operation}`,
7212
+ cwd,
7213
+ args: [operation, operation === "cherry-pick" ? "other" : "HEAD~1"],
7214
+ allowNonZeroExit: true,
7215
+ });
7216
+ assert.equal(result.exitCode, 1);
7217
+ yield* writeTextFile(cwd, "README.md", "resolved version\n");
7218
+ yield* git(cwd, ["add", "README.md"]);
7219
+ const selected = operation === "cherry-pick" ? "picked.txt" : "README.md";
7220
+
7221
+ const commit = yield* driver
7222
+ .commit(cwd, "Partial", "", { stage: { filePaths: [selected] } })
7223
+ .pipe(Effect.result);
7224
+
7225
+ assert.isTrue(Result.isFailure(commit), `Selected-file ${operation} commit succeeded`);
7226
+ assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), originalHead);
7227
+ assert.equal(
7228
+ yield* git(cwd, [
7229
+ "-c",
7230
+ "core.warnAmbiguousRefs=false",
7231
+ "rev-parse",
7232
+ "--verify",
7233
+ "--symbolic-full-name",
7234
+ head,
7235
+ ]),
7236
+ head,
7237
+ );
7238
+ }),
7239
+ );
7240
+
7241
+ it.effect("rejects selected-file commits during a multi-commit no-commit cherry-pick", () =>
7242
Effect.gen(function* () {
7243
const cwd = yield* makeTmpDir();
7244
const { initialBranch } = yield* initRepoWithCommit(cwd);
7245
const driver = yield* GitVcsDriver.GitVcsDriver;
7184
- yield* git(cwd, ["checkout", "-b", "other"]);
7185
- yield* writeTextFile(cwd, "README.md", "other version\n");
7186
- yield* writeTextFile(cwd, "picked.txt", "picked\n");
7246
+ const path = yield* Path.Path;
7247
+ yield* writeTextFile(cwd, "a.txt", "base a\n");
7248
+ yield* writeTextFile(cwd, "b.txt", "base b\n");
7249
yield* git(cwd, ["add", "."]);
7188
- yield* git(cwd, ["commit", "-m", "Other"]);
7189
- if (operation === "cherry-pick") yield* git(cwd, ["checkout", initialBranch]);
7190
- yield* writeTextFile(cwd, "README.md", "main version\n");
7250
+ yield* git(cwd, ["commit", "-m", "Base"]);
7251
+ yield* git(cwd, ["checkout", "-b", "feature"]);
7252
+ yield* writeTextFile(cwd, "a.txt", "feature a\n");
7253
+ yield* writeTextFile(cwd, "b.txt", "feature b\n");
7254
+ yield* git(cwd, ["commit", "-am", "Feature one"]);
7255
+ yield* writeTextFile(cwd, "later.txt", "later\n");
7256
+ yield* git(cwd, ["add", "."]);
7257
+ yield* git(cwd, ["commit", "-m", "Feature two"]);
7258
+ yield* git(cwd, ["checkout", initialBranch]);
7259
+ yield* writeTextFile(cwd, "a.txt", "main a\n");
7260
+ yield* writeTextFile(cwd, "b.txt", "main b\n");
7261
yield* git(cwd, ["commit", "-am", "Main"]);
7192
- const originalHead = yield* git(cwd, ["rev-parse", "HEAD"]);
7193
- const result = yield* driver.execute({
7194
- operation: `test.${operation}`,
7262
+ const head = yield* git(cwd, ["rev-parse", "HEAD"]);
7263
+ const started = yield* driver.execute({
7264
+ operation: "test.sequencer",
7265
cwd,
7196
- args: [operation, operation === "cherry-pick" ? "other" : "HEAD~1"],
7266
+ args: ["cherry-pick", "--no-commit", "feature~1", "feature"],
7267
allowNonZeroExit: true,
7268
});
7199
- assert.equal(result.exitCode, 1);
7200
- yield* writeTextFile(cwd, "README.md", "resolved version\n");
7201
- yield* git(cwd, ["add", "README.md"]);
7269
+ assert.equal(started.exitCode, 1);
7270
+ yield* writeTextFile(cwd, "a.txt", "resolved a\n");
7271
const gitDir = yield* git(cwd, ["rev-parse", "--absolute-git-dir"]);
7203
- const selected = operation === "cherry-pick" ? "picked.txt" : "README.md";
7272
+ assert.isFalse(NodeFS.existsSync(path.join(gitDir, "CHERRY_PICK_HEAD")));
7273
+ const names = ["index", "sequencer/todo", "sequencer/head"];
7274
+ const before = names.map((name) => NodeFS.readFileSync(path.join(gitDir, name)));
7275
7205
- const commit = yield* driver
7206
- .commit(cwd, "Partial", "", { stage: { filePaths: [selected] } })
7207
- .pipe(Effect.result);
7208
-
7209
- assert.isTrue(Result.isFailure(commit), `Selected-file ${operation} commit succeeded`);
7210
- assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), originalHead);
7211
- assert.isTrue(NodeFS.existsSync(`${gitDir}/${head}`));
7276
+ const error = yield* driver
7277
+ .commit(cwd, "Partial", "", { stage: { filePaths: ["a.txt"] } })
7278
+ .pipe(Effect.flip);
7279
+ assert.include(error.detail, "Cannot commit selected files during a cherry-pick or revert");
7280
+ assert.deepEqual(
7281
+ names.map((name) => NodeFS.readFileSync(path.join(gitDir, name))),
7282
+ before,
7283
+ );
7284
+ assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), head);
7285
}),
7286
);
7287
apps/server/src/vcs/GitVcsDriverCore.ts
+28
-2
@@ -2546,14 +2546,40 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2546
{ head: "MERGE_HEAD", operation: "merge" },
2547
{ head: "CHERRY_PICK_HEAD", operation: "cherry-pick" },
2548
{ head: "REVERT_HEAD", operation: "revert" },
2549
+ // A conflicted multi-commit `cherry-pick --no-commit` writes only the sequencer; reset
2550
+ // would clear its unmerged entries, so `--continue` would walk past the conflict.
2551
+ { head: "sequencer", operation: "cherry-pick or revert" },
2552
] as const;
2553
const headPaths = yield* runGitStdout("GitVcsDriver.commit.mergeHead", cwd, [
2554
"rev-parse",
2555
...inProgressHeads.flatMap(({ head }) => ["--git-path", head]),
2556
]);
2557
const resolvedHeadPaths = headPaths.trim().split("\n");
2555
- const inProgress = yield* Effect.findFirst(inProgressHeads, (_, index) =>
2556
- fileSystem.exists(path.resolve(cwd, resolvedHeadPaths[index] ?? "")),
2558
+ // Reftable keeps CHERRY_PICK_HEAD and REVERT_HEAD as refs with no file under .git. A
2559
+ // same-named branch resolves to its full name; an ambiguity warning would blank stdout.
2560
+ const operationRefs = new Set<string>(["CHERRY_PICK_HEAD", "REVERT_HEAD"]);
2561
+ const isOperationRef = (head: string) =>
2562
+ runGitStdout(
2563
+ "GitVcsDriver.commit.operationRef",
2564
+ cwd,
2565
+ [
2566
+ "-c",
2567
+ "core.warnAmbiguousRefs=false",
2568
+ "rev-parse",
2569
+ "--verify",
2570
+ "--quiet",
2571
+ "--symbolic-full-name",
2572
+ head,
2573
+ ],
2574
+ true,
2575
+ ).pipe(Effect.map((ref) => ref.trim() === head));
2576
+ const inProgress = yield* Effect.findFirst(inProgressHeads, ({ head }, index) =>
2577
+ fileSystem.exists(path.resolve(cwd, resolvedHeadPaths[index] ?? "")).pipe(
2578
+ Effect.filterOrElse(
2579
+ (exists) => exists || !operationRefs.has(head),
2580
+ () => isOperationRef(head),
2581
+ ),
2582
+ ),
2583
).pipe(
2584
Effect.mapError(
2585
(cause) =>