fix(version): report correct bera-geth version when building from detached HEAD (#77)

This commit is contained in:
Cal Bera 2025-08-26 11:39:51 -04:00 committed by GitHub
parent cdd8fc239f
commit 118eb75ed3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -156,18 +156,18 @@ func LocalEnv() Environment {
// see: https://git-scm.com/docs/git-checkout#_detached_head
// Additional check required to verify, that file contains commit hash
commitRe, _ := regexp.Compile("^([0-9a-f]{40})$")
if commit := commitRe.FindString(head); commit != "" && env.Commit == "" {
if commit := commitRe.FindString(strings.TrimSpace(head)); commit != "" && env.Commit == "" {
env.Commit = commit
env.Date = getDate(env.Commit)
}
return env
// Do not return early; allow tag discovery even in detached HEAD.
}
if env.Commit == "" {
env.Commit = readGitFile(head)
}
env.Date = getDate(env.Commit)
if env.Branch == "" {
if head != "HEAD" {
if strings.HasPrefix(head, "refs/heads/") {
env.Branch = strings.TrimPrefix(head, "refs/heads/")
}
}