diff options
author | Aleksey @soar Smyrnov <i@soar.name> | 2019-08-08 17:05:35 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-08-08 17:05:35 +0800 |
commit | f3478f2899e80d59d15956ae408fab93cf26254d (patch) | |
tree | 7a128598f29551ea82fa25e1bb41eb4394fcce33 /internal/build | |
parent | f891fd98754b49b351e3a289578bf3072c3e8c8a (diff) | |
download | go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.tar go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.tar.gz go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.tar.bz2 go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.tar.lz go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.tar.xz go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.tar.zst go-tangerine-f3478f2899e80d59d15956ae408fab93cf26254d.zip |
internal/build: fix commit extraction for detached head repo (#18315)
* Fix commit extraction
* Comments for commit extraction
Requested in https://github.com/ethereum/go-ethereum/pull/18315
Diffstat (limited to 'internal/build')
-rw-r--r-- | internal/build/env.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/internal/build/env.go b/internal/build/env.go index 95f00035d..a3017182e 100644 --- a/internal/build/env.go +++ b/internal/build/env.go @@ -20,6 +20,7 @@ import ( "flag" "fmt" "os" + "regexp" "strconv" "strings" "time" @@ -99,6 +100,13 @@ func LocalEnv() Environment { if fields := strings.Fields(head); len(fields) == 2 { head = fields[1] } else { + // In this case we are in "detached head" state + // see: https://git-scm.com/docs/git-checkout#_detached_head + // Additional check required to verify, that file contains commit hash + commitRe, _ := regexp.Compile("^([0-9a-f]{40})$") + if commit := commitRe.FindString(head); commit != "" && env.Commit == "" { + env.Commit = commit + } return env } if env.Commit == "" { |