Skip to content

Commit 2a4cb0a

Browse files
committed
fix(review): keep optimistic staging patches valid
1 parent d292bcd commit 2a4cb0a

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

‎apps/web/src/components/diffs/workingChangesState.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from "vite-plus/test";
22
import { hydratePartialDiff } from "@pierre/diffs";
3+
import { parsePatchFiles } from "@pierre/diffs/utils/parsePatchFiles";
34
import {
45
reviewPatchHunks,
56
reviewSelectedLinesPatch,
@@ -219,6 +220,11 @@ describe("optimistic working changes", () => {
219220
});
220221
expect(edits(next.staged)).toEqual(["+extra"]);
221222
expect(edits(next.unstaged)).toEqual(["-beta", "+BETA"]);
223+
for (const scope of [next.staged, next.unstaged]) {
224+
for (const patch of scope.hunksByPath.get("file.txt")!) {
225+
expect(parsePatchFiles(patch, undefined, true)[0]?.files).toHaveLength(1);
226+
}
227+
}
222228
expect(next.unstaged.files[0]?.additionLines).toEqual([
223229
"alpha\n",
224230
"BETA\n",

‎packages/client-runtime/src/reviewWorkingChangesState.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function optimisticFile(
9898
.join(""),
9999
)
100100
.join("");
101-
return `${header}${hunk.hunkSpecs}\n${body}`;
101+
return `${header}${hunk.hunkSpecs?.trimEnd()}\n${body}`;
102102
});
103103
const patch = header + hunks.map((hunk) => hunk.slice(header.length)).join("");
104104
const file = parsePatchFiles(patch, `optimistic:${Hash.string(patch)}`)[0]?.files[0];

0 commit comments

Comments
 (0)