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
This commit is contained in:
parent
f891fd9875
commit
f3478f2899
@ -20,6 +20,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -99,6 +100,13 @@ func LocalEnv() Environment {
|
|||||||
if fields := strings.Fields(head); len(fields) == 2 {
|
if fields := strings.Fields(head); len(fields) == 2 {
|
||||||
head = fields[1]
|
head = fields[1]
|
||||||
} else {
|
} 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
|
return env
|
||||||
}
|
}
|
||||||
if env.Commit == "" {
|
if env.Commit == "" {
|
||||||
|
Loading…
Reference in New Issue
Block a user