From f032ee8b0f36747b4edfeab178e82e2a4d32c643 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Thu, 21 May 2026 11:57:02 +0200 Subject: [PATCH] Extract BranchesHelper.PostFetchRefresh to unify the two fetch paths The post-fetch logic was duplicated in `backgroundFetch` and the manual fetch handler: refresh a fixed set of views, then auto-forward branches if the fetch succeeded. The two had already drifted on the refresh scope; folding them into a single helper makes the duplication go away and prevents it from drifting again. Pass the fetch error through so we preserve the previous behaviour of refreshing unconditionally but only auto-forwarding on success. Co-Authored-By: Claude Opus 4.7 (1M context) --- pkg/gui/background.go | 8 +------- pkg/gui/controllers/files_controller.go | 8 +------- pkg/gui/controllers/helpers/branches_helper.go | 13 +++++++++++++ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/pkg/gui/background.go b/pkg/gui/background.go index cedc6a78c..8795b49aa 100644 --- a/pkg/gui/background.go +++ b/pkg/gui/background.go @@ -155,13 +155,7 @@ func (self *BackgroundRoutineMgr) goEvery(interval time.Duration, stop chan stru func (self *BackgroundRoutineMgr) backgroundFetch() (err error) { err = self.gui.git.Sync.FetchBackground() - self.gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS, types.PULL_REQUESTS}, Mode: types.SYNC}) - - if err == nil { - err = self.gui.helpers.BranchesHelper.AutoForwardBranches() - } - - return err + return self.gui.helpers.BranchesHelper.PostFetchRefresh(err) } func (self *BackgroundRoutineMgr) triggerImmediateFetch() { diff --git a/pkg/gui/controllers/files_controller.go b/pkg/gui/controllers/files_controller.go index 1513a324e..c8d50d54d 100644 --- a/pkg/gui/controllers/files_controller.go +++ b/pkg/gui/controllers/files_controller.go @@ -1348,13 +1348,7 @@ func (self *FilesController) fetch() error { return errors.New(self.c.Tr.PassUnameWrong) } - self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS, types.PULL_REQUESTS}, Mode: types.SYNC}) - - if err == nil { - err = self.c.Helpers().BranchesHelper.AutoForwardBranches() - } - - return err + return self.c.Helpers().BranchesHelper.PostFetchRefresh(err) }) } diff --git a/pkg/gui/controllers/helpers/branches_helper.go b/pkg/gui/controllers/helpers/branches_helper.go index c3f4242bf..a53bf2181 100644 --- a/pkg/gui/controllers/helpers/branches_helper.go +++ b/pkg/gui/controllers/helpers/branches_helper.go @@ -285,6 +285,19 @@ func (self *BranchesHelper) deleteRemoteBranches(remoteBranches []*models.Remote return nil } +func (self *BranchesHelper) PostFetchRefresh(fetchErr error) error { + self.c.Refresh(types.RefreshOptions{ + Scope: []types.RefreshableView{ + types.BRANCHES, types.COMMITS, types.REMOTES, types.TAGS, types.PULL_REQUESTS, + }, + Mode: types.SYNC, + }) + if fetchErr != nil { + return fetchErr + } + return self.AutoForwardBranches() +} + func (self *BranchesHelper) AutoForwardBranches() error { if self.c.UserConfig().Git.AutoForwardBranches == "none" { return nil