diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index f0e4993eb..8f5b37a66 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -87,12 +87,23 @@ func (self *CherryPickHelper) Paste() error { } } - result := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits) - err := self.rebaseHelper.CheckMergeOrRebase(result) + cherryPickedCommits := self.getData().CherryPickedCommits + result := self.c.Git().Rebase.CherryPickCommits(cherryPickedCommits) + err := self.rebaseHelper.CheckMergeOrRebaseWithRefreshOptions(result, types.RefreshOptions{Mode: types.SYNC}) if err != nil { return result } + // Move the selection down by the number of commits we just + // cherry-picked, to keep the same commit selected as before. + // Don't do this if a rebase todo is selected, because in this + // case we are in a rebase and the cherry-picked commits end up + // below the selection. + if commit := self.c.Contexts().LocalCommits.GetSelected(); commit != nil && !commit.IsTODO() { + self.c.Contexts().LocalCommits.MoveSelection(len(cherryPickedCommits)) + self.c.Contexts().LocalCommits.FocusLine() + } + // If we're in the cherry-picking state 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 diff --git a/pkg/integration/tests/cherry_pick/cherry_pick.go b/pkg/integration/tests/cherry_pick/cherry_pick.go index 434e15d8c..ccdb606f8 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick.go @@ -73,9 +73,9 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(DoesNotContain("commits copied")) }). Lines( - Contains("four").IsSelected(), + Contains("four"), Contains("three"), - Contains("two"), + Contains("two").IsSelected(), Contains("one"), Contains("base"), ) @@ -102,9 +102,9 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(DoesNotContain("commits copied")) }). Lines( - Contains("four").IsSelected(), + Contains("four"), Contains("three"), - Contains("base"), + Contains("base").IsSelected(), ) }, }) diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_during_rebase.go b/pkg/integration/tests/cherry_pick/cherry_pick_during_rebase.go index e94a0342c..af4e8b9d2 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_during_rebase.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_during_rebase.go @@ -79,8 +79,8 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{ Contains("--- Pending rebase todos ---"), Contains("pick CI two"), Contains("--- Commits ---"), - Contains(" CI three").IsSelected(), - Contains(" CI one"), + Contains(" CI three"), + Contains(" CI one").IsSelected(), Contains(" CI base"), ). Tap(func() { @@ -88,8 +88,8 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{ }). Lines( Contains("CI two"), - Contains("CI three").IsSelected(), - Contains("CI one"), + Contains("CI three"), + Contains("CI one").IsSelected(), Contains("CI base"), ) }, diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_merge.go b/pkg/integration/tests/cherry_pick/cherry_pick_merge.go index 77b523ecc..7c68ce8eb 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_merge.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_merge.go @@ -63,9 +63,10 @@ var CherryPickMerge = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(DoesNotContain("commit copied")) }). Lines( - Contains("Merge branch 'second-branch'").IsSelected(), - Contains("base"), - ) + Contains("Merge branch 'second-branch'"), + Contains("base").IsSelected(), + ). + SelectPreviousItem() t.Views().Main().ContainsLines( Contains("Merge branch 'second-branch'"), diff --git a/pkg/integration/tests/cherry_pick/cherry_pick_range.go b/pkg/integration/tests/cherry_pick/cherry_pick_range.go index fc1c3b2e5..329ef1e9c 100644 --- a/pkg/integration/tests/cherry_pick/cherry_pick_range.go +++ b/pkg/integration/tests/cherry_pick/cherry_pick_range.go @@ -70,9 +70,9 @@ var CherryPickRange = NewIntegrationTest(NewIntegrationTestArgs{ t.Views().Information().Content(DoesNotContain("commits copied")) }). Lines( - Contains("four").IsSelected(), + Contains("four"), Contains("three"), - Contains("two"), + Contains("two").IsSelected(), Contains("one"), Contains("base"), ) diff --git a/pkg/integration/tests/reflog/cherry_pick.go b/pkg/integration/tests/reflog/cherry_pick.go index 1416ef955..1e223c9e0 100644 --- a/pkg/integration/tests/reflog/cherry_pick.go +++ b/pkg/integration/tests/reflog/cherry_pick.go @@ -43,8 +43,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{ Confirm() }). Lines( - Contains("three").IsSelected(), - Contains("one"), + Contains("three"), + Contains("one").IsSelected(), ) }, })