Skip to content

go build uses wrong VCS information when running in a git worktree #64772

@HeikoSchlittermann

Description

@HeikoSchlittermann

Go version

go version 1.21.5 linux/amd65

What operating system and processor architecture are you using (go env)?

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/heiko/.cache/go-build'
GOENV='/home/heiko/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/heiko/go/pkg/mod'
GONOPROXY='*.wdf.sap.corp'
GONOSUMDB='*.wdf.sap.corp'
GOOS='linux'
GOPATH='/home/heiko/go'
GOPRIVATE='*.wdf.sap.corp'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/heiko/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/heiko/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.21.5.linux-amd64/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/heiko/d/go/dmarc/go.mod'
GOWORK='/home/heiko/d/go/go.work'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3144831628=/tmp/go-build -gno-record-gcc-switches'

What did you do?

  • git clone ...
  • local modifications
  • git worktree add xxx @~ # use the previous commit
  • cd xxx
  • git status # which tells me, that the worktree is clean
  • go build -o out ./...
  • go version -m out/<built-binary>

What did you expect to see?

I expected to see vcs.modified=false and more importantly, I expected to see the commit ID I'm using in the worktree, the one I can see there using git show -s --format=%h.

What did you see instead?

I got vcs.modified=true and the vcs.revision mentions the commit ID of the "parent" folder, which is clearly does not match the output of git describe ... --dirty.

Unfortunately I wasn't able to find the piece of code, which sets the flag, yet.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions