Repository: gohugoio/hugo (language: go)

Issue:
Vendor-specified build date is ignored even if there is no git info
Since v0.96.0 (with commit 64afb7ca51ef5fd5d4a0afa121183217292daa5e), buildDate is read from debug.BuildInfo which is really awesome!

However, `-ldflags "-X github.com/gohugoio/hugo/common/hugo.buildDate"` is now ignored, thus leading to `BuildDate=unknown` in the version string for Debian (and probably Fedora) package build where .git/ is removed from the source package and thus Git info is unavailable.

### What version of Hugo are you using (`hugo version`)?

<pre>
$ hugo version
hugo v0.101.0+extended linux/amd64 BuildDate=unknown VendorInfo=debian:0.101.0-1
</pre>

### Does this issue reproduce with the latest release?

Yes


Discussion / hints:

Fix patch:
diff --git a/common/hugo/hugo.go b/common/hugo/hugo.go
index d78564a67db..54fbd65a365 100644
--- a/common/hugo/hugo.go
+++ b/common/hugo/hugo.go
@@ -38,6 +38,8 @@ const (
 )
 
 var (
+	// buildDate allows vendor-specified build date when .git/ is unavailable.
+	buildDate string
 	// vendorInfo contains vendor notes about the current build.
 	vendorInfo string
 )
diff --git a/common/hugo/version.go b/common/hugo/version.go
index edcb983d730..3bb6472e2fa 100644
--- a/common/hugo/version.go
+++ b/common/hugo/version.go
@@ -153,6 +153,10 @@ func BuildVersionString() string {
 	osArch := bi.GoOS + "/" + bi.GoArch
 
 	date := bi.RevisionTime
+	if date == "" {
+		// Accept vendor-specified build date if .git/ is unavailable.
+		date = buildDate
+	}
 	if date == "" {
 		date = "unknown"
 	}


Test patch: