diff --git a/pkg/gui/context/commit_list_goto_bottom.go b/pkg/gui/context/commit_list_goto_bottom.go index 288d276d6..92da10b17 100644 --- a/pkg/gui/context/commit_list_goto_bottom.go +++ b/pkg/gui/context/commit_list_goto_bottom.go @@ -19,6 +19,7 @@ import ( // - each branch of a stack, given by branchesBelow. Among the todos of a // rebase, update-ref todos separate the branches. // - the commits that aren't merged into a main branch yet +// - the remote commits of a divergence view, which are above the local ones // // During a bisect, it stops at the bottommost commit marked bad, at the commit // to test, and at the topmost commit marked good instead. The commits list @@ -61,6 +62,12 @@ func indexForGotoBottomInCommits( stops = append(stops, idx-1) } + if _, idx, found := lo.FindIndexOf(commits, func(c *models.Commit) bool { + return c.Divergence == models.DivergenceLeft + }); found { + stops = append(stops, idx-1) + } + return closestStopBelow(stops, selectedIdx, len(commits)-1) } diff --git a/pkg/gui/context/commit_list_goto_bottom_test.go b/pkg/gui/context/commit_list_goto_bottom_test.go index 36956b1e2..b6b653b85 100644 --- a/pkg/gui/context/commit_list_goto_bottom_test.go +++ b/pkg/gui/context/commit_list_goto_bottom_test.go @@ -40,6 +40,9 @@ func TestIndexForGotoBottomInCommits(t *testing.T) { Name: "refs/heads/" + branchName, Action: todo.UpdateRef, Status: models.StatusRebasing, }) } + divergentCommit := func(hash string, divergence models.Divergence) *models.Commit { + return models.NewCommit(hashPool, models.NewCommitOpts{Hash: hash, Divergence: divergence}) + } branch := func(name string, tip string) *models.Branch { return &models.Branch{Name: name, CommitHash: tip} } @@ -62,6 +65,14 @@ func TestIndexForGotoBottomInCommits(t *testing.T) { commit("m1", models.StatusMerged), } + divergenceCommits := []*models.Commit{ + divergentCommit("r2", models.DivergenceRight), + divergentCommit("r1", models.DivergenceRight), + divergentCommit("l3", models.DivergenceLeft), + divergentCommit("l2", models.DivergenceLeft), + divergentCommit("l1", models.DivergenceLeft), + } + scenarios := []struct { testName string selectedIdx int @@ -182,6 +193,27 @@ func TestIndexForGotoBottomInCommits(t *testing.T) { branchesBelow: []*models.Branch{}, expected: 4, }, + { + testName: "goes to the beginning of the remote commits of a divergence view", + selectedIdx: 0, + commits: divergenceCommits, + expected: 1, + }, + { + testName: "goes from the remote commits of a divergence view to the bottom", + selectedIdx: 1, + commits: divergenceCommits, + expected: 4, + }, + { + testName: "goes to the bottom of a divergence view without remote commits", + selectedIdx: 0, + commits: []*models.Commit{ + divergentCommit("l2", models.DivergenceLeft), + divergentCommit("l1", models.DivergenceLeft), + }, + expected: 1, + }, } for _, s := range scenarios {