Skip to content

Commit cca46da

Browse files
korthoutclaude
andcommitted
Prove fix: whitespace_tolerant mode applies cleanly (reproducer green)
The Step-0 reproducer test, which was intentionally red under default cherry-pick behavior, now runs with whitespace_tolerant mode and passes: -Xignore-space-at-eol lets git ignore trailing-whitespace differences when matching context lines, so the cherry-pick applies cleanly without conflict or duplication. The expected file content is "line1\nline2\nline_new\nline3\n" — the main-branch content with line_new inserted. Git's 3-way merge keeps the patch content when -Xignore-space-at-eol treats the target branch's trailing spaces as no-change, so the release branch whitespace is not preserved in the result. Each line appears exactly once: the key invariant (no duplication) holds. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 617a709 commit cca46da

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

src/test/git.integration.test.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -625,21 +625,17 @@ describe("cherry-pick whitespace-tolerant mode", () => {
625625
}
626626

627627
it.concurrent(
628-
// This test documents the #529 bug class: repos that declare
628+
// This test proves the fix for the #529 bug class: repos that declare
629629
// `merge=union` for a path — the common Visual Studio convention for
630630
// `.csproj`/`.sln` files — get silent content duplication when the
631631
// target branch's context lines differ from the source parent only by
632-
// trailing whitespace. Without a custom merge driver, this kind of
633-
// divergence produces an explicit conflict; the union driver instead
634-
// combines both sides of the unaligned hunk, so it keeps both the target
635-
// branch's version of line2/line3 and the source's inserted content —
636-
// the cherry-pick exits 0 with line2/line3 doubled in the file.
632+
// trailing whitespace, because the union merge driver combines both
633+
// sides of a hunk it can't align instead of flagging a conflict.
637634
//
638-
// This test fails red today because the resulting file content has
639-
// those lines doubled. It goes green when whitespace-tolerant mode is
640-
// wired in (Step 2), since -Xignore-space-at-eol lets the merge ignore
641-
// the trailing-whitespace difference and align cleanly up front.
642-
"default mode fails when context lines differ only by trailing whitespace (reproducer)",
635+
// With whitespace_tolerant mode (-Xignore-space-at-eol), the cherry-pick
636+
// applies cleanly: the merge ignores the trailing-whitespace difference
637+
// and aligns up front, so the union driver never has to guess.
638+
"whitespace_tolerant mode applies cleanly when context lines differ only by trailing whitespace",
643639
async (ctx) => {
644640
const repo = (ctx.repo = await template.createTestRepo());
645641
const git = setupGit();
@@ -691,9 +687,15 @@ describe("cherry-pick whitespace-tolerant mode", () => {
691687
);
692688
await gitCmd("push origin release", repo.workDir);
693689

694-
// With default cherry-pick, this exits 0 but silently duplicates
695-
// line2/line3 — the assertion below catches the wrong content.
696-
await git.cherryPick([featureSha], "fail", repo.workDir, "default");
690+
// With whitespace_tolerant mode (-Xignore-space-at-eol) the cherry-pick
691+
// applies cleanly: trailing whitespace differences in context lines are
692+
// ignored, line_new is inserted cleanly, and no duplication occurs.
693+
await git.cherryPick(
694+
[featureSha],
695+
"fail",
696+
repo.workDir,
697+
"whitespace_tolerant",
698+
);
697699

698700
const content = await readFile(
699701
join(repo.workDir, "feature.txt"),

0 commit comments

Comments
 (0)