@devries-cameron20 / t3code-1 / commits / 8ef649f8b5
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(server): Commit refuses while a merge still has conflict markers (#35132)

Julius Marminge committed Nov 12, 2026 at 02:59 UTC 8ef649f8b56abded899e8a29b2ff4dac2a03e2e2
2 files changed +87 -2
apps/server/src/vcs/GitVcsDriverCore.test.ts
+15 -2
@@ -6507,7 +6507,17 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6507 assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), mainHead);
6508 assert.equal(yield* git(cwd, ["ls-files", "--unmerged"]), unmerged);
6509
6510 - if (conflict) yield* writeTextFile(cwd, "README.md", "resolved version\n");
6510 + if (conflict) {
6511 + const unresolved = yield* driver
6512 + .commit(commitCwd, "Unresolved merge", "", { stage: {} })
6513 + .pipe(Effect.result);
6514 + assert.isTrue(Result.isFailure(unresolved), "committed an unresolved conflict");
6515 + assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), mainHead);
6516 + assert.equal(yield* git(cwd, ["ls-files", "--unmerged"]), unmerged);
6517 + // A lone "=======" is a heading underline, not a conflict boundary.
6518 + yield* writeTextFile(cwd, "README.md", "Heading\n=======\n\nresolved\n");
6519 + assert.isNotNull(yield* driver.prepareCommitContext(commitCwd));
6520 + }
6521 yield* driver.commit(commitCwd, "Finish merge", "", { stage: {} });
6522 assert.equal(
6523 yield* git(cwd, ["show", "-s", "--format=%P", "HEAD"]),
@@ -6517,7 +6527,10 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
6527 assert.equal(yield* git(cwd, ["show", "HEAD:feature.txt"]), "feature");
6528 assert.equal(yield* git(cwd, ["show", "HEAD:unrelated.txt"]), "unrelated");
6529 if (conflict)
6520 - assert.equal(yield* git(cwd, ["show", "HEAD:README.md"]), "resolved version");
6530 + assert.equal(
6531 + yield* git(cwd, ["show", "HEAD:README.md"]),
6532 + "Heading\n=======\n\nresolved",
6533 + );
6534 }),
6535 );
6536
apps/server/src/vcs/GitVcsDriverCore.ts
+72
@@ -2543,6 +2543,78 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2543 },
2544 );
2545 } else {
2546 + // add -A marks unmerged paths resolved, so refuse while one still has conflict markers.
2547 + const unmergedPaths = (yield* runGitStdoutWithOptions(
2548 + "GitVcsDriver.commit.unmergedPaths",
2549 + cwd,
2550 + ["-c", "diff.relative=false", "diff", "--name-only", "--diff-filter=U", "-z"],
2551 + env ? { env } : {},
2552 + ))
2553 + .split("\0")
2554 + .filter((file) => file.length > 0);
2555 + if (unmergedPaths.length > 0) {
2556 + const check = yield* executeGit(
2557 + "GitVcsDriver.commit.conflictMarkers",
2558 + cwd,
2559 + [
2560 + "-c",
2561 + "diff.relative=false",
2562 + "diff",
2563 + "--check",
2564 + "--no-color",
2565 + "--",
2566 + ...unmergedPaths.map((file) => `:(top,literal)${file}`),
2567 + ],
2568 + {
2569 + ...(env ? { env } : {}),
2570 + allowNonZeroExit: true,
2571 + maxOutputBytes: REVIEW_METADATA_MAX_OUTPUT_BYTES,
2572 + appendTruncationMarker: true,
2573 + },
2574 + );
2575 + const reports = check.stdout.split("\n");
2576 + const conflicted: string[] = [];
2577 + let topLevel: string | undefined;
2578 + for (const file of unmergedPaths) {
2579 + const markerLines = new Set(
2580 + reports.flatMap((line) => {
2581 + const match = line.startsWith(`${file}:`)
2582 + ? /^(\d+): leftover conflict marker$/.exec(line.slice(file.length + 1))
2583 + : null;
2584 + return match ? [Number(match[1]) - 1] : [];
2585 + }),
2586 + );
2587 + if (markerLines.size === 0) continue;
2588 + topLevel ??= (yield* runGitStdout("GitVcsDriver.commit.topLevel", cwd, [
2589 + "rev-parse",
2590 + "--show-toplevel",
2591 + ])).trim();
2592 + const lines = (yield* fileSystem.readFileString(path.join(topLevel, file)).pipe(
2593 + Effect.mapError(
2594 + (cause) =>
2595 + new GitCommandError({
2596 + operation: "GitVcsDriver.commit.conflictMarkers",
2597 + command: "git commit",
2598 + cwd,
2599 + detail: `Could not check ${file} for conflict markers.`,
2600 + cause,
2601 + }),
2602 + ),
2603 + )).split("\n");
2604 + // Git also reports a lone "=======", which is valid content such as a heading underline.
2605 + const reported = (marker: string) =>
2606 + lines.some((line, index) => markerLines.has(index) && line.startsWith(marker));
2607 + if (reported("<") && reported(">")) conflicted.push(file);
2608 + }
2609 + if (conflicted.length > 0) {
2610 + return yield* new GitCommandError({
2611 + operation: "GitVcsDriver.commit",
2612 + command: "git commit",
2613 + cwd,
2614 + detail: `Cannot commit with unresolved merge conflicts in ${conflicted.join(", ")}. Resolve them, then commit.`,
2615 + });
2616 + }
2617 + }
2618 yield* runGit(
2619 "GitVcsDriver.commit.addAll",
2620 cwd,