fix(git): set Detached on when fetch_status is false

This commit is contained in:
Jan De Dobbeleer 2024-01-13 20:10:49 +01:00 committed by Jan De Dobbeleer
parent f24ddbdfca
commit 4cf65fddfb

View file

@ -735,6 +735,7 @@ func (g *Git) setPrettyHEADName() {
// we didn't fetch status, fallback to parsing the HEAD file
if len(g.ShortHash) == 0 {
HEADRef := g.FileContents(g.workingDir, "HEAD")
g.Detached = !strings.HasPrefix(HEADRef, "ref:")
if strings.HasPrefix(HEADRef, BRANCHPREFIX) {
branchName := strings.TrimPrefix(HEADRef, BRANCHPREFIX)
g.HEAD = fmt.Sprintf("%s%s", g.props.GetString(BranchIcon, "\uE0A0"), g.formatHEAD(branchName))
@ -746,17 +747,20 @@ func (g *Git) setPrettyHEADName() {
g.Hash = HEADRef[0:]
}
}
// check for tag
tagName := g.getGitCommandOutput("describe", "--tags", "--exact-match")
if len(tagName) > 0 {
g.HEAD = fmt.Sprintf("%s%s", g.props.GetString(TagIcon, "\uF412"), tagName)
return
}
// fallback to commit
if len(g.ShortHash) == 0 {
g.HEAD = g.props.GetString(NoCommitsIcon, "\uF594 ")
return
}
g.HEAD = fmt.Sprintf("%s%s", g.props.GetString(CommitIcon, "\uF417"), g.ShortHash)
}