mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-08-24 10:13:41 -05:00
Don't refresh pull requests when checking out a local branch
For esthetic reasons, checking out a branch (or other ref) blocks the UI until the refresh is done, so it's important that the refresh doesn't do unnecessary work. Refreshing pull requests is unnecessary (but costly, when waiting for it) when a branch is checked out that already existed locally. However, it is required when checking out a remote branch for the first time, so that the PR icon appears immediately when there is one.
This commit is contained in:
@@ -54,7 +54,19 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
||||
// loading a heap of commits is slow so we limit them whenever doing a reset
|
||||
self.c.Contexts().LocalCommits.SetLimitCommits(true)
|
||||
|
||||
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, KeepBranchSelectionIndex: true})
|
||||
scope := []types.RefreshableView{
|
||||
types.COMMITS,
|
||||
types.BRANCHES,
|
||||
types.FILES,
|
||||
types.REFLOG,
|
||||
types.WORKTREES,
|
||||
types.BISECT_INFO,
|
||||
types.STAGING,
|
||||
}
|
||||
if options.RefreshPullRequests {
|
||||
scope = append(scope, types.PULL_REQUESTS)
|
||||
}
|
||||
self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI, Scope: scope, KeepBranchSelectionIndex: true})
|
||||
}
|
||||
|
||||
localBranch, found := lo.Find(self.c.Model().Branches, func(branch *models.Branch) bool {
|
||||
@@ -120,8 +132,8 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
|
||||
|
||||
// Shows a prompt to choose between creating a new branch or checking out a detached head
|
||||
func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchName string) error {
|
||||
checkout := func(branchName string) error {
|
||||
return self.CheckoutRef(branchName, types.CheckoutRefOptions{})
|
||||
checkout := func(branchName string, refreshPullRequests bool) error {
|
||||
return self.CheckoutRef(branchName, types.CheckoutRefOptions{RefreshPullRequests: refreshPullRequests})
|
||||
}
|
||||
|
||||
// If a branch with this name already exists locally, just check it out. We
|
||||
@@ -130,7 +142,7 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN
|
||||
if lo.ContainsBy(self.c.Model().Branches, func(branch *models.Branch) bool {
|
||||
return branch.Name == localBranchName
|
||||
}) {
|
||||
return checkout(localBranchName)
|
||||
return checkout(localBranchName, false)
|
||||
}
|
||||
|
||||
return self.c.Menu(types.CreateMenuOptions{
|
||||
@@ -156,14 +168,14 @@ func (self *RefsHelper) CheckoutRemoteBranch(fullBranchName string, localBranchN
|
||||
Mode: types.SYNC,
|
||||
Scope: []types.RefreshableView{types.BRANCHES},
|
||||
})
|
||||
return checkout(localBranchName)
|
||||
return checkout(localBranchName, true)
|
||||
},
|
||||
},
|
||||
{
|
||||
Label: self.c.Tr.CheckoutTypeDetachedHead,
|
||||
Tooltip: self.c.Tr.CheckoutTypeDetachedHeadTooltip,
|
||||
OnPress: func() error {
|
||||
return checkout(fullBranchName)
|
||||
return checkout(fullBranchName, false)
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -4,4 +4,9 @@ type CheckoutRefOptions struct {
|
||||
WaitingStatus string
|
||||
EnvVars []string
|
||||
OnRefNotFound func(ref string) error
|
||||
|
||||
// Refreshing pull requests is necessary when checking out a branch that doesn't exist locally
|
||||
// (e.g. checking out a remote branch), but it not needed when checking out an existing local
|
||||
// branch or a detached head (e.g. a tag).
|
||||
RefreshPullRequests bool
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user