fix(git): initialize status correctly

This commit is contained in:
Jan De Dobbeleer 2021-12-08 13:02:06 +01:00 committed by Jan De Dobbeleer
parent 4294351e6f
commit 04f841d1b3
4 changed files with 9 additions and 2 deletions

View file

@ -87,6 +87,8 @@ func (g *git) deprecatedString(statusColorsEnabled bool) string {
if len(g.BranchStatus) > 0 {
buffer.WriteString(g.BranchStatus)
}
// status
if g.Staging.Changed() {
fmt.Fprint(buffer, g.getStatusDetailString(g.Staging, StagingColor, LocalStagingIcon, " \uF046"))
}

View file

@ -242,6 +242,8 @@ func TestStatusColorsWithoutDisplayStatus(t *testing.T) {
LocalChangesColor: expected,
},
}
g.Working = &GitStatus{}
g.Staging = &GitStatus{}
g.string()
assert.Equal(t, expected, g.props[BackgroundOverride])
}

View file

@ -183,6 +183,9 @@ func (g *git) string() string {
g.setGitStatus()
g.setGitHEADContext()
g.BranchStatus = g.getBranchStatus()
} else {
g.Working = &GitStatus{}
g.Staging = &GitStatus{}
}
if g.Upstream != "" && g.props.getOneOfBool(FetchUpstreamIcon, DisplayUpstreamIcon, false) {
g.UpstreamIcon = g.getUpstreamIcon()
@ -274,8 +277,6 @@ func (g *git) setGitStatus() {
UPSTREAM = "# branch.upstream "
BRANCHSTATUS = "# branch.ab "
)
g.Staging = &GitStatus{}
g.Working = &GitStatus{}
output := g.getGitCommandOutput("status", "-unormal", "--branch", "--porcelain=2")
for _, line := range strings.Split(output, "\n") {
if strings.HasPrefix(line, HASH) {

View file

@ -364,6 +364,8 @@ 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)