Extract the rule for which branches can be part of a stack

When moving commits outside of a rebase, we will need to know where the
branch boundaries of a stack are. These are the heads of the branches
that the commits list marks, so we want to use the same rule there.

Put the rule in the branchstack package. BranchesBelow had its own copy
of it, so use it there too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan HallerandClaude Opus 5.5 committed 2026-11-12 15:26:10 +01:00
1 parent f794d3460d
commit 39252fea94
2 files changed
+16 -15

No files matched your search

+14 -1
View File
@@ -6,6 +6,19 @@ import (
"github.com/samber/lo"
)
// IsStackBranch tells whether the given branch can be one of the stack of
// branches below the current branch. The commits list visualizes them with
// markers at their heads. The current branch and the main branches are not,
// because the goal is to show stacks of local branches, and they don't
// contribute to one.
func IsStackBranch(branch *models.Branch, currentBranchName string, mainBranches []string) bool {
// Branches without a commit hash are excluded too. As far as I can see,
// this happens for a detached head.
return branch.CommitHash != "" &&
branch.Name != currentBranchName &&
!lo.Contains(mainBranches, branch.Name)
}
// Returns the branches stacked below the branch with the given name: those
// whose tip is one of the given commits of the branch that hasn't been
// merged into a main branch yet. The branch itself and the main branches
@@ -28,7 +41,7 @@ func BranchesBelow(
) []*models.Branch {
branchesByTip := map[string][]*models.Branch{}
for _, other := range branches {
if !lo.Contains(mainBranches, other.Name) && other.Name != branchName {
if IsStackBranch(other, branchName, mainBranches) {
branchesByTip[other.CommitHash] = append(branchesByTip[other.CommitHash], other)
}
}
+2 -14
View File
@@ -156,26 +156,14 @@ func GetCommitListDisplayStrings(
}
// Determine the hashes of the local branches for which we want to show a
// branch marker in the commits list. We only want to do this for branches
// that are not the current branch, and not any of the main branches. The
// goal is to visualize stacks of local branches, so anything that doesn't
// contribute to a branch stack shouldn't show a marker.
// branch marker in the commits list.
//
// If there are other branches pointing to the current head commit, we only
// want to show the marker if the rebase.updateRefs config is on.
branchHeadsToVisualize := set.NewFromSlice(lo.FilterMap(branches,
func(b *models.Branch, index int) (string, bool) {
return b.CommitHash,
// Don't consider branches that don't have a commit hash. As far
// as I can see, this happens for a detached head, so filter
// these out
b.CommitHash != "" &&
// Don't show a marker for the current branch
b.Name != currentBranchName &&
// Don't show a marker for main branches
!lo.Contains(common.UserConfig().Git.MainBranches, b.Name) &&
// Don't show a marker for the head commit unless the
// rebase.updateRefs config is on
branchstack.IsStackBranch(b, currentBranchName, common.UserConfig().Git.MainBranches) &&
(hasRebaseUpdateRefsConfig || b.CommitHash != commits[0].Hash())
}))