Fix native diff row expansion (#940)

* Fix structured diff parsing for no-prefix paths

Git can emit diff --git path path when diff.noprefix is enabled. The structured diff parser only handled the default a/path b/path form, so checkout diff assembly could lose hunks for affected files and render expanded rows empty.

Normalize optional a/ and b/ prefixes in both app and server parsers, and cover the no-prefix header form with regression tests.

* Fix no-prefix diff path parsing

---------

Co-authored-by: Mohamed Boudra <boudra.moha@gmail.com>
This commit is contained in:
c4605
2026-05-17 18:58:10 +08:00
committed by GitHub
co-authored by Mohamed Boudra
parent bb5c3dae00
commit b3c272f720
5 changed files with 195 additions and 16 deletions
@@ -348,6 +348,27 @@ const x = 1;
expect(removedLine?.tokens).toEqual([{ text: "old comment line", style: "comment" }]);
});
it("preserves no-prefix structured paths that start with a or b", async () => {
mkdirSync(join(repoDir, "a"));
mkdirSync(join(repoDir, "b"));
commitFile(repoDir, "a/example.ts", "const value = 1;\n", "add a-prefixed path");
commitFile(repoDir, "b/other.ts", "const value = 1;\n", "add b-prefixed path");
commitFile(repoDir, "file with space.ts", "const value = 1;\n", "add path with space");
execFileSync("git", ["config", "diff.noprefix", "true"], { cwd: repoDir });
writeFileSync(join(repoDir, "a/example.ts"), "const value = 2;\n");
writeFileSync(join(repoDir, "b/other.ts"), "const value = 2;\n");
writeFileSync(join(repoDir, "file with space.ts"), "const value = 2;\n");
const diff = await getCheckoutDiff(repoDir, { mode: "uncommitted", includeStructured: true });
expect(diff.structured?.map((file) => [file.path, file.hunks.length])).toEqual([
["a/example.ts", 1],
["b/other.ts", 1],
["file with space.ts", 1],
]);
});
it("returns checkout root metadata for normal repos", async () => {
const status = await getCheckoutStatus(repoDir);
expect(status.isGit).toBe(true);