fix(git): initialize status correctly

relates to #3992
This commit is contained in:
Jan De Dobbeleer 2023-06-26 13:21:50 +02:00 committed by Jan De Dobbeleer
parent f8ec5ab3ae
commit 301ca0b7aa
2 changed files with 5 additions and 5 deletions

View file

@ -146,9 +146,6 @@ func (g *Git) Template() string {
} }
func (g *Git) Enabled() bool { 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{} g.User = &User{}
if !g.shouldDisplay() { if !g.shouldDisplay() {
@ -489,8 +486,9 @@ func (g *Git) setGitStatus() {
) )
// firstly assume that upstream is gone // firstly assume that upstream is gone
g.UpstreamGone = true g.UpstreamGone = true
g.Working = &GitStatus{} statusFormats := g.props.GetKeyValueMap(StatusFormats, map[string]string{})
g.Staging = &GitStatus{} g.Working = &GitStatus{ScmStatus: ScmStatus{Formats: statusFormats}}
g.Staging = &GitStatus{ScmStatus: ScmStatus{Formats: statusFormats}}
untrackedMode := g.getUntrackedFilesMode() untrackedMode := g.getUntrackedFilesMode()
args := []string{"status", untrackedMode, "--branch", "--porcelain=2"} args := []string{"status", untrackedMode, "--branch", "--porcelain=2"}
ignoreSubmodulesMode := g.getIgnoreSubmodulesMode() ignoreSubmodulesMode := g.getIgnoreSubmodulesMode()

View file

@ -554,6 +554,8 @@ func TestSetGitStatus(t *testing.T) {
if tc.ExpectedStaging == nil { if tc.ExpectedStaging == nil {
tc.ExpectedStaging = &GitStatus{} tc.ExpectedStaging = &GitStatus{}
} }
tc.ExpectedStaging.Formats = map[string]string{}
tc.ExpectedWorking.Formats = map[string]string{}
g.setGitStatus() g.setGitStatus()
assert.Equal(t, tc.ExpectedStaging, g.Staging, tc.Case) assert.Equal(t, tc.ExpectedStaging, g.Staging, tc.Case)
assert.Equal(t, tc.ExpectedWorking, g.Working, tc.Case) assert.Equal(t, tc.ExpectedWorking, g.Working, tc.Case)