From 1c908a8ce6b24e20b4a3bf821426afb7b0806f9a Mon Sep 17 00:00:00 2001 From: Jan De Dobbeleer Date: Fri, 26 Jul 2024 14:00:38 +0200 Subject: [PATCH] fix(git): resolve bare repo pointer --- src/segments/git.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/segments/git.go b/src/segments/git.go index 6390c128..bb272ca6 100644 --- a/src/segments/git.go +++ b/src/segments/git.go @@ -280,12 +280,7 @@ 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 { @@ -293,7 +288,10 @@ func (g *Git) shouldDisplay() bool { g.workingDir = g.realDir return true } + } + gitdir, err := g.env.HasParentFilePath(".git", true) + if err != nil { return false } @@ -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) @@ -345,6 +350,7 @@ func (g *Git) setDir(dir string) { g.Dir = strings.TrimSuffix(dir, `\.git`) return } + g.Dir = strings.TrimSuffix(dir, "/.git") }