version: construct short hash in dev mode if GitCommit is given.

Allows a dev built to provide GitCommit and have the short hash
computed correctly, even if the Go embedded build info lacks a
git commit.

Signed-off-by: David Anderson <dave@natulte.net>
This commit is contained in:
David Anderson 2022-12-24 12:42:53 -08:00 committed by Dave Anderson
parent 2a1f1c79ca
commit eb682d2a0b
1 changed files with 5 additions and 4 deletions

View File

@ -41,14 +41,11 @@ func init() {
return
}
var dirty string // "-dirty" suffix if dirty
var commitHashAbbrev, commitDate string
var commitDate string
for _, s := range bi.Settings {
switch s.Key {
case "vcs.revision":
GitCommit = s.Value
if len(s.Value) >= 9 {
commitHashAbbrev = s.Value[:9]
}
case "vcs.time":
if len(s.Value) >= len("yyyy-mm-dd") {
commitDate = s.Value[:len("yyyy-mm-dd")]
@ -61,6 +58,10 @@ func init() {
}
}
}
commitHashAbbrev := GitCommit
if len(commitHashAbbrev) >= 9 {
commitHashAbbrev = commitHashAbbrev[:9]
}
// Backup path, using Go 1.18's built-in git stamping.
Short = strings.TrimSpace(tailscaleroot.Version) + "-dev" + commitDate