Skip to content

Commit 0fc107c

Browse files
committed
Adjust selection after cherry-picking commits
Keep the same commit selected, by moving the selection down by the number of cherry-picked commits. We also do this when reverting commits, and it is possible now that we use a sync waiting status. We also need to turn the refresh that happens as part of CheckMergeOrRebase into a sync one, so that the commits list is up to date and the new selection isn't clamped.
1 parent 09a4e0b commit 0fc107c

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

pkg/gui/controllers/helpers/cherry_pick_helper.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,23 @@ func (self *CherryPickHelper) Paste() error {
8787
}
8888
}
8989

90-
result := self.c.Git().Rebase.CherryPickCommits(self.getData().CherryPickedCommits)
91-
err := self.rebaseHelper.CheckMergeOrRebase(result)
90+
cherryPickedCommits := self.getData().CherryPickedCommits
91+
result := self.c.Git().Rebase.CherryPickCommits(cherryPickedCommits)
92+
err := self.rebaseHelper.CheckMergeOrRebaseWithRefreshOptions(result, types.RefreshOptions{Mode: types.SYNC})
9293
if err != nil {
9394
return result
9495
}
9596

97+
// Move the selection down by the number of commits we just
98+
// cherry-picked, to keep the same commit selected as before.
99+
// Don't do this if a rebase todo is selected, because in this
100+
// case we are in a rebase and the cherry-picked commits end up
101+
// below the selection.
102+
if commit := self.c.Contexts().LocalCommits.GetSelected(); commit != nil && !commit.IsTODO() {
103+
self.c.Contexts().LocalCommits.MoveSelection(len(cherryPickedCommits))
104+
self.c.Contexts().LocalCommits.FocusLine()
105+
}
106+
96107
// If we're in the cherry-picking state at this point, it must
97108
// be because there were conflicts. Don't clear the copied
98109
// commits in this case, since we might want to abort and try

pkg/integration/tests/cherry_pick/cherry_pick.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
7373
t.Views().Information().Content(DoesNotContain("commits copied"))
7474
}).
7575
Lines(
76-
Contains("four").IsSelected(),
76+
Contains("four"),
7777
Contains("three"),
78-
Contains("two"),
78+
Contains("two").IsSelected(),
7979
Contains("one"),
8080
Contains("base"),
8181
)
@@ -102,9 +102,9 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
102102
t.Views().Information().Content(DoesNotContain("commits copied"))
103103
}).
104104
Lines(
105-
Contains("four").IsSelected(),
105+
Contains("four"),
106106
Contains("three"),
107-
Contains("base"),
107+
Contains("base").IsSelected(),
108108
)
109109
},
110110
})

pkg/integration/tests/cherry_pick/cherry_pick_during_rebase.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,17 @@ var CherryPickDuringRebase = NewIntegrationTest(NewIntegrationTestArgs{
7979
Contains("--- Pending rebase todos ---"),
8080
Contains("pick CI two"),
8181
Contains("--- Commits ---"),
82-
Contains(" CI three").IsSelected(),
83-
Contains(" CI one"),
82+
Contains(" CI three"),
83+
Contains(" CI one").IsSelected(),
8484
Contains(" CI base"),
8585
).
8686
Tap(func() {
8787
t.Common().ContinueRebase()
8888
}).
8989
Lines(
9090
Contains("CI two"),
91-
Contains("CI three").IsSelected(),
92-
Contains("CI one"),
91+
Contains("CI three"),
92+
Contains("CI one").IsSelected(),
9393
Contains("CI base"),
9494
)
9595
},

pkg/integration/tests/cherry_pick/cherry_pick_merge.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ var CherryPickMerge = NewIntegrationTest(NewIntegrationTestArgs{
6363
t.Views().Information().Content(DoesNotContain("commit copied"))
6464
}).
6565
Lines(
66-
Contains("Merge branch 'second-branch'").IsSelected(),
67-
Contains("base"),
68-
)
66+
Contains("Merge branch 'second-branch'"),
67+
Contains("base").IsSelected(),
68+
).
69+
SelectPreviousItem()
6970

7071
t.Views().Main().ContainsLines(
7172
Contains("Merge branch 'second-branch'"),

pkg/integration/tests/cherry_pick/cherry_pick_range.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ var CherryPickRange = NewIntegrationTest(NewIntegrationTestArgs{
7070
t.Views().Information().Content(DoesNotContain("commits copied"))
7171
}).
7272
Lines(
73-
Contains("four").IsSelected(),
73+
Contains("four"),
7474
Contains("three"),
75-
Contains("two"),
75+
Contains("two").IsSelected(),
7676
Contains("one"),
7777
Contains("base"),
7878
)

pkg/integration/tests/reflog/cherry_pick.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ var CherryPick = NewIntegrationTest(NewIntegrationTestArgs{
4343
Confirm()
4444
}).
4545
Lines(
46-
Contains("three").IsSelected(),
47-
Contains("one"),
46+
Contains("three"),
47+
Contains("one").IsSelected(),
4848
)
4949
},
5050
})

0 commit comments

Comments
 (0)