Skip to content

cmd/go: build fails when using GIT_DIR environment variable #56862

@horacimacias

Description

@horacimacias

What version of Go are you using (go version)?

$ go version
go version go1.19.1 darwin/arm64

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="arm64"
GOBIN=""
GOCACHE="/Users/...../Library/Caches/go-build"
GOENV="/Users/...../Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/...../go/pkg/mod"
GOOS="darwin"
GOPATH="/Users/..../go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.19.1/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.1/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.1"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="..../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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/0y/6l073n8s6gj4gzqccdtb009h3rtc0w/T/go-build757008333=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Create a project with the .git folder being renamed as testgit instead of the default .git.
All git operations function normally as long as GIT_DIR=testgit is passed through the environment.
Try to build the project using

env GIT_DIR=testgit go build ./...

What did you expect to see?

Success building project

What did you see instead?

error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping.

Looks like go build is not considering that the git directory may have been overriden using GIT_DIR.
If I rename my testgit folder to the default .git and do not use GIT_DIR environment variable, go build ./... succeeds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions