diff --git a/app/src/context_chips/current_prompt.rs b/app/src/context_chips/current_prompt.rs index ef779c6e29..5aa05d4819 100644 --- a/app/src/context_chips/current_prompt.rs +++ b/app/src/context_chips/current_prompt.rs @@ -773,6 +773,16 @@ impl CurrentPrompt { output: value.as_ref(), timed_out, }); + // GitDiffStats has two value sources that can race when entering a repo: + // this shell fallback (`git diff --shortstat HEAD`, tracked changes only) + // and a repo-status watcher that also counts untracked files. If the + // watcher attached while this fallback was in flight, drop the fallback's + // result + if matches!(chip_kind, ContextChipKind::GitDiffStats) + && me.is_updated_externally(&chip_kind) + { + return; + } if timed_out { if suppress_on_failure @@ -1431,6 +1441,16 @@ impl CurrentPrompt { } } + // Repo detached, clear GitDiffStats. + if handle.is_none() { + if let Some(state) = self.states.get_mut(&ContextChipKind::GitDiffStats) { + state.clear_abort_handlers(); + state.clear_cache(); + } + let _ = self.update_tx.try_send(()); + return; + } + if let Some(weak) = handle { if let Some(strong) = weak.upgrade(ctx) { self.git_repo_status = Some(weak);