Skip to content
TypeScript

fix(web): show the comparison base beside Changes totals (#30085)

shivam199cb5b6a9d1
diff --git a/apps/web/src/components/GitActionsControl.logic.test.ts b/apps/web/src/components/GitActionsControl.logic.test.ts
index 3c58675d6f6..43e10293741 100644
--- a/apps/web/src/components/GitActionsControl.logic.test.ts
+++ b/apps/web/src/components/GitActionsControl.logic.test.ts
@@ -251,7 +251,7 @@ describe("resolveAutoFeatureBranchName", () => {
describe("resolveChangesTotals", () => {
it("does not let an empty branchChanges hide a dirty working tree", () => {
- assert.deepEqual(
+ assert.deepInclude(
resolveChangesTotals(
status({
hasWorkingTreeChanges: true,
@@ -271,7 +271,7 @@ describe("resolveChangesTotals", () => {
assert.deepEqual(
resolveChangesTotals(
status({
- branchChanges: { baseRef: "main", insertions: 20, deletions: 3 },
+ branchChanges: { baseRef: "origin/master", insertions: 20, deletions: 3 },
workingTree: {
files: [{ path: "a.ts", insertions: 1, deletions: 0 }],
insertions: 1,
@@ -279,12 +279,12 @@ describe("resolveChangesTotals", () => {
},
}),
),
- { insertions: 20, deletions: 3 },
+ { insertions: 20, deletions: 3, baseRef: "origin/master" },
);
});
it("falls back to the working tree when branchChanges is omitted", () => {
- assert.deepEqual(
+ assert.deepInclude(
resolveChangesTotals(
status({
workingTree: {
diff --git a/apps/web/src/components/GitActionsControl.logic.ts b/apps/web/src/components/GitActionsControl.logic.ts
index ca396893acc..5effb44c79a 100644
--- a/apps/web/src/components/GitActionsControl.logic.ts
+++ b/apps/web/src/components/GitActionsControl.logic.ts
@@ -429,6 +429,8 @@ export function resolveLiveThreadBranchUpdate(input: {
export type ChangesLineTotals = {
readonly insertions: number;
readonly deletions: number;
+ /** Ref the counts compare against; `null` means they are uncommitted changes against HEAD. */
+ readonly baseRef: string | null;
};
// `branchChanges ?? workingTree` treats `{0,0}` as present, so a zero branch total hid a dirty
@@ -438,15 +440,16 @@ export function resolveChangesTotals(
): ChangesLineTotals | null {
if (!status) return null;
const branch = status.branchChanges;
- const tree = status.workingTree;
- if (branch && (branch.insertions > 0 || branch.deletions > 0)) {
- return { insertions: branch.insertions, deletions: branch.deletions };
- }
- if (tree.insertions > 0 || tree.deletions > 0) {
- return { insertions: tree.insertions, deletions: tree.deletions };
- }
- if (branch) {
- return { insertions: branch.insertions, deletions: branch.deletions };
- }
- return { insertions: tree.insertions, deletions: tree.deletions };
+ const tree = { ...status.workingTree, baseRef: null };
+ const selected =
+ branch && (branch.insertions > 0 || branch.deletions > 0)
+ ? branch
+ : tree.insertions > 0 || tree.deletions > 0
+ ? tree
+ : (branch ?? tree);
+ return {
+ insertions: selected.insertions,
+ deletions: selected.deletions,
+ baseRef: selected.baseRef,
+ };
}
diff --git a/apps/web/src/components/GitActionsControl.tsx b/apps/web/src/components/GitActionsControl.tsx
index 6afb76c3760..d9662910ff6 100644
--- a/apps/web/src/components/GitActionsControl.tsx
+++ b/apps/web/src/components/GitActionsControl.tsx
@@ -1049,10 +1049,13 @@ export default function GitActionsControl({
const isRepo = gitStatus?.isRepo ?? true;
const hasPrimaryRemote = gitStatus?.hasPrimaryRemote ?? false;
const gitStatusForActions = gitStatus;
- const changesTotals = resolveChangesTotals(gitStatusForActions) ?? {
- insertions: 0,
- deletions: 0,
- };
+ const resolvedChangesTotals = resolveChangesTotals(gitStatusForActions);
+ const changesTotals = resolvedChangesTotals ?? { insertions: 0, deletions: 0 };
+ const changesBaseLabel = resolvedChangesTotals
+ ? resolvedChangesTotals.baseRef === null
+ ? "Uncommitted"
+ : `vs ${resolvedChangesTotals.baseRef}`
+ : null;
const allFiles = gitStatusForActions?.workingTree.files ?? [];
// Changed-file paths are repository-relative, so they must resolve against
@@ -1636,8 +1639,22 @@ export default function GitActionsControl({
onClick={onOpenChanges}
>
<FileDiffIcon className={THREAD_DETAILS_PANEL_ICON_CLASS} aria-hidden />
- <span className={cn("flex-1 text-left", THREAD_DETAILS_PANEL_LABEL_CLASS)}>Changes</span>
- <span className="flex items-center gap-1.5 font-mono text-xs tabular-nums">
+ <span className={cn("shrink-0", THREAD_DETAILS_PANEL_LABEL_CLASS)}>Changes</span>
+ {changesBaseLabel ? (
+ <Tooltip>
+ <TooltipTrigger
+ render={
+ <span className="pointer-events-auto min-w-0 truncate text-xs text-muted-foreground" />
+ }
+ >
+ {changesBaseLabel}
+ </TooltipTrigger>
+ <TooltipPopup side="top" className="max-w-96 break-words">
+ {changesBaseLabel}
+ </TooltipPopup>
+ </Tooltip>
+ ) : null}
+ <span className="ml-auto flex shrink-0 items-center gap-1.5 font-mono text-xs tabular-nums">
<span
className={
changesTotals.insertions ? "text-diff-addition-foreground" : "text-muted-foreground"