What version of Go are you using (go version
)?
$ go version go version go1.18 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="" GOCACHE="/home/mdevan/.cache/go-build" GOENV="/home/mdevan/.config/go/env" GOEXE="" GOEXPERIMENT="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOINSECURE="" GOMODCACHE="/home/mdevan/go/pkg/mod" GONOPROXY="" GONOSUMDB="" GOOS="linux" GOPATH="/home/mdevan/go" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/go" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GOVCS="" GOVERSION="go1.18" GCCGO="gccgo" GOAMD64="v1" AR="ar" CC="gcc" CXX="g++" CGO_ENABLED="1" GOMOD="/tmp/x/go.mod" GOWORK="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build1281482272=/tmp/go-build -gno-record-gcc-switches"
What did you do?
$ cd /tmp [19/19]
$ git init x
Initialized empty Git repository in /tmp/x/.git/
$ cd x
$ go mod init x
go: creating new go.mod: module x
$ cat > main.go
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
$ go build -v
# cd /tmp/x; git -c log.showsignature=false show -s --format=%H:%ct
fatal: your current branch 'master' does not have any commits yet
$
What did you expect to see?
A successful build.
What did you see instead?
~~Build itself failed.~~
Edit: The build does succeed even though the "fatal" message is printed.
Comment From: seankhliao
you can't do much with an empty git repo, though I've never noticed as I always have git commit --allow-empty -m "root-commit"
set as the first commit (so you can push the empty repo upstream).
cc @bcmills @matloob
Comment From: notfilippo
The fatal
log message is printed by the git CLI when executing git -c log.showsignature=false show -s --format=%H:%ct
on an empty repository. The command can be replaced with git rev-list -n 1 --all --format=%H:%ct
, tweaking a bit the parsing to account for the extra header that is printed.
Will open a changelist soon.
Comment From: gopherbot
Change https://go.dev/cl/399828 mentions this issue: cmd/go: prevent fatal when working in a git repo with no commit
Comment From: kevinburkesegment
I just ran into this... can we try again to merge it?