diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index e5488556e..c21e7037a 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -57,6 +57,8 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty } } + self.getData().DidPaste = false + self.rerender() return nil } @@ -103,7 +105,8 @@ func (self *CherryPickHelper) Paste() error { return err } if !isInRebase { - return self.Reset() + self.getData().DidPaste = true + self.rerender() } return nil }) @@ -114,7 +117,7 @@ func (self *CherryPickHelper) Paste() error { } func (self *CherryPickHelper) CanPaste() bool { - return self.getData().Active() + return self.getData().CanPaste() } func (self *CherryPickHelper) Reset() error { diff --git a/pkg/gui/modes/cherrypicking/cherry_picking.go b/pkg/gui/modes/cherrypicking/cherry_picking.go index 40b9ce287..d84cec39a 100644 --- a/pkg/gui/modes/cherrypicking/cherry_picking.go +++ b/pkg/gui/modes/cherrypicking/cherry_picking.go @@ -12,6 +12,10 @@ type CherryPicking struct { // we only allow cherry picking from one context at a time, so you can't copy a commit from // the local commits context and then also copy a commit in the reflog context ContextKey string + + // keep track of whether the currently copied commits have been pasted already. If so, we hide + // the mode and the blue display of the commits, but we still allow pasting them again. + DidPaste bool } func New() *CherryPicking { @@ -22,10 +26,18 @@ func New() *CherryPicking { } func (self *CherryPicking) Active() bool { + return self.CanPaste() && !self.DidPaste +} + +func (self *CherryPicking) CanPaste() bool { return len(self.CherryPickedCommits) > 0 } func (self *CherryPicking) SelectedHashSet() *set.Set[string] { + if self.DidPaste { + return set.New[string]() + } + hashes := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string { return commit.Hash }) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick.go b/pkg/integration/tests/cherry_pick/cherry_pick.go index c49e5cf38..eefe73692 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick.go @@ -79,5 +79,32 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ Contains("one"), Contains("base"), ) + + // Even though the cherry-picking mode has been reset, it's still possible to paste the copied commits again: + t.Views().Branches(). + Focus(). + NavigateToLine(Contains("master")). + PressPrimaryAction() + + t.Views().Commits(). + Focus(). + Lines( + Contains("base").IsSelected(), + ). + Press(keys.Commits.PasteCommits). + Tap(func() { + t.ExpectPopup().Alert(). + Title(Equals("Cherry-pick")). + Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")). + Confirm() + }). + Tap(func() { + t.Views().Information().Content(DoesNotContain("commits copied")) + }). + Lines( + Contains("four"), + Contains("three"), + Contains("base"), + ) }, })