Skip to content

Commit 716e1c0

Browse files
authored
fix(web): Changes row no longer shows +0 while Diff has edits (#28439)
1 parent 52715df commit 716e1c0

3 files changed

Lines changed: 87 additions & 9 deletions

File tree

‎apps/web/src/components/GitActionsControl.logic.test.ts‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { assert, describe, it } from "vite-plus/test";
55
import {
66
buildMenuItems,
77
requiresDefaultBranchConfirmation,
8+
resolveChangesTotals,
89
resolveDefaultBranchActionDialogCopy,
910
resolveLiveThreadBranchUpdate,
1011
resolveQuickAction,
@@ -247,3 +248,53 @@ describe("resolveAutoFeatureBranchName", () => {
247248
assert.equal(ref, "feature/ticket-1-2");
248249
});
249250
});
251+
252+
describe("resolveChangesTotals", () => {
253+
it("does not let an empty branchChanges hide a dirty working tree", () => {
254+
assert.deepEqual(
255+
resolveChangesTotals(
256+
status({
257+
hasWorkingTreeChanges: true,
258+
branchChanges: { baseRef: "main", insertions: 0, deletions: 0 },
259+
workingTree: {
260+
files: [{ path: "a.ts", insertions: 5, deletions: 1 }],
261+
insertions: 5,
262+
deletions: 1,
263+
},
264+
}),
265+
),
266+
{ insertions: 5, deletions: 1 },
267+
);
268+
});
269+
270+
it("keeps non-zero branchChanges over the working tree", () => {
271+
assert.deepEqual(
272+
resolveChangesTotals(
273+
status({
274+
branchChanges: { baseRef: "main", insertions: 20, deletions: 3 },
275+
workingTree: {
276+
files: [{ path: "a.ts", insertions: 1, deletions: 0 }],
277+
insertions: 1,
278+
deletions: 0,
279+
},
280+
}),
281+
),
282+
{ insertions: 20, deletions: 3 },
283+
);
284+
});
285+
286+
it("falls back to the working tree when branchChanges is omitted", () => {
287+
assert.deepEqual(
288+
resolveChangesTotals(
289+
status({
290+
workingTree: {
291+
files: [{ path: "a.ts", insertions: 2, deletions: 0 }],
292+
insertions: 2,
293+
deletions: 0,
294+
},
295+
}),
296+
),
297+
{ insertions: 2, deletions: 0 },
298+
);
299+
});
300+
});

‎apps/web/src/components/GitActionsControl.logic.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,3 +425,28 @@ export function resolveLiveThreadBranchUpdate(input: {
425425
branch: input.gitStatus.refName,
426426
};
427427
}
428+
429+
export type ChangesLineTotals = {
430+
readonly insertions: number;
431+
readonly deletions: number;
432+
};
433+
434+
// `branchChanges ?? workingTree` treats `{0,0}` as present, so a zero branch total hid a dirty
435+
// working tree and the Changes row read +0 while Diff still showed the work.
436+
export function resolveChangesTotals(
437+
status: VcsStatusResult | null | undefined,
438+
): ChangesLineTotals | null {
439+
if (!status) return null;
440+
const branch = status.branchChanges;
441+
const tree = status.workingTree;
442+
if (branch && (branch.insertions > 0 || branch.deletions > 0)) {
443+
return { insertions: branch.insertions, deletions: branch.deletions };
444+
}
445+
if (tree.insertions > 0 || tree.deletions > 0) {
446+
return { insertions: tree.insertions, deletions: tree.deletions };
447+
}
448+
if (branch) {
449+
return { insertions: branch.insertions, deletions: branch.deletions };
450+
}
451+
return { insertions: tree.insertions, deletions: tree.deletions };
452+
}

‎apps/web/src/components/GitActionsControl.tsx‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
type GitQuickAction,
5353
type DefaultBranchConfirmableAction,
5454
requiresDefaultBranchConfirmation,
55+
resolveChangesTotals,
5556
resolveDefaultBranchActionDialogCopy,
5657
resolveFeatureBranchUnavailableReason,
5758
resolveGitActionProgressPresentation,
@@ -1048,7 +1049,10 @@ export default function GitActionsControl({
10481049
const isRepo = gitStatus?.isRepo ?? true;
10491050
const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;
10501051
const gitStatusForActions = gitStatus;
1051-
const changesTotals = gitStatusForActions?.branchChanges ?? gitStatusForActions?.workingTree;
1052+
const changesTotals = resolveChangesTotals(gitStatusForActions) ?? {
1053+
insertions: 0,
1054+
deletions: 0,
1055+
};
10521056

10531057
const allFiles = gitStatusForActions?.workingTree.files ?? [];
10541058
// Changed-file paths are repository-relative, so they must resolve against
@@ -1118,8 +1122,8 @@ export default function GitActionsControl({
11181122
gitActionProgress === null &&
11191123
!gitStatusError &&
11201124
quickAction.disabled &&
1121-
!changesTotals?.insertions &&
1122-
!changesTotals?.deletions;
1125+
!changesTotals.insertions &&
1126+
!changesTotals.deletions;
11231127
const pendingDefaultBranchActionCopy = pendingDefaultBranchAction
11241128
? resolveDefaultBranchActionDialogCopy({
11251129
action: pendingDefaultBranchAction.action,
@@ -1636,19 +1640,17 @@ export default function GitActionsControl({
16361640
<span className="flex items-center gap-1.5 font-mono text-xs tabular-nums">
16371641
<span
16381642
className={
1639-
changesTotals?.insertions
1640-
? "text-diff-addition-foreground"
1641-
: "text-muted-foreground"
1643+
changesTotals.insertions ? "text-diff-addition-foreground" : "text-muted-foreground"
16421644
}
16431645
>
1644-
+{formatDiffCount(changesTotals?.insertions ?? 0)}
1646+
+{formatDiffCount(changesTotals.insertions)}
16451647
</span>
16461648
<span
16471649
className={
1648-
changesTotals?.deletions ? "text-diff-deletion-foreground" : "text-muted-foreground"
1650+
changesTotals.deletions ? "text-diff-deletion-foreground" : "text-muted-foreground"
16491651
}
16501652
>
1651-
-{formatDiffCount(changesTotals?.deletions ?? 0)}
1653+
-{formatDiffCount(changesTotals.deletions)}
16521654
</span>
16531655
</span>
16541656
</ThreadDetailsControl>

0 commit comments

Comments
 (0)