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:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user