Skip to content

Commit

Permalink
fix(git): resolve bare repo pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Jul 26, 2024
1 parent 3fddcac commit 1c908a8
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/segments/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,20 +280,18 @@ func (g *Git) shouldDisplay() bool {
return false
}

gitdir, err := g.env.HasParentFilePath(".git", true)
if err != nil {
if !g.props.GetBool(FetchBareInfo, false) {
return false
}

if g.props.GetBool(FetchBareInfo, false) {
g.realDir = g.env.Pwd()
bare := g.getGitCommandOutput("rev-parse", "--is-bare-repository")
if bare == trueStr {
g.IsBare = true
g.workingDir = g.realDir
return true
}
}

gitdir, err := g.env.HasParentFilePath(".git", true)
if err != nil {
return false
}

Expand Down Expand Up @@ -325,6 +323,13 @@ func (g *Git) setUser() {
}

func (g *Git) getBareRepoInfo() {
// we can still have a pointer to a bare repo
if file, err := g.env.HasParentFilePath(".git", true); err == nil && !file.IsDir {
content := g.FileContents(file.ParentFolder, ".git")
path := strings.TrimPrefix(content, "gitdir: ")
g.workingDir = filepath.Join(file.ParentFolder, path)
}

head := g.FileContents(g.workingDir, "HEAD")
branchIcon := g.props.GetString(BranchIcon, "\uE0A0")
g.Ref = strings.Replace(head, "ref: refs/heads/", "", 1)
Expand All @@ -345,6 +350,7 @@ func (g *Git) setDir(dir string) {
g.Dir = strings.TrimSuffix(dir, `\.git`)
return
}

g.Dir = strings.TrimSuffix(dir, "/.git")
}

Expand Down

0 comments on commit 1c908a8

Please sign in to comment.