mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-30 03:23:08 +03:00
Visualize local branch heads in commits panel
We want to mark all local branch heads with a "*" in the local commits panel, to make it easier to see how branches are stacked onto each other. In order to not confuse users with "*" markers that they don't understand, do this only for the case where users actually use stacked branches; those users are likely not going to be confused by the display. This means we want to filter out a few branch heads that shouldn't get the marker: the current branch, any main branch, and any old branch that has been merged to master already.
This commit is contained in:
@ -39,6 +39,8 @@ type bisectBounds struct {
|
||||
func GetCommitListDisplayStrings(
|
||||
common *common.Common,
|
||||
commits []*models.Commit,
|
||||
branches []*models.Branch,
|
||||
currentBranchName string,
|
||||
fullDescription bool,
|
||||
cherryPickedCommitShaSet *set.Set[string],
|
||||
diffName string,
|
||||
@ -99,6 +101,24 @@ func GetCommitListDisplayStrings(
|
||||
getGraphLine = func(idx int) string { return "" }
|
||||
}
|
||||
|
||||
// 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.
|
||||
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)
|
||||
}))
|
||||
|
||||
lines := make([][]string, 0, len(filteredCommits))
|
||||
var bisectStatus BisectStatus
|
||||
for i, commit := range filteredCommits {
|
||||
@ -112,6 +132,7 @@ func GetCommitListDisplayStrings(
|
||||
lines = append(lines, displayCommit(
|
||||
common,
|
||||
commit,
|
||||
branchHeadsToVisualize,
|
||||
cherryPickedCommitShaSet,
|
||||
diffName,
|
||||
timeFormat,
|
||||
@ -260,6 +281,7 @@ func getBisectStatusText(bisectStatus BisectStatus, bisectInfo *git_commands.Bis
|
||||
func displayCommit(
|
||||
common *common.Common,
|
||||
commit *models.Commit,
|
||||
branchHeadsToVisualize *set.Set[string],
|
||||
cherryPickedCommitShaSet *set.Set[string],
|
||||
diffName string,
|
||||
timeFormat string,
|
||||
@ -290,6 +312,11 @@ func displayCommit(
|
||||
if len(commit.Tags) > 0 {
|
||||
tagString = theme.DiffTerminalColor.SetBold().Sprint(strings.Join(commit.Tags, " ")) + " "
|
||||
}
|
||||
|
||||
if branchHeadsToVisualize.Includes(commit.Sha) && commit.Status != models.StatusMerged {
|
||||
tagString = style.FgCyan.SetBold().Sprint(
|
||||
lo.Ternary(icons.IsIconEnabled(), icons.BRANCH_ICON, "*") + " " + tagString)
|
||||
}
|
||||
}
|
||||
|
||||
name := commit.Name
|
||||
|
Reference in New Issue
Block a user