From d4628bd751cda03c0f041b9333151630fcd3ab1b Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 8 Jul 2019 14:36:22 -0600 Subject: [PATCH] fail softly, as documented --- gitver.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gitver.go b/gitver.go index d3cf421..a0641e4 100644 --- a/gitver.go +++ b/gitver.go @@ -6,7 +6,6 @@ import ( "bytes" "fmt" "go/format" - "log" "os" "text/template" "time" @@ -45,8 +44,13 @@ func main() { v, err := gitver.ExecAndParse() if nil != err { - log.Fatalf("Failed to get git version: %s\n", err) - os.Exit(exitCode) + fmt.Fprintf(os.Stderr, "Failed to get git version: %s\n", err) + if exitCode > 0 { + os.Exit(exitCode) + } + v = &gitver.Versions{ + Timestamp: time.Now(), + } } // Create or overwrite the go file from template @@ -89,8 +93,10 @@ var versionTpl = template.Must(template.New("").Parse(`// Code generated by go g package {{ .Package }} func init() { + {{ if .GitRev -}} GitRev = "{{ .GitRev }}" - {{ if .Version -}} + {{ end -}} + {{ if .Version -}} GitVersion = "{{ .Version }}" {{ end -}} GitTimestamp = "{{ .Timestamp }}"