Skip to content

Commit afbeb26

Browse files
fix(server): selected-file commits during a cherry-pick or revert are refused
Committing only some files while a cherry-pick or revert was stopped ran git reset, which cleared CHERRY_PICK_HEAD/REVERT_HEAD and committed the selection under the current user. Reject it like a merge, as git commit --only does. Fixes #35096 AI-assisted; verified with the tests and tools listed above.
1 parent c87f876 commit afbeb26

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

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

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,31 +2489,38 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
24892489
{ env },
24902490
);
24912491
} else {
2492-
const mergeHeadPath = yield* runGitStdout("GitVcsDriver.commit.mergeHead", cwd, [
2492+
const inProgressHeads = [
2493+
{ head: "MERGE_HEAD", operation: "merge" },
2494+
{ head: "CHERRY_PICK_HEAD", operation: "cherry-pick" },
2495+
{ head: "REVERT_HEAD", operation: "revert" },
2496+
] as const;
2497+
const headPaths = yield* runGitStdout("GitVcsDriver.commit.mergeHead", cwd, [
24932498
"rev-parse",
2494-
"--git-path",
2495-
"MERGE_HEAD",
2499+
...inProgressHeads.flatMap(({ head }) => ["--git-path", head]),
24962500
]);
2497-
const isMerging = yield* fileSystem.exists(path.resolve(cwd, mergeHeadPath.trim())).pipe(
2501+
const resolvedHeadPaths = headPaths.trim().split("\n");
2502+
const inProgress = yield* Effect.findFirst(inProgressHeads, (_, index) =>
2503+
fileSystem.exists(path.resolve(cwd, resolvedHeadPaths[index] ?? "")),
2504+
).pipe(
24982505
Effect.mapError(
24992506
(cause) =>
25002507
new GitCommandError({
25012508
operation: "GitVcsDriver.commit.mergeHead",
25022509
command: "git commit",
25032510
cwd,
2504-
detail: "Could not check whether a merge is in progress.",
2511+
detail: "Could not check whether a merge, cherry-pick or revert is in progress.",
25052512
cause,
25062513
}),
25072514
),
25082515
);
2509-
// Like git commit --only, reject partial merges before reset can discard their ancestry.
2510-
if (isMerging) {
2516+
// Like git commit --only, reject partial commits before reset can discard their state.
2517+
if (Option.isSome(inProgress)) {
2518+
const { operation } = inProgress.value;
25112519
return yield* new GitCommandError({
25122520
operation: "GitVcsDriver.commit",
25132521
command: "git commit",
25142522
cwd,
2515-
detail:
2516-
"Cannot commit selected files during a merge. Commit all files to finish the merge.",
2523+
detail: `Cannot commit selected files during a ${operation}. Commit all files to finish the ${operation}.`,
25172524
});
25182525
}
25192526
yield* runGit("GitVcsDriver.commit.reset", cwd, ["reset", "--quiet"]);

0 commit comments

Comments
 (0)