The best way to control Claude Code, Codex and more from any computer or phone
fix(server): refuse unresolved UTF-16 merge commits (#36817)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 17:55 UTC
d2a941435969d855969716012e21f0698dac2c03
3 files changed
+119
-20
apps/server/src/vcs/GitVcsDriverCore.test.ts
+40
-13
@@ -7396,30 +7396,49 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7396
);
7397
7398
it.effect.each([
7399
- { location: "root", conflict: false },
7400
- { location: "nested", conflict: false },
7401
- { location: "worktree", conflict: false },
7402
- { location: "root", conflict: true },
7403
- { location: "nested", conflict: true },
7404
- { location: "worktree", conflict: true },
7399
+ { location: "root", conflict: false, encoding: "utf8" },
7400
+ { location: "nested", conflict: false, encoding: "utf8" },
7401
+ { location: "worktree", conflict: false, encoding: "utf8" },
7402
+ { location: "root", conflict: true, encoding: "utf8" },
7403
+ { location: "nested", conflict: true, encoding: "utf8" },
7404
+ { location: "worktree", conflict: true, encoding: "utf8" },
7405
+ { location: "root", conflict: true, encoding: "utf16le" },
7406
+ { location: "root", conflict: true, encoding: "utf16le", large: true },
7407
])(
7406
- "rejects selected-file merge commits without mutation ($location, conflict: $conflict)",
7407
- ({ location, conflict }) =>
7408
+ "rejects selected-file merge commits without mutation ($location, conflict: $conflict, $encoding)",
7409
+ ({ location, conflict, encoding, large }) =>
7410
Effect.gen(function* () {
7411
let cwd = yield* makeTmpDir();
7412
const { initialBranch } = yield* initRepoWithCommit(cwd);
7413
+ const writeReadme = (text: string) =>
7414
+ Effect.sync(() =>
7415
+ NodeFS.writeFileSync(
7416
+ NodePath.join(cwd, "README.md"),
7417
+ encoding === "utf16le" ? Buffer.from(`\ufeff${text}`, "utf16le") : text,
7418
+ ),
7419
+ );
7420
+ if (encoding === "utf16le") {
7421
+ yield* writeTextFile(
7422
+ cwd,
7423
+ ".gitattributes",
7424
+ "README.md text working-tree-encoding=UTF-16\n",
7425
+ );
7426
+ yield* writeReadme("base\n");
7427
+ yield* git(cwd, ["add", "."]);
7428
+ yield* git(cwd, ["commit", "-m", "Declare UTF-16 encoding"]);
7429
+ }
7430
const driver = yield* GitVcsDriver.GitVcsDriver;
7431
const fs = yield* FileSystem.FileSystem;
7432
const path = yield* Path.Path;
7433
yield* git(cwd, ["checkout", "-b", "feature"]);
7434
yield* writeTextFile(cwd, "feature.txt", "feature\n");
7416
- if (conflict) yield* writeTextFile(cwd, "README.md", "feature version\n");
7435
+ if (conflict) yield* writeReadme("feature version\n");
7436
yield* git(cwd, ["add", "."]);
7437
yield* git(cwd, ["commit", "-m", "Feature"]);
7438
const featureHead = yield* git(cwd, ["rev-parse", "HEAD"]);
7439
yield* git(cwd, ["checkout", initialBranch]);
7440
yield* writeTextFile(cwd, "main.txt", "main\n");
7422
- if (conflict) yield* writeTextFile(cwd, "README.md", "main version\n");
7441
+ if (conflict) yield* writeReadme("main version\n");
7442
yield* git(cwd, ["add", "."]);
7443
yield* git(cwd, ["commit", "-m", "Main"]);
7444
const mainHead = yield* git(cwd, ["rev-parse", "HEAD"]);
@@ -7468,6 +7487,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7487
assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), mainHead);
7488
assert.equal(yield* git(cwd, ["ls-files", "--unmerged"]), unmerged);
7489
7490
+ const resolvedText = `Heading\n=======\n\nresolved${large ? "x".repeat(17 * 1024 * 1024) : ""}\n`;
7491
if (conflict) {
7492
const unresolved = yield* driver
7493
.commit(commitCwd, "Unresolved merge", "", { stage: {} })
@@ -7476,8 +7496,10 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7496
assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), mainHead);
7497
assert.equal(yield* git(cwd, ["ls-files", "--unmerged"]), unmerged);
7498
// A lone "=======" is a heading underline, not a conflict boundary.
7479
- yield* writeTextFile(cwd, "README.md", "Heading\n=======\n\nresolved\n");
7480
- assert.isNotNull(yield* driver.prepareCommitContext(commitCwd));
7499
+ yield* writeReadme(resolvedText);
7500
+ assert.isNotNull(
7501
+ yield* driver.prepareCommitContext(commitCwd, undefined, { includePatch: false }),
7502
+ );
7503
}
7504
yield* driver.commit(commitCwd, "Finish merge", "", { stage: {} });
7505
assert.equal(
@@ -7487,7 +7509,12 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
7509
assert.isFalse(NodeFS.existsSync(path.join(gitDir, "MERGE_HEAD")));
7510
assert.equal(yield* git(cwd, ["show", "HEAD:feature.txt"]), "feature");
7511
assert.equal(yield* git(cwd, ["show", "HEAD:unrelated.txt"]), "unrelated");
7490
- if (conflict)
7512
+ if (large) {
7513
+ assert.equal(
7514
+ yield* git(cwd, ["cat-file", "-s", "HEAD:README.md"]),
7515
+ String(Buffer.byteLength(resolvedText)),
7516
+ );
7517
+ } else if (conflict)
7518
assert.equal(
7519
yield* git(cwd, ["show", "HEAD:README.md"]),
7520
"Heading\n=======\n\nresolved",
apps/server/src/vcs/GitVcsDriverCore.ts
+27
-7
@@ -2696,7 +2696,7 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2696
);
2697
const reports = check.stdout.split("\n");
2698
const conflicted: string[] = [];
2699
- let topLevel: string | undefined;
2699
+ let emptyTree: string | undefined;
2700
for (const file of unmergedPaths) {
2701
const markerLines = new Set(
2702
reports.flatMap((line) => {
@@ -2707,11 +2707,26 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2707
}),
2708
);
2709
if (markerLines.size === 0) continue;
2710
- topLevel ??= (yield* runGitStdout("GitVcsDriver.commit.topLevel", cwd, [
2711
- "rev-parse",
2712
- "--show-toplevel",
2713
- ])).trim();
2714
- const lines = (yield* fileSystem.readFileString(path.join(topLevel, file)).pipe(
2710
+ emptyTree ??= yield* readEmptyTreeHash(cwd);
2711
+ // --check numbers lines after working-tree-encoding and clean filters; a diff from the
2712
+ // empty tree prints that view. Read it in full so large resolved files can still commit.
2713
+ const fileDiff = yield* runGitStdoutWithOptions(
2714
+ "GitVcsDriver.commit.conflictMarkers",
2715
+ cwd,
2716
+ [
2717
+ "-c",
2718
+ "diff.relative=false",
2719
+ "diff",
2720
+ "--no-color",
2721
+ "--no-ext-diff",
2722
+ "--no-textconv",
2723
+ "--text",
2724
+ emptyTree,
2725
+ "--",
2726
+ `:(top,literal)${file}`,
2727
+ ],
2728
+ { ...(env ? { env } : {}), maxOutputBytes: Number.POSITIVE_INFINITY },
2729
+ ).pipe(
2730
Effect.mapError(
2731
(cause) =>
2732
new GitCommandError({
@@ -2722,7 +2737,12 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
2737
cause,
2738
}),
2739
),
2725
- )).split("\n");
2740
+ );
2741
+ const diffLines = fileDiff.split("\n");
2742
+ const lines = diffLines
2743
+ .slice(diffLines.findIndex((line) => line.startsWith("@@")) + 1)
2744
+ .filter((line) => line.startsWith("+"))
2745
+ .map((line) => line.slice(1));
2746
// Git also reports a lone "=======", which is valid content such as a heading underline.
2747
const reported = (marker: string) =>
2748
lines.some((line, index) => markerLines.has(index) && line.startsWith(marker));
scripts/scenarios/utf16-merge-conflict-blocks-commit.e2e.ts
new
+52
@@ -0,0 +1,52 @@
1
+import { expect } from "e2e";
2
+import * as Effect from "effect/Effect";
3
+import * as FileSystem from "effect/FileSystem";
4
+
5
+import { run } from "./shell.ts";
6
+import { runPromise, test, WEB } from "./t3.ts";
7
+
8
+const utf16 = (text: string) => Buffer.from(`\ufeff${text}`, "utf16le");
9
+
10
+test(
11
+ "The commit dialog refuses a merge whose UTF-16 file still has conflict markers",
12
+ WEB,
13
+ async ({ t3, app, screen }) => {
14
+ const project = await t3.project("demo", {
15
+ ".gitattributes": "README.md text working-tree-encoding=UTF-16\n",
16
+ "README.md": utf16("base\n"),
17
+ });
18
+ const git = (args: ReadonlyArray<string>, allowExit: ReadonlyArray<number> = [0]) =>
19
+ runPromise(
20
+ run(
21
+ "git",
22
+ ["-c", "user.name=Scenario", "-c", "user.email=scenario@example.invalid", ...args],
23
+ { cwd: project, allowExit },
24
+ ),
25
+ );
26
+ const commitReadme = async (text: string) => {
27
+ await runPromise(
28
+ Effect.flatMap(FileSystem.FileSystem, (fs) =>
29
+ fs.writeFile(`${project}/README.md`, utf16(text)),
30
+ ),
31
+ );
32
+ await git(["commit", "--quiet", "--all", "--message", text.trim()]);
33
+ };
34
+ await git(["checkout", "--quiet", "-b", "feature"]);
35
+ await commitReadme("feature version\n");
36
+ await git(["checkout", "--quiet", "main"]);
37
+ await commitReadme("main version\n");
38
+ await git(["merge", "--quiet", "feature"], [1]);
39
+ const thread = await t3.thread({ project, title: "Merge", messages: ["merge"] });
40
+
41
+ await t3.open(thread);
42
+ await screen.getByRole("button", "Git action options").tap();
43
+ await screen.getByRole("menuitem", "Commit").tap();
44
+ await screen.getByPlaceholder("Leave empty to auto-generate").fill("Finish merge");
45
+ await screen.getByRole("button", "Commit", { exact: true }).tap();
46
+ // On a failed assertion e2e captures the committed merge itself.
47
+ await expect(
48
+ screen.getByText("unresolved merge conflicts in README.md", { exact: false }),
49
+ ).toBeVisible();
50
+ await app.screenshot("refused");
51
+ },
52
+);