1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2026-05-22 10:15:43 +02:00

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) <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-05-21 11:57:02 +02:00
parent 77652863c4
commit f032ee8b0f
3 changed files with 15 additions and 14 deletions
+1 -7
View File
@@ -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() {
+1 -7
View File
@@ -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)
})
}
@@ -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