@@ -94,6 +94,15 @@ import {
9494import { useQuietThreadProjection , useQuietThreadShell } from "~/state/entities" ;
9595import { readEnvironmentScope , useEnvironmentScope } from "~/state/session" ;
9696import { useEnvironmentQuery } from "~/state/query" ;
97+ import { useFilesystemReadAccess } from "~/state/filesystem" ;
98+ import { reviewEnvironment } from "~/state/review" ;
99+ import { revisionedQuery } from "~/state/revisionedQuery" ;
100+ import {
101+ selectThreadBranchBaseRef ,
102+ useDiffPanelSessionStore ,
103+ useDiffPanelStore ,
104+ } from "~/diffPanelStore" ;
105+ import { useClientSettings } from "~/hooks/useSettings" ;
97106import { serverEnvironment } from "~/state/server" ;
98107import { sourceControlEnvironment } from "~/state/sourceControl" ;
99108import { threadEnvironment } from "~/state/threads" ;
@@ -122,6 +131,7 @@ interface GitActionsControlProps {
122131 showActions ?: boolean ;
123132 showChanges ?: boolean ;
124133 onOpenChanges ?: ( ) => void ;
134+ workspaceMutationId ?: string | null ;
125135}
126136
127137interface PendingDefaultBranchAction {
@@ -933,6 +943,7 @@ export default function GitActionsControl({
933943 showActions = true ,
934944 showChanges = true ,
935945 onOpenChanges,
946+ workspaceMutationId = null ,
936947} : GitActionsControlProps ) {
937948 const panelAnchorRef = useRef < HTMLDivElement | null > ( null ) ;
938949 const updateThreadMetadata = useAtomCommand (
@@ -1050,7 +1061,53 @@ export default function GitActionsControl({
10501061 const isRepo = gitStatus ?. isRepo ?? true ;
10511062 const hasPrimaryRemote = gitStatus ?. hasPrimaryRemote ?? false ;
10521063 const gitStatusForActions = gitStatus ;
1053- const resolvedChangesTotals = resolveChangesTotals ( gitStatusForActions ) ;
1064+ const changesBaseRef = useDiffPanelStore ( ( state ) =>
1065+ selectThreadBranchBaseRef ( state , activeThreadRef ) ,
1066+ ) ;
1067+ const ignoreWhitespaceSetting = useClientSettings ( ( settings ) => settings . diffIgnoreWhitespace ) ;
1068+ const ignoreWhitespace =
1069+ useDiffPanelSessionStore ( ( state ) => state . ignoreWhitespace ) ?? ignoreWhitespaceSetting ;
1070+ const { canReadFiles } = useFilesystemReadAccess ( activeEnvironmentId ) ;
1071+ // Same input as the Diff panel's branch query, so both read one cached result. Status
1072+ // totals join the revision because edits, pulls and resets outside a turn leave the mutation
1073+ // id as is.
1074+ const changesRevision = gitStatusForActions
1075+ ? JSON . stringify ( [
1076+ workspaceMutationId ,
1077+ gitStatusForActions . refName ,
1078+ gitStatusForActions . workingTree . insertions ,
1079+ gitStatusForActions . workingTree . deletions ,
1080+ gitStatusForActions . branchChanges ?. baseRef ,
1081+ gitStatusForActions . branchChanges ?. insertions ,
1082+ gitStatusForActions . branchChanges ?. deletions ,
1083+ ] )
1084+ : null ;
1085+ const changesPreview = useEnvironmentQuery (
1086+ showChanges &&
1087+ isRepo &&
1088+ canReadFiles &&
1089+ changesRevision !== null &&
1090+ activeEnvironmentId !== null &&
1091+ gitCwd !== null
1092+ ? revisionedQuery (
1093+ reviewEnvironment . diffPreview ( {
1094+ environmentId : activeEnvironmentId ,
1095+ input : {
1096+ cwd : gitCwd ,
1097+ ...( changesBaseRef ? { baseRef : changesBaseRef } : { } ) ,
1098+ ignoreWhitespace,
1099+ metadataOnly : true ,
1100+ sourceKind : "branch-range" ,
1101+ } ,
1102+ } ) ,
1103+ changesRevision ,
1104+ )
1105+ : null ,
1106+ ) ;
1107+ const resolvedChangesTotals = resolveChangesTotals (
1108+ gitStatusForActions ,
1109+ changesPreview . data ?. sources . find ( ( source ) => source . kind === "branch-range" ) ,
1110+ ) ;
10541111 const changesTotals = resolvedChangesTotals ?? { insertions : 0 , deletions : 0 } ;
10551112 const changesBaseLabel = resolvedChangesTotals
10561113 ? resolvedChangesTotals . baseRef === null
0 commit comments