diff --git a/pkg/gui/branchstack/branchstack.go b/pkg/gui/branchstack/branchstack.go index 5455fe442..c691cda73 100644 --- a/pkg/gui/branchstack/branchstack.go +++ b/pkg/gui/branchstack/branchstack.go @@ -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) } } diff --git a/pkg/gui/presentation/commits.go b/pkg/gui/presentation/commits.go index 20660513d..23efd5451 100644 --- a/pkg/gui/presentation/commits.go +++ b/pkg/gui/presentation/commits.go @@ -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()) }))