fix(code): fix branch vs default diff for unpushed changes#1874
Conversation
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
8baaf60 to
ec729a7
Compare
d46c6f4 to
a844b47
Compare
ec729a7 to
83a3771
Compare
a844b47 to
c9125cb
Compare
a634430 to
7d0719f
Compare
c9125cb to
1805acd
Compare
7d0719f to
cf00d9b
Compare
1805acd to
dbfc625
Compare
Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/git/src/queries.test.ts
Line: 101-145
Comment:
**Prefer parameterised tests for `splitUnifiedDiffByFile`**
The four cases for `splitUnifiedDiffByFile` all follow the same pattern — supply a raw diff string, check keys and values in the returned map — and could be collapsed into a single `it.each` table per the team's preference for parameterised tests. The test for the two-file case is the outlier (multiple assertions), but even that can live as a row with a callback to an inline assertion helper.
```ts
it.each([
["empty input", "", []],
["binary diff", "diff --git a/image.png b/image.png\nBinary files ...", ["image.png"]],
["rename keyed by new path", "diff --git a/old.txt b/new.txt\nsimilarity index 100%\n...", ["new.txt"]],
] as const)("splitUnifiedDiffByFile: %s", (_label, raw, expectedKeys) => {
const result = splitUnifiedDiffByFile(raw);
expect([...result.keys()]).toEqual(expectedKeys);
});
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix(code): fix branch vs default diff fo..." | Re-trigger Greptile |
|
|
||
| describe("splitUnifiedDiffByFile", () => { | ||
| it("returns an empty map for empty input", () => { | ||
| expect(splitUnifiedDiffByFile("")).toEqual(new Map()); | ||
| }); | ||
|
|
||
| it("splits a two-file diff keyed by post-image path", () => { | ||
| const raw = [ | ||
| "diff --git a/one.txt b/one.txt", | ||
| "index 0000000..1111111 100644", | ||
| "--- a/one.txt", | ||
| "+++ b/one.txt", | ||
| "@@ -1 +1 @@", | ||
| "-hello", | ||
| "+hello world", | ||
| "diff --git a/two.txt b/two.txt", | ||
| "new file mode 100644", | ||
| "--- /dev/null", | ||
| "+++ b/two.txt", | ||
| "@@ -0,0 +1 @@", | ||
| "+brand new", | ||
| "", | ||
| ].join("\n"); | ||
|
|
||
| const result = splitUnifiedDiffByFile(raw); | ||
|
|
||
| expect([...result.keys()]).toEqual(["one.txt", "two.txt"]); | ||
| expect(result.get("one.txt")).toContain("diff --git a/one.txt b/one.txt"); | ||
| expect(result.get("one.txt")).toContain("+hello world"); | ||
| expect(result.get("two.txt")).toContain("diff --git a/two.txt b/two.txt"); | ||
| expect(result.get("two.txt")).toContain("+brand new"); | ||
| }); | ||
|
|
||
| it("keys renames by the post-rename (b/) path", () => { | ||
| const raw = [ | ||
| "diff --git a/old.txt b/new.txt", | ||
| "similarity index 100%", | ||
| "rename from old.txt", | ||
| "rename to new.txt", | ||
| "", | ||
| ].join("\n"); | ||
|
|
||
| const result = splitUnifiedDiffByFile(raw); | ||
| expect(result.has("new.txt")).toBe(true); | ||
| expect(result.has("old.txt")).toBe(false); |
There was a problem hiding this comment.
Prefer parameterised tests for
splitUnifiedDiffByFile
The four cases for splitUnifiedDiffByFile all follow the same pattern — supply a raw diff string, check keys and values in the returned map — and could be collapsed into a single it.each table per the team's preference for parameterised tests. The test for the two-file case is the outlier (multiple assertions), but even that can live as a row with a callback to an inline assertion helper.
it.each([
["empty input", "", []],
["binary diff", "diff --git a/image.png b/image.png\nBinary files ...", ["image.png"]],
["rename keyed by new path", "diff --git a/old.txt b/new.txt\nsimilarity index 100%\n...", ["new.txt"]],
] as const)("splitUnifiedDiffByFile: %s", (_label, raw, expectedKeys) => {
const result = splitUnifiedDiffByFile(raw);
expect([...result.keys()]).toEqual(expectedKeys);
});Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/git/src/queries.test.ts
Line: 101-145
Comment:
**Prefer parameterised tests for `splitUnifiedDiffByFile`**
The four cases for `splitUnifiedDiffByFile` all follow the same pattern — supply a raw diff string, check keys and values in the returned map — and could be collapsed into a single `it.each` table per the team's preference for parameterised tests. The test for the two-file case is the outlier (multiple assertions), but even that can live as a row with a callback to an inline assertion helper.
```ts
it.each([
["empty input", "", []],
["binary diff", "diff --git a/image.png b/image.png\nBinary files ...", ["image.png"]],
["rename keyed by new path", "diff --git a/old.txt b/new.txt\nsimilarity index 100%\n...", ["new.txt"]],
] as const)("splitUnifiedDiffByFile: %s", (_label, raw, expectedKeys) => {
const result = splitUnifiedDiffByFile(raw);
expect([...result.keys()]).toEqual(expectedKeys);
});
```
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Problem
when a user has committed but unpushed changes, they do not show up in the "branch vs [default]" diff because we use the github APIs and compare to the remote branch
Changes
updates to use local instead of assuming remote for this case
How did you test this?
manually repro'd and tested after fix