1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 11:02:41 +03:00

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.
This commit is contained in:
Stefan Haller
2024-10-11 10:40:06 +02:00
parent f473d23d65
commit 85523402d6
3 changed files with 44 additions and 2 deletions

View File

@@ -57,6 +57,8 @@ func (self *CherryPickHelper) CopyRange(commitsList []*models.Commit, context ty
} }
} }
self.getData().DidPaste = false
self.rerender() self.rerender()
return nil return nil
} }
@@ -103,7 +105,8 @@ func (self *CherryPickHelper) Paste() error {
return err return err
} }
if !isInRebase { if !isInRebase {
return self.Reset() self.getData().DidPaste = true
self.rerender()
} }
return nil return nil
}) })
@@ -114,7 +117,7 @@ func (self *CherryPickHelper) Paste() error {
} }
func (self *CherryPickHelper) CanPaste() bool { func (self *CherryPickHelper) CanPaste() bool {
return self.getData().Active() return self.getData().CanPaste()
} }
func (self *CherryPickHelper) Reset() error { func (self *CherryPickHelper) Reset() error {

View File

@@ -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 // 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 // the local commits context and then also copy a commit in the reflog context
ContextKey string 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 { func New() *CherryPicking {
@@ -22,10 +26,18 @@ func New() *CherryPicking {
} }
func (self *CherryPicking) Active() bool { func (self *CherryPicking) Active() bool {
return self.CanPaste() && !self.DidPaste
}
func (self *CherryPicking) CanPaste() bool {
return len(self.CherryPickedCommits) > 0 return len(self.CherryPickedCommits) > 0
} }
func (self *CherryPicking) SelectedHashSet() *set.Set[string] { 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 { hashes := lo.Map(self.CherryPickedCommits, func(commit *models.Commit, _ int) string {
return commit.Hash return commit.Hash
}) })

View File

@@ -79,5 +79,32 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("one"), Contains("one"),
Contains("base"), 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"),
)
}, },
}) })