The best way to control Claude Code, Codex and more from any computer or phone
fix(server): selected-file commits during a cherry-pick or revert are refused (#35120)
Julius Marminge committed
Nov 12, 2026 at 02:48 UTC
06274896eeb9a8c1646afffd4e45e77ce17596e9
2 files changed
+55
-9
apps/server/src/vcs/GitVcsDriverCore.test.ts
+39
@@ -6492,6 +6492,45 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6492
}),
6493
);
6494
6495
+ it.effect.each([
6496
+ { operation: "cherry-pick", head: "CHERRY_PICK_HEAD" },
6497
+ { operation: "revert", head: "REVERT_HEAD" },
6498
+ ])("rejects selected-file commits during a $operation", ({ operation, head }) =>
6499
+ Effect.gen(function* () {
6500
+ const cwd = yield* makeTmpDir();
6501
+ const { initialBranch } = yield* initRepoWithCommit(cwd);
6502
+ const driver = yield* GitVcsDriver.GitVcsDriver;
6503
+ yield* git(cwd, ["checkout", "-b", "other"]);
6504
+ yield* writeTextFile(cwd, "README.md", "other version\n");
6505
+ yield* writeTextFile(cwd, "picked.txt", "picked\n");
6506
+ yield* git(cwd, ["add", "."]);
6507
+ yield* git(cwd, ["commit", "-m", "Other"]);
6508
+ if (operation === "cherry-pick") yield* git(cwd, ["checkout", initialBranch]);
6509
+ yield* writeTextFile(cwd, "README.md", "main version\n");
6510
+ yield* git(cwd, ["commit", "-am", "Main"]);
6511
+ const originalHead = yield* git(cwd, ["rev-parse", "HEAD"]);
6512
+ const result = yield* driver.execute({
6513
+ operation: `test.${operation}`,
6514
+ cwd,
6515
+ args: [operation, operation === "cherry-pick" ? "other" : "HEAD~1"],
6516
+ allowNonZeroExit: true,
6517
+ });
6518
+ assert.equal(result.exitCode, 1);
6519
+ yield* writeTextFile(cwd, "README.md", "resolved version\n");
6520
+ yield* git(cwd, ["add", "README.md"]);
6521
+ const gitDir = yield* git(cwd, ["rev-parse", "--absolute-git-dir"]);
6522
+ const selected = operation === "cherry-pick" ? "picked.txt" : "README.md";
6523
+
6524
+ const commit = yield* driver
6525
+ .commit(cwd, "Partial", "", { stage: { filePaths: [selected] } })
6526
+ .pipe(Effect.result);
6527
+
6528
+ assert.isTrue(Result.isFailure(commit), `Selected-file ${operation} commit succeeded`);
6529
+ assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), originalHead);
6530
+ assert.isTrue(NodeFS.existsSync(`${gitDir}/${head}`));
6531
+ }),
6532
+ );
6533
+
6534
it.effect("treats selected file paths literally", () =>
6535
Effect.gen(function* () {
6536
const cwd = yield* makeTmpDir();
apps/server/src/vcs/GitVcsDriverCore.ts
+16
-9
@@ -2495,31 +2495,38 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2495
{ env },
2496
);
2497
} else {
2498
- const mergeHeadPath = yield* runGitStdout("GitVcsDriver.commit.mergeHead", cwd, [
2498
+ const inProgressHeads = [
2499
+ { head: "MERGE_HEAD", operation: "merge" },
2500
+ { head: "CHERRY_PICK_HEAD", operation: "cherry-pick" },
2501
+ { head: "REVERT_HEAD", operation: "revert" },
2502
+ ] as const;
2503
+ const headPaths = yield* runGitStdout("GitVcsDriver.commit.mergeHead", cwd, [
2504
"rev-parse",
2500
- "--git-path",
2501
- "MERGE_HEAD",
2505
+ ...inProgressHeads.flatMap(({ head }) => ["--git-path", head]),
2506
]);
2503
- const isMerging = yield* fileSystem.exists(path.resolve(cwd, mergeHeadPath.trim())).pipe(
2507
+ const resolvedHeadPaths = headPaths.trim().split("\n");
2508
+ const inProgress = yield* Effect.findFirst(inProgressHeads, (_, index) =>
2509
+ fileSystem.exists(path.resolve(cwd, resolvedHeadPaths[index] ?? "")),
2510
+ ).pipe(
2511
Effect.mapError(
2512
(cause) =>
2513
new GitCommandError({
2514
operation: "GitVcsDriver.commit.mergeHead",
2515
command: "git commit",
2516
cwd,
2510
- detail: "Could not check whether a merge is in progress.",
2517
+ detail: "Could not check whether a merge, cherry-pick or revert is in progress.",
2518
cause,
2519
}),
2520
),
2521
);
2515
- // Like git commit --only, reject partial merges before reset can discard their ancestry.
2516
- if (isMerging) {
2522
+ // Like git commit --only, reject partial commits before reset can discard their state.
2523
+ if (Option.isSome(inProgress)) {
2524
+ const { operation } = inProgress.value;
2525
return yield* new GitCommandError({
2526
operation: "GitVcsDriver.commit",
2527
command: "git commit",
2528
cwd,
2521
- detail:
2522
- "Cannot commit selected files during a merge. Commit all files to finish the merge.",
2529
+ detail: `Cannot commit selected files during a ${operation}. Commit all files to finish the ${operation}.`,
2530
});
2531
}
2532
yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset", "--quiet"]);