fix(git): set .Ref correctly on detached HEAD

resolves #5035
This commit is contained in:
Jan De Dobbeleer 2024-06-10 16:19:49 +02:00 committed by Jan De Dobbeleer
parent ddd120178d
commit fbc21b8c97

View file

@ -750,6 +750,7 @@ func (g *Git) setPrettyHEADName() {
g.Detached = !strings.HasPrefix(HEADRef, "ref:")
if strings.HasPrefix(HEADRef, BRANCHPREFIX) {
branchName := strings.TrimPrefix(HEADRef, BRANCHPREFIX)
g.Ref = branchName
g.HEAD = fmt.Sprintf("%s%s", g.props.GetString(BranchIcon, "\uE0A0"), g.formatHEAD(branchName))
return
}
@ -757,12 +758,14 @@ func (g *Git) setPrettyHEADName() {
if len(HEADRef) >= 7 {
g.ShortHash = HEADRef[0:7]
g.Hash = HEADRef[0:]
g.Ref = g.ShortHash
}
}
// check for tag
tagName := g.getGitCommandOutput("describe", "--tags", "--exact-match")
if len(tagName) > 0 {
g.Ref = tagName
g.HEAD = fmt.Sprintf("%s%s", g.props.GetString(TagIcon, "\uF412"), tagName)
return
}