From e92b04e1dc60bf7c3a0293597b0d2506a4a03f98 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Tue, 31 Mar 2026 16:15:37 +0200 Subject: [PATCH] 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. --- pkg/gui/controllers/helpers/refs_helper.go | 24 ++++++++++++++++------ pkg/gui/types/common_commands.go | 5 +++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index d52d9bbad..791f0d481 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -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) }, }, }, diff --git a/pkg/gui/types/common_commands.go b/pkg/gui/types/common_commands.go index 74bfd603b..3b74477fc 100644 --- a/pkg/gui/types/common_commands.go +++ b/pkg/gui/types/common_commands.go @@ -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 }