Skip to content

Commit e4f909c

Browse files
fix(server): a lone "=======" line no longer blocks finishing a merge
git diff --check reports a standalone "=======" as a leftover conflict marker, so a resolved file with a reStructuredText heading underline was refused. Treat a file as still conflicted only when its reported marker lines include both an opening "<" and a closing ">" boundary. AI-assisted; verified with the tests and tools listed above.
1 parent 6d66290 commit e4f909c

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6407,7 +6407,9 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
64076407
assert.isTrue(Result.isFailure(unresolved), "committed an unresolved conflict");
64086408
assert.equal(yield* git(cwd, ["rev-parse", "HEAD"]), mainHead);
64096409
assert.equal(yield* git(cwd, ["ls-files", "--unmerged"]), unmerged);
6410-
yield* writeTextFile(cwd, "README.md", "resolved version\n");
6410+
// A lone "=======" is a heading underline, not a conflict boundary.
6411+
yield* writeTextFile(cwd, "README.md", "Heading\n=======\n\nresolved\n");
6412+
assert.isNotNull(yield* driver.prepareCommitContext(commitCwd));
64116413
}
64126414
yield* driver.commit(commitCwd, "Finish merge", "", { stage: {} });
64136415
assert.equal(
@@ -6418,7 +6420,10 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
64186420
assert.equal(yield* git(cwd, ["show", "HEAD:feature.txt"]), "feature");
64196421
assert.equal(yield* git(cwd, ["show", "HEAD:unrelated.txt"]), "unrelated");
64206422
if (conflict)
6421-
assert.equal(yield* git(cwd, ["show", "HEAD:README.md"]), "resolved version");
6423+
assert.equal(
6424+
yield* git(cwd, ["show", "HEAD:README.md"]),
6425+
"Heading\n=======\n\nresolved",
6426+
);
64226427
}),
64236428
);
64246429

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

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2555,20 +2555,46 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
25552555
appendTruncationMarker: true,
25562556
},
25572557
);
2558-
const markerLines = check.stdout
2559-
.split("\n")
2560-
.filter((line) => line.endsWith(": leftover conflict marker"));
2561-
if (markerLines.length > 0) {
2562-
const conflicted = unmergedPaths.filter((file) =>
2563-
markerLines.some((line) => line.startsWith(`${file}:`)),
2558+
const reports = check.stdout.split("\n");
2559+
const conflicted: string[] = [];
2560+
let topLevel: string | undefined;
2561+
for (const file of unmergedPaths) {
2562+
const markerLines = new Set(
2563+
reports.flatMap((line) => {
2564+
const match = line.startsWith(`${file}:`)
2565+
? /^(\d+): leftover conflict marker$/.exec(line.slice(file.length + 1))
2566+
: null;
2567+
return match ? [Number(match[1]) - 1] : [];
2568+
}),
25642569
);
2570+
if (markerLines.size === 0) continue;
2571+
topLevel ??= (yield* runGitStdout("GitVcsDriver.commit.topLevel", cwd, [
2572+
"rev-parse",
2573+
"--show-toplevel",
2574+
])).trim();
2575+
const lines = (yield* fileSystem.readFileString(path.join(topLevel, file)).pipe(
2576+
Effect.mapError(
2577+
(cause) =>
2578+
new GitCommandError({
2579+
operation: "GitVcsDriver.commit.conflictMarkers",
2580+
command: "git commit",
2581+
cwd,
2582+
detail: `Could not check ${file} for conflict markers.`,
2583+
cause,
2584+
}),
2585+
),
2586+
)).split("\n");
2587+
// Git also reports a lone "=======", which is valid content such as a heading underline.
2588+
const reported = (marker: string) =>
2589+
lines.some((line, index) => markerLines.has(index) && line.startsWith(marker));
2590+
if (reported("<") && reported(">")) conflicted.push(file);
2591+
}
2592+
if (conflicted.length > 0) {
25652593
return yield* new GitCommandError({
25662594
operation: "GitVcsDriver.commit",
25672595
command: "git commit",
25682596
cwd,
2569-
detail: `Cannot commit with unresolved merge conflicts${
2570-
conflicted.length > 0 ? ` in ${conflicted.join(", ")}` : ""
2571-
}. Resolve them, then commit.`,
2597+
detail: `Cannot commit with unresolved merge conflicts in ${conflicted.join(", ")}. Resolve them, then commit.`,
25722598
});
25732599
}
25742600
}

0 commit comments

Comments
 (0)