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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user