diff options
author | Stefan Haller <stefan@haller-berlin.de> | 2024-05-03 19:30:31 +0200 |
---|---|---|
committer | Stefan Haller <stefan@haller-berlin.de> | 2024-06-03 14:06:11 +0200 |
commit | ddf5e24499fb8ca91ca67f8efa887b74bebb5a70 (patch) | |
tree | 50155059c5992f95776b62b43eeee9c3315715c0 /pkg | |
parent | ca6d88080cef1ab768fc088081d1962e110234e8 (diff) |
Always show rebase menu, even when rebasing is not possible
Instead, disable the individual entries in the menu.
This is necessary because we are going to add another entry to the menu that is
independent of the selected branch.
Diffstat (limited to 'pkg')
-rw-r--r-- | pkg/gui/controllers/branches_controller.go | 31 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/merge_and_rebase_helper.go | 16 |
2 files changed, 20 insertions, 27 deletions
diff --git a/pkg/gui/controllers/branches_controller.go b/pkg/gui/controllers/branches_controller.go index c975d500d..62eda703e 100644 --- a/pkg/gui/controllers/branches_controller.go +++ b/pkg/gui/controllers/branches_controller.go @@ -100,15 +100,13 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty DisplayOnScreen: true, }, { - Key: opts.GetKey(opts.Config.Branches.RebaseBranch), - Handler: opts.Guards.OutsideFilterMode(self.rebase), - GetDisabledReason: self.require( - self.singleItemSelected(self.notRebasingOntoSelf), - ), - Description: self.c.Tr.RebaseBranch, - Tooltip: self.c.Tr.RebaseBranchTooltip, - OpensMenu: true, - DisplayOnScreen: true, + Key: opts.GetKey(opts.Config.Branches.RebaseBranch), + Handler: opts.Guards.OutsideFilterMode(self.withItem(self.rebase)), + GetDisabledReason: self.require(self.singleItemSelected()), + Description: self.c.Tr.RebaseBranch, + Tooltip: self.c.Tr.RebaseBranchTooltip, + OpensMenu: true, + DisplayOnScreen: true, }, { Key: opts.GetKey(opts.Config.Branches.MergeIntoCurrentBranch), @@ -634,19 +632,8 @@ func (self *BranchesController) merge() error { return self.c.Helpers().MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName) } -func (self *BranchesController) rebase() error { - selectedBranchName := self.context().GetSelected().Name - return self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranchName) -} - -func (self *BranchesController) notRebasingOntoSelf(branch *models.Branch) *types.DisabledReason { - selectedBranchName := branch.Name - checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef().Name - if selectedBranchName == checkedOutBranch { - return &types.DisabledReason{Text: self.c.Tr.CantRebaseOntoSelf} - } - - return nil +func (self *BranchesController) rebase(branch *models.Branch) error { + return self.c.Helpers().MergeAndRebase.RebaseOntoRef(branch.Name) } func (self *BranchesController) fastForward(branch *models.Branch) error { diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 4bffcfa99..35903ea64 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -235,10 +235,15 @@ func (self *MergeAndRebaseHelper) PromptToContinueRebase() error { func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { checkedOutBranch := self.refsHelper.GetCheckedOutRef().Name + var disabledReason *types.DisabledReason + if checkedOutBranch == ref { + disabledReason = &types.DisabledReason{Text: self.c.Tr.CantRebaseOntoSelf} + } menuItems := []*types.MenuItem{ { - Label: self.c.Tr.SimpleRebase, - Key: 's', + Label: self.c.Tr.SimpleRebase, + Key: 's', + DisabledReason: disabledReason, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.RebaseBranch) return self.c.WithWaitingStatus(self.c.Tr.RebasingStatus, func(task gocui.Task) error { @@ -258,9 +263,10 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { }, }, { - Label: self.c.Tr.InteractiveRebase, - Key: 'i', - Tooltip: self.c.Tr.InteractiveRebaseTooltip, + Label: self.c.Tr.InteractiveRebase, + Key: 'i', + DisabledReason: disabledReason, + Tooltip: self.c.Tr.InteractiveRebaseTooltip, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.RebaseBranch) baseCommit := self.c.Modes().MarkedBaseCommit.GetHash() |