diff --git a/src/segment_git.go b/src/segment_git.go index f3c0dff6..b73978be 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -224,14 +224,14 @@ func (g *git) getUpstreamIcon() string { func (g *git) setGitStatus() { addToStatus := func(status string) { - if len(status) <= 4 { - return - } const UNTRACKED = "?" if strings.HasPrefix(status, UNTRACKED) { g.Working.add(UNTRACKED) return } + if len(status) <= 4 { + return + } workingCode := status[3:4] stagingCode := status[2:3] g.Working.add(workingCode) diff --git a/src/segment_git_test.go b/src/segment_git_test.go index 842a281e..ee813a68 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -361,6 +361,22 @@ func TestSetGitStatus(t *testing.T) { ExpectedAhead: 2, ExpectedBehind: 1, }, + { + Case: "untracked files", + Output: ` + # branch.oid 1234567891011121314 + # branch.head main + # branch.upstream origin/main + # branch.ab +0 -0 + ? q + ? qq + ? qqq + `, + ExpectedUpstream: "origin/main", + ExpectedHash: "1234567", + ExpectedRef: "main", + ExpectedWorking: &GitStatus{ScmStatus: ScmStatus{Added: 3}}, + }, } for _, tc := range cases { env := new(MockedEnvironment)