Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: misleading fatal: log message when working in a git repo with no commits #52263

Open
mdevan opened this issue Apr 10, 2022 · 3 comments
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mdevan
Copy link

mdevan commented Apr 10, 2022

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.

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Apr 10, 2022
@seankhliao
Copy link
Member

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

@bcmills bcmills changed the title cmd/go: build does not work on a fresh git repo without commits cmd/go: misleading fatal: log message when working in a git repo with no commits Apr 12, 2022
@bcmills bcmills added this to the Go1.19 milestone Apr 12, 2022
@notfilippo
Copy link

notfilippo commented Apr 13, 2022

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.

notfilippo added a commit to notfilippo/go that referenced this issue Apr 13, 2022
Use git rev-list instead of git show to prevent misleading error
in the user's console when working with an empty repository with
no commits.

Fixes golang#52263
@gopherbot
Copy link

Change https://go.dev/cl/399828 mentions this issue: cmd/go: prevent fatal when working in a git repo with no commit

@gopherbot gopherbot modified the milestones: Go1.19, Go1.20 Aug 2, 2022
@gopherbot gopherbot modified the milestones: Go1.20, Go1.21 Feb 1, 2023
@gopherbot gopherbot modified the milestones: Go1.21, Go1.22 Aug 8, 2023
@gopherbot gopherbot modified the milestones: Go1.22, Go1.23 Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: No status
Development

Successfully merging a pull request may close this issue.

5 participants