From d9e642a1320d859f549c32f6c76fa80a0ef6f7a3 Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Wed, 8 Dec 2021 14:53:41 +0100 Subject: [PATCH] fix(git): initialize status correctly --- src/segment_git.go | 2 ++ src/segment_git_test.go | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/segment_git.go b/src/segment_git.go index e02fe8a9..88c00186 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -280,6 +280,8 @@ func (g *git) setGitStatus() { UPSTREAM = "# branch.upstream " BRANCHSTATUS = "# branch.ab " ) + g.Working = &GitStatus{} + g.Staging = &GitStatus{} output := g.getGitCommandOutput("status", "-unormal", "--branch", "--porcelain=2") for _, line := range strings.Split(output, "\n") { if strings.HasPrefix(line, HASH) { diff --git a/src/segment_git_test.go b/src/segment_git_test.go index feebbe1c..501a3cd4 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -364,8 +364,6 @@ func TestSetGitStatus(t *testing.T) { if tc.ExpectedStaging == nil { tc.ExpectedStaging = &GitStatus{} } - g.Working = &GitStatus{} - g.Staging = &GitStatus{} g.setGitStatus() assert.Equal(t, tc.ExpectedStaging, g.Staging, tc.Case) assert.Equal(t, tc.ExpectedWorking, g.Working, tc.Case)