fix(git): move untracked to added

resolves #628
This commit is contained in:
Jan De Dobbeleer 2021-04-12 19:28:32 +02:00 committed by Jan De Dobbeleer
parent 3f046e31a1
commit 434cd41faf
2 changed files with 8 additions and 12 deletions

View file

@ -19,12 +19,11 @@ type gitRepo struct {
} }
type gitStatus struct { type gitStatus struct {
unmerged int unmerged int
deleted int deleted int
added int added int
modified int modified int
untracked int changed bool
changed bool
} }
func (s *gitStatus) string() string { func (s *gitStatus) string() string {
@ -38,7 +37,6 @@ func (s *gitStatus) string() string {
status += stringIfValue(s.added, "+") status += stringIfValue(s.added, "+")
status += stringIfValue(s.modified, "~") status += stringIfValue(s.modified, "~")
status += stringIfValue(s.deleted, "-") status += stringIfValue(s.deleted, "-")
status += stringIfValue(s.untracked, "?")
status += stringIfValue(s.unmerged, "x") status += stringIfValue(s.unmerged, "x")
return status return status
} }
@ -384,7 +382,7 @@ func (g *git) parseGitStats(output []string, working bool) *gitStatus {
switch code { switch code {
case "?": case "?":
if working { if working {
status.untracked++ status.added++
} }
case "D": case "D":
status.deleted++ status.deleted++
@ -396,7 +394,7 @@ func (g *git) parseGitStats(output []string, working bool) *gitStatus {
status.modified++ status.modified++
} }
} }
status.changed = status.added > 0 || status.deleted > 0 || status.modified > 0 || status.unmerged > 0 || status.untracked > 0 status.changed = status.added > 0 || status.deleted > 0 || status.modified > 0 || status.unmerged > 0
return &status return &status
} }

View file

@ -352,9 +352,8 @@ func TestParseGitStatsWorking(t *testing.T) {
status := g.parseGitStats(output, true) status := g.parseGitStats(output, true)
assert.Equal(t, 3, status.modified) assert.Equal(t, 3, status.modified)
assert.Equal(t, 1, status.unmerged) assert.Equal(t, 1, status.unmerged)
assert.Equal(t, 1, status.added) assert.Equal(t, 3, status.added)
assert.Equal(t, 1, status.deleted) assert.Equal(t, 1, status.deleted)
assert.Equal(t, 2, status.untracked)
assert.True(t, status.changed) assert.True(t, status.changed)
} }
@ -376,7 +375,6 @@ func TestParseGitStatsStaging(t *testing.T) {
assert.Equal(t, 0, status.unmerged) assert.Equal(t, 0, status.unmerged)
assert.Equal(t, 1, status.added) assert.Equal(t, 1, status.added)
assert.Equal(t, 2, status.deleted) assert.Equal(t, 2, status.deleted)
assert.Equal(t, 0, status.untracked)
assert.True(t, status.changed) assert.True(t, status.changed)
} }