diff --git a/pkg/gui/controllers/basic_commits_controller.go b/pkg/gui/controllers/basic_commits_controller.go index 5a4e4190e..a589e3828 100644 --- a/pkg/gui/controllers/basic_commits_controller.go +++ b/pkg/gui/controllers/basic_commits_controller.go @@ -84,9 +84,10 @@ func (self *BasicCommitsController) GetKeybindings(opts types.KeybindingsOpts) [ DisplayOnScreen: true, }, { - Key: opts.GetKey(opts.Config.Commits.CherryPickCopy), - Handler: self.withItem(self.copyRange), - Description: self.c.Tr.CherryPickCopy, + Key: opts.GetKey(opts.Config.Commits.CherryPickCopy), + Handler: self.withItem(self.copyRange), + GetDisabledReason: self.require(self.itemRangeSelected(self.canCopyCommits)), + Description: self.c.Tr.CherryPickCopy, Tooltip: utils.ResolvePlaceholderString(self.c.Tr.CherryPickCopyTooltip, map[string]string{ "paste": keybindings.Label(opts.Config.Commits.PasteCommits), @@ -292,6 +293,20 @@ func (self *BasicCommitsController) copyRange(*models.Commit) error { return self.c.Helpers().CherryPick.CopyRange(self.context.GetCommits(), self.context) } +func (self *BasicCommitsController) canCopyCommits(selectedCommits []*models.Commit, startIdx int, endIdx int) *types.DisabledReason { + for _, commit := range selectedCommits { + if commit.Sha == "" { + return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickNonCommit, ShowErrorInPanel: true} + } + + if commit.IsMerge() { + return &types.DisabledReason{Text: self.c.Tr.CannotCherryPickMergeCommit, ShowErrorInPanel: true} + } + } + + return nil +} + func (self *BasicCommitsController) handleOldCherryPickKey() error { msg := utils.ResolvePlaceholderString(self.c.Tr.OldCherryPickKeyWarning, map[string]string{ diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 137d0626d..e57d743b7 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -31,21 +31,6 @@ func (self *CherryPickHelper) getData() *cherrypicking.CherryPicking { return self.c.Modes().CherryPicking } -func (self *CherryPickHelper) Copy(commit *models.Commit, commitsList []*models.Commit, context types.Context) error { - if err := self.resetIfNecessary(context); err != nil { - return err - } - - // we will un-copy it if it's already copied - if self.getData().SelectedShaSet().Includes(commit.Sha) { - self.getData().Remove(commit, commitsList) - } else { - self.getData().Add(commit, commitsList) - } - - return self.rerender() -} - func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context types.IListContext) error { startIdx, endIdx := context.GetList().GetSelectionRange() diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index 5ff58d085..048f0e6c4 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -302,6 +302,8 @@ type TranslationSet struct { PasteCommits string SureCherryPick string CherryPick string + CannotCherryPickNonCommit string + CannotCherryPickMergeCommit string Donate string AskQuestion string PrevLine string @@ -1242,6 +1244,8 @@ func EnglishTranslationSet() TranslationSet { PasteCommits: "Paste (cherry-pick)", SureCherryPick: "Are you sure you want to cherry-pick the copied commits onto this branch?", CherryPick: "Cherry-pick", + CannotCherryPickNonCommit: "Cannot cherry-pick this kind of todo item", + CannotCherryPickMergeCommit: "Cherry-picking merge commits is not supported", Donate: "Donate", AskQuestion: "Ask Question", PrevLine: "Select previous line",