diff options
author | molejnik88 <maciej.olejnik88@gmail.com> | 2024-01-20 13:55:25 +0000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2024-01-30 09:21:12 +1100 |
commit | ee173ff7c9f0a7c4279982c2361c12e0d1897504 (patch) | |
tree | 086a73477ce574ab1159ee3af3bf08ffee7c5088 /pkg/gui/controllers/helpers/cherry_pick_helper.go | |
parent | 761c77f5a278c998afe8ca5c34e1b832185d6b3b (diff) |
Clear cherry-picked commits after pasting
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.
The only exception is a merge conflict. Initially, I wanted to clear
selected commits in this scenario too. During a discussion we found out
that it may be convenient to have the copied commits still around.
Aborting the rebase and pasting the commits in the middle of a branch
can be a valid use case.
Diffstat (limited to 'pkg/gui/controllers/helpers/cherry_pick_helper.go')
-rw-r--r-- | pkg/gui/controllers/helpers/cherry_pick_helper.go | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 61a37220b..137d0626d 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -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 }) }, }) |