1
0
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:
Stefan Haller
2023-07-11 12:13:40 +02:00
parent 0c07963a2e
commit 6dc25d796b
6 changed files with 122 additions and 5 deletions

View File

@ -28,6 +28,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
scenarios := []struct {
testName string
commits []*models.Commit
branches []*models.Branch
currentBranchName string
fullDescription bool
cherryPickedCommitShaSet *set.Set[string]
diffName string
@ -72,6 +74,73 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
sha2 commit2
`),
},
{
testName: "commit with tags",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1", Tags: []string{"tag1", "tag2"}},
{Name: "commit2", Sha: "sha2"},
},
startIdx: 0,
length: 2,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 tag1 tag2 commit1
sha2 commit2
`),
},
{
testName: "show local branch head, except the current branch, main branches, or merged branches",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2"},
{Name: "commit3", Sha: "sha3"},
{Name: "commit4", Sha: "sha4", Status: models.StatusMerged},
},
branches: []*models.Branch{
{Name: "current-branch", CommitHash: "sha1", Head: true},
{Name: "other-branch", CommitHash: "sha2", Head: false},
{Name: "master", CommitHash: "sha3", Head: false},
{Name: "old-branch", CommitHash: "sha4", Head: false},
},
currentBranchName: "current-branch",
startIdx: 0,
length: 4,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 * commit2
sha3 commit3
sha4 commit4
`),
},
{
testName: "show local branch head and tag if both exist",
commits: []*models.Commit{
{Name: "commit1", Sha: "sha1"},
{Name: "commit2", Sha: "sha2", Tags: []string{"some-tag"}},
{Name: "commit3", Sha: "sha3"},
},
branches: []*models.Branch{
{Name: "some-branch", CommitHash: "sha2"},
},
startIdx: 0,
length: 3,
showGraph: false,
bisectInfo: git_commands.NewNullBisectInfo(),
cherryPickedCommitShaSet: set.New[string](),
now: time.Date(2020, 1, 1, 0, 0, 0, 0, time.UTC),
expected: formatExpected(`
sha1 commit1
sha2 * some-tag commit2
sha3 commit3
`),
},
{
testName: "showing graph",
commits: []*models.Commit{
@ -285,6 +354,8 @@ func TestGetCommitListDisplayStrings(t *testing.T) {
result := GetCommitListDisplayStrings(
common,
s.commits,
s.branches,
s.currentBranchName,
s.fullDescription,
s.cherryPickedCommitShaSet,
s.diffName,