Make "go to bottom" in a divergence view stop at the last remote commit

The divergence view shows the remote commits in a section above the
local ones. Pressing '>' now goes to the beginning of the remote section
before it goes on to the bottom of the local one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-11-08 14:08:51 +01:00
co-authored by Claude Opus 5.5
parent 280c67ff98
commit af0e6ab7f2
2 changed files with 39 additions and 0 deletions
@@ -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)
}
@@ -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 {