From eb682d2a0b65270e3c9d2966cd3b66d0e96651b7 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 24 Dec 2022 12:42:53 -0800 Subject: [PATCH] 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 --- version/version.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/version/version.go b/version/version.go index 5def6e5bb..82f694cf6 100644 --- a/version/version.go +++ b/version/version.go @@ -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