diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index a8e48c052..119381f63 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -34,9 +34,10 @@ func NewBranchesController( func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding { return []*types.Binding{ { - Key: opts.GetKey(opts.Config.Universal.Select), - Handler: self.checkSelected(self.press), - Description: self.c.Tr.Checkout, + Key: opts.GetKey(opts.Config.Universal.Select), + Handler: self.checkSelected(self.press), + GetDisabledReason: self.getDisabledReasonForPress, + Description: self.c.Tr.Checkout, }, { Key: opts.GetKey(opts.Config.Universal.New), @@ -299,6 +300,18 @@ func (self *BranchesController) press(selectedBranch *models.Branch) error { return self.c.Helpers().Refs.CheckoutRef(selectedBranch.Name, types.CheckoutRefOptions{}) } +func (self *BranchesController) getDisabledReasonForPress() string { + currentBranch := self.c.Helpers().Refs.GetCheckedOutRef() + if currentBranch != nil { + op := self.c.State().GetRefOperation(currentBranch.FullRefName()) + if op == types.RefOperationFastForwarding || op == types.RefOperationPulling { + return self.c.Tr.CantCheckoutBranchWhilePulling + } + } + + return "" +} + func (self *BranchesController) worktreeForBranch(branch *models.Branch) (*models.Worktree, bool) { return git_commands.WorktreeForBranch(branch, self.c.Model().Worktrees) } diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 454a2a739..b02853a93 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -57,6 +57,7 @@ type TranslationSet struct { ResetFilter string MergeConflictsTitle string Checkout string + CantCheckoutBranchWhilePulling string NoChangedFiles string SoftReset string AlreadyCheckedOutBranch string @@ -847,6 +848,7 @@ func EnglishTranslationSet() TranslationSet { Scroll: "Scroll", MergeConflictsTitle: "Merge conflicts", Checkout: "Checkout", + CantCheckoutBranchWhilePulling: "You cannot checkout another branch while pulling the current branch", FileFilter: "Filter files by status", FilterStagedFiles: "Show only staged files", FilterUnstagedFiles: "Show only unstaged files",