From 46761ad2e540bd8a331d00bc413e4474b850b5f3 Mon Sep 17 00:00:00 2001 From: Stefan Haller Date: Fri, 25 Sep 2026 13:30:01 +0200 Subject: [PATCH] Demonstrate that author colors don't follow a change of gui.authorColors If gui.authorColors changes while lazygit is running, the authors that are already on screen keep their old colors, both in the author column and in the commit graph. Co-Authored-By: Claude Opus 5.5 (1M context) --- pkg/gui/presentation/authors/authors_test.go | 23 +++++++++++++++++ pkg/gui/presentation/commits_test.go | 27 ++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/pkg/gui/presentation/authors/authors_test.go b/pkg/gui/presentation/authors/authors_test.go index d7c651031..d01fddbf4 100644 --- a/pkg/gui/presentation/authors/authors_test.go +++ b/pkg/gui/presentation/authors/authors_test.go @@ -3,8 +3,11 @@ package authors import ( "testing" + "github.com/gookit/color" + "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/stretchr/testify/assert" + "github.com/xo/terminfo" ) func TestGetInitials(t *testing.T) { @@ -41,3 +44,23 @@ func TestAuthorWithLength(t *testing.T) { assert.Equal(t, s.expectedOutput, utils.Decolorise(AuthorWithLength(s.authorName, s.length))) } } + +func TestAuthorColorsFollowTheConfig(t *testing.T) { + oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions) + defer color.ForceSetColorLevel(oldColorLevel) + t.Cleanup(func() { SetCustomAuthors(nil) }) + + SetCustomAuthors(map[string]string{"Jane Doe": "red"}) + assert.Equal(t, style.FgRed.Sprint("JD"), ShortAuthor("Jane Doe")) + assert.Equal(t, style.FgRed.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8)) + + SetCustomAuthors(map[string]string{"Jane Doe": "blue"}) + /* EXPECTED: + assert.Equal(t, style.FgBlue.Sprint("JD"), ShortAuthor("Jane Doe")) + ACTUAL: */ + assert.Equal(t, style.FgRed.Sprint("JD"), ShortAuthor("Jane Doe")) + /* EXPECTED: + assert.Equal(t, style.FgBlue.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8)) + ACTUAL: */ + assert.Equal(t, style.FgRed.Sprint("Jane Doe"), LongAuthor("Jane Doe", 8)) +} diff --git a/pkg/gui/presentation/commits_test.go b/pkg/gui/presentation/commits_test.go index 3c3ce0044..8a93faf1a 100644 --- a/pkg/gui/presentation/commits_test.go +++ b/pkg/gui/presentation/commits_test.go @@ -10,6 +10,9 @@ 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/presentation/authors" + "github.com/jesseduffield/lazygit/pkg/gui/presentation/graph" + "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" "github.com/stefanhaller/git-todo-parser/todo" @@ -620,3 +623,27 @@ func TestGetCommitListDisplayStrings(t *testing.T) { } } } + +func TestGraphColorsFollowTheAuthorColors(t *testing.T) { + oldColorLevel := color.ForceSetColorLevel(terminfo.ColorLevelMillions) + defer color.ForceSetColorLevel(oldColorLevel) + t.Cleanup(func() { authors.SetCustomAuthors(nil) }) + + hashPool := &utils.StringPool{} + commits := []*models.Commit{ + models.NewCommit(hashPool, models.NewCommitOpts{Hash: "authorcolors1", AuthorName: "Jane Doe", Parents: []string{"authorcolors2"}}), + models.NewCommit(hashPool, models.NewCommitOpts{Hash: "authorcolors2", AuthorName: "Jane Doe"}), + } + renderGraph := func() string { + return strings.Join(graph.RenderAux(loadPipesets(commits), commits, nil), "\n") + } + + authors.SetCustomAuthors(map[string]string{"Jane Doe": "red"}) + assert.Contains(t, renderGraph(), style.FgRed.Sprint("○")) + + authors.SetCustomAuthors(map[string]string{"Jane Doe": "blue"}) + /* EXPECTED: + assert.Contains(t, renderGraph(), style.FgBlue.Sprint("○")) + ACTUAL: */ + assert.Contains(t, renderGraph(), style.FgRed.Sprint("○")) +}