aboutsummaryrefslogtreecommitdiffstats
path: root/commands
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 /commands
parent83ffed8c3e33d487571106ce29c0d2ce7a1ea0ed (diff)
downloadgit-bug-68dcbab83391336ca129d382b7ab75ef9eadf591.tar.gz
address PR review
Diffstat (limited to 'commands')
-rw-r--r--commands/root.go24
1 files changed, 14 insertions, 10 deletions
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
}