aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvasser <serhiy.vas@gmail.com>2023-01-18 22:33:45 +0200
committervasser <serhiy.vas@gmail.com>2023-01-18 22:33:45 +0200
commit68dcbab83391336ca129d382b7ab75ef9eadf591 (patch)
tree44776fb7feb5e3731984105a1b15816a66fcfcc8
parent83ffed8c3e33d487571106ce29c0d2ce7a1ea0ed (diff)
downloadgit-bug-68dcbab83391336ca129d382b7ab75ef9eadf591.tar.gz
address PR review
-rw-r--r--Makefile2
-rw-r--r--commands/root.go24
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
}