Skip to content

Commit

Permalink
fix: check isInGitDir instead of stderr msg (#63)
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 authored Apr 22, 2024
1 parent fc8581b commit 568a36c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/test_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ jobs:
run: |
make test
- name: test (different LOCALE)
if: runner.os == 'Linux'
run: |
sudo locale-gen zh_CN.UTF-8
LC_ALL='zh_CN.UTF-8' make test
release:
if: (github.ref == 'refs/heads/main') && (github.repository_owner == 'mikesmithgh')
Expand Down
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 568a36c

Please sign in to comment.