Skip to content

Commit 8552340

Browse files
committed
Allow pasting commits more than once
After pasting commits once, we hide the cherry-picking status (as if it had been reset), and no longer paint the copied commits with blue hashes; however, we still allow pasting them again. This can be useful e.g. to backport a bugfix to multiple major version release branches.
1 parent f473d23 commit 8552340

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

pkg/gui/controllers/helpers/cherry_pick_helper.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
5757
}
5858
}
5959

60+
self.getData().DidPaste = false
61+
6062
self.rerender()
6163
return nil
6264
}
@@ -103,7 +105,8 @@ func (self *CherryPickHelper) Paste() error {
103105
return err
104106
}
105107
if !isInRebase {
106-
return self.Reset()
108+
self.getData().DidPaste = true
109+
self.rerender()
107110
}
108111
return nil
109112
})
@@ -114,7 +117,7 @@ func (self *CherryPickHelper) Paste() error {
114117
}
115118

116119
func (self *CherryPickHelper) CanPaste() bool {
117-
return self.getData().Active()
120+
return self.getData().CanPaste()
118121
}
119122

120123
func (self *CherryPickHelper) Reset() error {

pkg/gui/modes/cherrypicking/cherry_picking.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ type CherryPicking struct {
1212
// we only allow cherry picking from one context at a time, so you can't copy a commit from
1313
// the local commits context and then also copy a commit in the reflog context
1414
ContextKey string
15+
16+
// keep track of whether the currently copied commits have been pasted already. If so, we hide
17+
// the mode and the blue display of the commits, but we still allow pasting them again.
18+
DidPaste bool
1519
}
1620

1721
func New() *CherryPicking {
@@ -22,10 +26,18 @@ func New() *CherryPicking {
2226
}
2327

2428
func (self *CherryPicking) Active() bool {
29+
return self.CanPaste() && !self.DidPaste
30+
}
31+
32+
func (self *CherryPicking) CanPaste() bool {
2533
return len(self.CherryPickedCommits) > 0
2634
}
2735

2836
func (self *CherryPicking) SelectedHashSet() *set.Set[string] {
37+
if self.DidPaste {
38+
return set.New[string]()
39+
}
40+
2941
hashes := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string {
3042
return commit.Hash
3143
})

pkg/integration/tests/cherry_pick/cherry_pick.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,32 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
7979
Contains("one"),
8080
Contains("base"),
8181
)
82+
83+
// Even though the cherry-picking mode has been reset, it's still possible to paste the copied commits again:
84+
t.Views().Branches().
85+
Focus().
86+
NavigateToLine(Contains("master")).
87+
PressPrimaryAction()
88+
89+
t.Views().Commits().
90+
Focus().
91+
Lines(
92+
Contains("base").IsSelected(),
93+
).
94+
Press(keys.Commits.PasteCommits).
95+
Tap(func() {
96+
t.ExpectPopup().Alert().
97+
Title(Equals("Cherry-pick")).
98+
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
99+
Confirm()
100+
}).
101+
Tap(func() {
102+
t.Views().Information().Content(DoesNotContain("commits copied"))
103+
}).
104+
Lines(
105+
Contains("four"),
106+
Contains("three"),
107+
Contains("base"),
108+
)
82109
},
83110
})

0 commit comments

Comments
 (0)