From 301ca0b7aa1f4b9ec04ef765a20daeae6e0de8ef Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Mon, 26 Jun 2023 13:21:50 +0200 Subject: [PATCH] fix(git): initialize status correctly relates to #3992 --- src/segments/git.go | 8 +++----- src/segments/git_test.go | 2 ++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/segments/git.go b/src/segments/git.go index 1ac5de3e..df120ab9 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -146,9 +146,6 @@ func (g *Git) Template() string { } func (g *Git) Enabled() bool { - statusFormats := g.props.GetKeyValueMap(StatusFormats, map[string]string{}) - g.Working = &GitStatus{ScmStatus: ScmStatus{Formats: statusFormats}} - g.Staging = &GitStatus{ScmStatus: ScmStatus{Formats: statusFormats}} g.User = &User{} if !g.shouldDisplay() { @@ -489,8 +486,9 @@ func (g *Git) setGitStatus() { ) // firstly assume that upstream is gone g.UpstreamGone = true - g.Working = &GitStatus{} - g.Staging = &GitStatus{} + statusFormats := g.props.GetKeyValueMap(StatusFormats, map[string]string{}) + g.Working = &GitStatus{ScmStatus: ScmStatus{Formats: statusFormats}} + g.Staging = &GitStatus{ScmStatus: ScmStatus{Formats: statusFormats}} untrackedMode := g.getUntrackedFilesMode() args := []string{"status", untrackedMode, "--branch", "--porcelain=2"} ignoreSubmodulesMode := g.getIgnoreSubmodulesMode() diff --git a/src/segments/git_test.go b/src/segments/git_test.go index 076f6981..8f112bab 100644 --- a/src/segments/git_test.go +++ b/src/segments/git_test.go @@ -554,6 +554,8 @@ func TestSetGitStatus(t *testing.T) { if tc.ExpectedStaging == nil { tc.ExpectedStaging = &GitStatus{} } + tc.ExpectedStaging.Formats = map[string]string{} + tc.ExpectedWorking.Formats = map[string]string{} g.setGitStatus() assert.Equal(t, tc.ExpectedStaging, g.Staging, tc.Case) assert.Equal(t, tc.ExpectedWorking, g.Working, tc.Case)