Don't mark branches merged into a local main branch in the commits list

If a branch was merged into a local main branch, but the main branch
wasn't pushed yet, the commits list still marks the head of the branch
as part of a stack. For example, after merging wip into master locally,
the commits of master show a marker at the head of wip.

Pushing and pulling a stack leave such branches out since #6169, and the
markers disappear as soon as the main branch is pushed. Leave them out
of the markers too, so that the markers show the same stack.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Stefan Haller
2026-11-08 12:40:06 +01:00
co-authored by Claude Opus 5.5
parent c84a181de9
commit 89c6f0ce5a
2 changed files with 40 additions and 2 deletions
+9 -2
View File
@@ -9,6 +9,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/gui/branchstack"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/authors"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/graph"
"github.com/jesseduffield/lazygit/pkg/gui/presentation/icons"
@@ -182,6 +183,9 @@ func GetCommitListDisplayStrings(
commits, common.UserConfig().Gui.CommitHashLength, fullDescription,
timeFormat, shortTimeFormat, now, bisectInfo)
mergedIntoLocalMainBranch := branchstack.CommitsMergedIntoLocalMainBranch(
commits, branches, common.UserConfig().Git.MainBranches)
lines := make([][]string, 0, len(filteredCommits))
var bisectStatus BisectStatus
willBeRebased := markedBaseCommit == ""
@@ -196,6 +200,7 @@ func GetCommitListDisplayStrings(
common,
commit,
branchHeadsToVisualize,
mergedIntoLocalMainBranch.Includes(commit.Hash()),
hasRebaseUpdateRefsConfig,
cherryPickedCommitHashSet,
isMarkedBaseCommit,
@@ -401,6 +406,7 @@ func displayCommit(
common *common.Common,
commit *models.Commit,
branchHeadsToVisualize *set.Set[string],
isMergedIntoLocalMainBranch bool,
hasRebaseUpdateRefsConfig bool,
cherryPickedCommitHashSet *set.Set[string],
isMarkedBaseCommit bool,
@@ -457,8 +463,9 @@ func displayCommit(
}
if branchHeadsToVisualize.Includes(commit.Hash()) &&
// Don't show branch head on commits that are already merged to a main branch
commit.Status != models.StatusMerged &&
// Don't show branch head on commits that are already merged to a
// main branch, be it its remote branch or the local one
commit.Status != models.StatusMerged && !isMergedIntoLocalMainBranch &&
// Don't show branch head on a "pick" todo if the rebase.updateRefs config is on
!(commit.IsTODO() && hasRebaseUpdateRefsConfig) {
tagString = style.FgCyan.SetBold().Sprint(
+31
View File
@@ -126,6 +126,37 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
hash4 commit4
`),
},
{
testName: "don't show branch heads of branches merged into a local main branch",
commitOpts: []models.NewCommitOpts{
{Name: "commit1", Hash: "hash1", Parents: []string{"hash2"}},
{Name: "commit2", Hash: "hash2", Parents: []string{"hash3"}},
{Name: "commit3", Hash: "hash3", Parents: []string{"hash4"}},
{Name: "commit4", Hash: "hash4", Parents: []string{"hash5"}},
{Name: "commit5", Hash: "hash5", Status: models.StatusMerged},
},
branches: []*models.Branch{
{Name: "current-branch", CommitHash: "hash1", Head: true},
{Name: "other-branch", CommitHash: "hash2", Head: false},
{Name: "master", CommitHash: "hash3", Head: false},
{Name: "merged-into-local-master", CommitHash: "hash4", Head: false},
},
currentBranchName: "current-branch",
hasUpdateRefConfig: true,
startIdx: 0,
endIdx: 5,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitHashSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
hash1 commit1
hash2 * commit2
hash3 commit3
hash4 commit4
hash5 commit5
`),
},
{
testName: "show local branch head for head commit if updateRefs is on",
commitOpts: []models.NewCommitOpts{