1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-02-01 13:17:53 +02:00

Clear cherry-picked commits after pasting (#3240)

It can be tedious after each cherry-pick opearation to clear the
selection by pressing escape in order for lazygit to stop displaying
info about copied commits. Also, it seems to be a rare case to
cherry-pick commits to more than one destination.

The simplest solution to address this issue is to clear the selection
upon paste, including merge conflict scenario.
Previously discussed in #3198.
This commit is contained in:
Stefan Haller 2024-01-30 08:59:38 +01:00 committed by GitHub
commit 607034a61e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 20 deletions

View File

@ -90,15 +90,36 @@ func (self *CherryPickHelper) Paste() error {
if err := self.c.Git().Rebase.CherryPickCommitsDuringRebase(self.getData().CherryPickedCommits); err != nil {
return err
}
return self.c.Refresh(types.RefreshOptions{
err = self.c.Refresh(types.RefreshOptions{
Mode: types.SYNC, Scope: []types.RefreshableView{types.REBASE_COMMITS},
})
if err != nil {
return err
}
return self.Reset()
}
return self.c.WithWaitingStatus(self.c.Tr.CherryPickingStatus, func(gocui.Task) error {
self.c.LogAction(self.c.Tr.Actions.CherryPick)
err := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
return self.rebaseHelper.CheckMergeOrRebase(err)
err = self.rebaseHelper.CheckMergeOrRebase(err)
if err != nil {
return err
}
// If we're in an interactive rebase at this point, it must
// be because there were conflicts. Don't clear the copied
// commits in this case, since we might want to abort and
// try pasting them again.
isInRebase, err = self.c.Git().Status.IsInInteractiveRebase()
if err != nil {
return err
}
if !isInRebase {
return self.Reset()
}
return nil
})
},
})

View File

@ -59,26 +59,25 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
Contains("base"),
).
Press(keys.Commits.PasteCommits).
Tap(func() {
// cherry-picked commits will be deleted after confirmation
t.Views().Information().Content(Contains("2 commits copied"))
}).
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("two"),
Contains("one"),
Contains("base"),
).
Tap(func() {
// we need to manually exit out of cherry pick mode
t.Views().Information().Content(Contains("2 commits copied"))
}).
PressEscape().
Tap(func() {
t.Views().Information().Content(DoesNotContain("commits copied"))
})
)
},
})

View File

@ -54,6 +54,10 @@ var CherryPickConflicts = NewIntegrationTest(NewIntegrationTestArgs{
t.Common().AcknowledgeConflicts()
// cherry pick selection is not cleared when there are conflicts, so that the user
// is able to abort and try again without having to re-copy the commits
t.Views().Information().Content(Contains("2 commits copied"))
t.Views().Files().
IsFocused().
SelectedLine(Contains("file")).

View File

@ -68,6 +68,9 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
Content(Contains("Are you sure you want to cherry-pick the copied commits onto this branch?")).
Confirm()
}).
Tap(func() {
t.Views().Information().Content(DoesNotContain("commit copied"))
}).
Lines(
Contains("pick CI two"),
Contains("pick CI three"),

View File

@ -66,20 +66,15 @@ var CherryPickRange = NewIntegrationTest(NewIntegrationTestArgs{
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("two"),
Contains("one"),
Contains("base"),
).
Tap(func() {
// we need to manually exit out of cherry pick mode
t.Views().Information().Content(Contains("2 commits copied"))
}).
PressEscape().
Tap(func() {
t.Views().Information().Content(DoesNotContain("commits copied"))
})
)
},
})