Skip to content

Commit

Permalink
fix: check isInGitDir instead of stderr msg
Browse files Browse the repository at this point in the history
stderr is not reliable due to other LOCALEs

closes #62
  • Loading branch information
mikesmithgh committed Apr 22, 2024
1 parent 8e206ec commit 93a9ab6
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,12 @@ func main() {
util.ErrMsg("color reset", err)
}

gitRepo, stderr, err := git.RevParse()
gitRepo, _, err := git.RevParse()
if err != nil {
switch {
case strings.Contains(err.Error(), exec.ErrNotFound.Error()):
util.ErrMsg("rev parse", err)
case strings.Contains(string(stderr), "not a git repository"):
case gitRepo.IsInGitDir == nil:
os.Exit(0)
default:
// allow other errors to pass through, the git repo may not have upstream
Expand Down
3 changes: 2 additions & 1 deletion pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ func RevParse() (*GitRepo, []byte, error) {
resultLen := len(result)
if resultLen == 5 || resultLen == 6 {
g.GitDir = result[0]
g.IsInGitDir, _ = strconv.ParseBool(result[1])
isInGitDir, _ := strconv.ParseBool(result[1])
g.IsInGitDir = &isInGitDir
g.IsInWorkTree, _ = strconv.ParseBool(result[2])
g.IsInBareRepo, _ = strconv.ParseBool(result[3])
g.IsInShallowRepo, _ = strconv.ParseBool(result[4])
Expand Down
6 changes: 3 additions & 3 deletions pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

type GitRepo struct {
GitDir string
IsInGitDir bool
IsInGitDir *bool // pointer is used during checks if in a git repo
IsInWorkTree bool
IsInBareRepo bool
IsInShallowRepo bool
Expand Down Expand Up @@ -155,7 +155,7 @@ func (g *GitRepo) BranchInfo(cfg config.GitPromptStringConfig) (string, error) {
}
}

if g.IsInGitDir {
if *g.IsInGitDir {
if g.IsInBareRepo {
g.PromptBareRepoStatus = "BARE:"
} else {
Expand Down Expand Up @@ -201,7 +201,7 @@ func (g *GitRepo) BranchStatus(cfg config.GitPromptStringConfig) (string, string
status := ""
statusColor := ""

if g.IsInBareRepo || g.IsInGitDir {
if g.IsInBareRepo || *g.IsInGitDir {
return status, cfg.ColorNoUpstream, nil
}

Expand Down

0 comments on commit 93a9ab6

Please sign in to comment.