Skip to content

Commit

Permalink
fix(git): set .Ref correctly on detached HEAD
Browse files Browse the repository at this point in the history
resolves #5035
  • Loading branch information
JanDeDobbeleer committed Jun 10, 2024
1 parent ddd1201 commit fbc21b8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/segments/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,19 +750,22 @@ 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
}
// no branch, points to commit
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
}
Expand Down

0 comments on commit fbc21b8

Please sign in to comment.