From 68dcbab83391336ca129d382b7ab75ef9eadf591 Mon Sep 17 00:00:00 2001 From: vasser Date: Wed, 18 Jan 2023 22:33:45 +0200 Subject: address PR review --- Makefile | 2 +- commands/root.go | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index b5aca82a..ea30e193 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ all: build -GIT_COMMIT:=$(shell git rev-parse --short HEAD) +GIT_COMMIT:=$(shell git rev-list -1 HEAD) GIT_LAST_TAG:=$(shell git describe --dirty --tags) GIT_EXACT_TAG:=$(shell git name-rev --name-only --tags HEAD) UNAME_S := $(shell uname -s) diff --git a/commands/root.go b/commands/root.go index 0767c701..f8eda136 100644 --- a/commands/root.go +++ b/commands/root.go @@ -2,6 +2,7 @@ package commands import ( + "errors" "fmt" "os" "runtime/debug" @@ -49,11 +50,14 @@ the same git remote you are already using to collaborate with other people. } else { // if we don't have a tag, try to read // commit and dirty state from the build info - commit, dirty := getCommitAndDirty() - root.Version = fmt.Sprintf("dev-%.10s", commit) - - if dirty != "" { - root.Version = fmt.Sprintf("%s-dirty", root.Version) + if commit, dirty, err := getCommitAndDirty(); err == nil { + root.Version = fmt.Sprintf("dev-%.10s", commit) + + if dirty != "" { + root.Version = fmt.Sprintf("%s-dirty", root.Version) + } + } else { + root.Version = "dev-unknown" } } } @@ -108,17 +112,17 @@ func Execute() { } } -func getCommitAndDirty() (commit, dirty string) { +func getCommitAndDirty() (commit, dirty string, err error) { var d, c string info, ok := debug.ReadBuildInfo() if !ok { - fmt.Println("could not get commit") + return d, c, errors.New("unable to read build info") } - // get the commit and - // modified status (that is the flag for repository dirty or not) + // get the commit and modified status + // (that is the flag for repository dirty or not) for _, kv := range info.Settings { switch kv.Key { case "vcs.revision": @@ -130,5 +134,5 @@ func getCommitAndDirty() (commit, dirty string) { } } - return c, d + return c, d, nil } -- cgit