Skip to content

Commit 93a9ab6

Browse files
committed
fix: check isInGitDir instead of stderr msg
stderr is not reliable due to other LOCALEs closes #62
1 parent 8e206ec commit 93a9ab6

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ func main() {
175175
util.ErrMsg("color reset", err)
176176
}
177177

178-
gitRepo, stderr, err := git.RevParse()
178+
gitRepo, _, err := git.RevParse()
179179
if err != nil {
180180
switch {
181181
case strings.Contains(err.Error(), exec.ErrNotFound.Error()):
182182
util.ErrMsg("rev parse", err)
183-
case strings.Contains(string(stderr), "not a git repository"):
183+
case gitRepo.IsInGitDir == nil:
184184
os.Exit(0)
185185
default:
186186
// allow other errors to pass through, the git repo may not have upstream

pkg/git/git.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ func RevParse() (*GitRepo, []byte, error) {
191191
resultLen := len(result)
192192
if resultLen == 5 || resultLen == 6 {
193193
g.GitDir = result[0]
194-
g.IsInGitDir, _ = strconv.ParseBool(result[1])
194+
isInGitDir, _ := strconv.ParseBool(result[1])
195+
g.IsInGitDir = &isInGitDir
195196
g.IsInWorkTree, _ = strconv.ParseBool(result[2])
196197
g.IsInBareRepo, _ = strconv.ParseBool(result[3])
197198
g.IsInShallowRepo, _ = strconv.ParseBool(result[4])

pkg/git/repo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
type GitRepo struct {
1515
GitDir string
16-
IsInGitDir bool
16+
IsInGitDir *bool // pointer is used during checks if in a git repo
1717
IsInWorkTree bool
1818
IsInBareRepo bool
1919
IsInShallowRepo bool
@@ -155,7 +155,7 @@ func (g *GitRepo) BranchInfo(cfg config.GitPromptStringConfig) (string, error) {
155155
}
156156
}
157157

158-
if g.IsInGitDir {
158+
if *g.IsInGitDir {
159159
if g.IsInBareRepo {
160160
g.PromptBareRepoStatus = "BARE:"
161161
} else {
@@ -201,7 +201,7 @@ func (g *GitRepo) BranchStatus(cfg config.GitPromptStringConfig) (string, string
201201
status := ""
202202
statusColor := ""
203203

204-
if g.IsInBareRepo || g.IsInGitDir {
204+
if g.IsInBareRepo || *g.IsInGitDir {
205205
return status, cfg.ColorNoUpstream, nil
206206
}
207207

0 commit comments

Comments
 (0)