fix(source-control): wait for a git status read before judging a merged workspace

Before the first status read the change count is zero and HEAD may be stale,
so the notice could call a dirty workspace safe to delete. Use the HEAD from
the latest successful status read and say nothing until one completes.
This commit is contained in:
Jinjing
2026-11-12 14:37:34 -08:00
parent 7b50de783f
commit 20fd3c53de
3 changed files with 21 additions and 6 deletions
@@ -18,7 +18,6 @@ const review: HostedReviewInfo = {
const worktree = {
id: 'repo-1::/work/app-sync',
path: '/work/app-sync',
head: 'a1b2c3d',
branch: 'refs/heads/feature/sync-retry',
isMainWorktree: false
} as Worktree
@@ -31,7 +30,12 @@ export const safeToDelete = defineFixture({
width: 300,
render: () => (
<Frame>
<SourceControlMergedReviewNotice review={review} worktree={worktree} uncommittedCount={0} />
<SourceControlMergedReviewNotice
review={review}
worktree={worktree}
statusHeadOid="a1b2c3d"
uncommittedCount={0}
/>
</Frame>
)
})
@@ -40,7 +44,12 @@ export const uncommittedChanges = defineFixture({
width: 300,
render: () => (
<Frame>
<SourceControlMergedReviewNotice review={review} worktree={worktree} uncommittedCount={2} />
<SourceControlMergedReviewNotice
review={review}
worktree={worktree}
statusHeadOid="a1b2c3d"
uncommittedCount={2}
/>
</Frame>
)
})
@@ -51,7 +60,8 @@ export const headMovedPastReview = defineFixture({
<Frame>
<SourceControlMergedReviewNotice
review={review}
worktree={{ ...worktree, head: 'e4f5a6b' }}
worktree={worktree}
statusHeadOid="e4f5a6b"
uncommittedCount={0}
/>
</Frame>
@@ -17,10 +17,13 @@ import { getDeleteStateForWorktreeHost } from '../../../sidebar/workspace-action
export function SourceControlMergedReviewNotice({
review,
worktree,
statusHeadOid,
uncommittedCount
}: {
review: HostedReviewInfo | null
worktree: Worktree
/** HEAD from the latest successful git status read; null until one completes. */
statusHeadOid: string | null
uncommittedCount: number
}): React.JSX.Element | null {
const t = useTranslate()
@@ -29,10 +32,11 @@ export function SourceControlMergedReviewNotice({
)
const readiness = resolveMergedReviewWorkspaceReadiness({
review,
headOid: worktree.head,
headOid: statusHeadOid,
uncommittedCount
})
if (!review || !readiness) {
// Without a status read the change count is unknown, so say nothing rather than guess.
if (!review || !readiness || !statusHeadOid) {
return null
}
const label = `${
@@ -140,6 +140,7 @@ export function SourceControlPanelContent(props: SourceControlPanelReadyProps) {
<SourceControlMergedReviewNotice
review={model.hostedReview}
worktree={activeWorktree}
statusHeadOid={statusReadError === undefined ? model.activeGitStatusHead : null}
uncommittedCount={model.entries.length}
/>
)}