Don't pop up errors from a refresh worker once the repo was switched

An error returned from a gocui worker is shown to the user in an error
popup. For the branch loader's behind-counts worker that used to be the
"no such ref" popup when a background refresh crossed a repo switch:
the old repo's main branch didn't exist in the new repo. The previous
commits fix that scenario properly — the command now runs against the
repo the refresh was started for — but a stale worker can still fail
legitimately, most plausibly because that repo was deleted after
switching away from it (e.g. removing a worktree). Its results are
dropped anyway, so log the error instead of alarming the user about a
repo they already left.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller 2026-07-19 22:34:08 +02:00
parent 7c0fa9fe33
commit 8e045653be

View file

@ -1039,7 +1039,18 @@ func (self *RefreshHelper) refreshBranches(captured capturedBranchState, refresh
loadBehindCounts,
func(f func() error) {
self.onWorker(env.background, func(_ gocui.Task) error {
return f()
err := f()
if err != nil && self.c.State().GetRepoGeneration() != env.generation {
// An error returned from a worker is shown in a popup. Don't
// do that if the repo was switched while this worker was in
// flight: its results are dropped anyway, and the error
// concerns a repo the user has already left — e.g. failing to
// compute the behind-counts for a worktree that was deleted
// after switching away from it.
self.c.Log.Warnf("dropping error from a stale refresh worker after a repo switch: %v", err)
return nil
}
return err
})
},
func() {