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: go build fails to read vcs info when .git is owned by a different user #53532

Open
ultrabear opened this issue Jun 24, 2022 · 4 comments
Labels
GoCommand NeedsFix

Comments

@ultrabear
Copy link

@ultrabear ultrabear commented Jun 24, 2022

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

$ go version
go version go1.18.3 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/ultrabear/.cache/go-build"
GOENV="/home/ultrabear/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ultrabear/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ultrabear/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18.3"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ultrabear/cpgov/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-build2447704394=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.18.3 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.18.3
uname -sr: Linux 5.15.46-1-MANJARO
LSB Version:	n/a
Distributor ID:	ManjaroLinux
Description:	Manjaro Linux
Release:	21.3.0
Codename:	Ruah
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.35.
lldb --version: lldb version 13.0.1
gdb --version: GNU gdb (GDB) 12.1

What did you do?

tried to build a program with a git repository in root, program stated:

$ sudo make
go build -o cpgov
error obtaining VCS status: exit status 128
	Use -buildvcs=false to disable VCS stamping.
make: *** [Makefile:5: cpgov] Error 1

while running without root works

$ make
go build -o cpgov
$ sudo make install
# successfully installs now that compilation is not happening

example not using Makefile as image:
Terminal screen with contents "$ sudo go build -o cpgov; error obtaining VCS status: exit status 128 Use -buildvcs=false to disable VCS stamping. $ go build -o cpgov; $ ls cpgov; cpgov "

What did you expect to see?

The program should not fail to grab vcs info (seemingly) just because it is in root instead of the owning user of the git repository (swapping permissions on .git to 777 did not work, swapping owner of .git to root.root did not work).

What did you see instead?

go build outputted a very unhelpful error message that it failed to obtain VCS information for some reason, and left not enough information to even properly understand the scope of this issue, for that reason I do not fully understand the scope of this issue, or even if it is somehow intended behavior.

@seankhliao
Copy link
Member

@seankhliao seankhliao commented Jun 24, 2022

This is a git issue:

11:28:23 ~/tmp/delve 0:00:00                                                       
master arccy@eevee» sudo /usr/bin/go build ./cmd/dlv
error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.

11:28:44 ~/tmp/delve 0:00:00                                                       
master arccy@eevee» sudo git status
fatal: unsafe repository ('/home/arccy/tmp/delve' is owned by someone else)
To add an exception for this directory, call:

        git config --global --add safe.directory /home/arccy/tmp/delve

@seankhliao
Copy link
Member

@seankhliao seankhliao commented Jun 24, 2022

on the safe.directory setting, git says:

This config setting is only respected when specified in a system or global config, not when it is specified in a repository config or via the command line option -c safe.directory=.

@ultrabear
Copy link
Author

@ultrabear ultrabear commented Jun 24, 2022

If this was a git issue, could go build be patched to forward git error messages to the end user instead of hiding them?

@dmitshur dmitshur changed the title go build Fails to Read VCS Info When in Root User cmd/go go build Fails to Read VCS Info When in Root User Jun 27, 2022
@dmitshur dmitshur changed the title cmd/go go build Fails to Read VCS Info When in Root User cmd/go: go build Fails to Read VCS Info When in Root User Jun 27, 2022
@bcmills
Copy link
Member

@bcmills bcmills commented Jun 29, 2022

If this was a git issue, could go build be patched to forward git error messages to the end user instead of hiding them?

That sounds appropriate. It looks like the error probably comes from here:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/vcs/vcs.go;l=657-663;drc=160414ca6a30a210b82fb09abbd3541802a51017

Perhaps we should move ee.Stderr explicitly into the error text — the exec.ExitError.Error method omits it, but it seems to me that it is essentially always relevant for VCS commands executed by go.

@seankhliao seankhliao changed the title cmd/go: go build Fails to Read VCS Info When in Root User cmd/go: go build fails to read vcs info when .git is owned by a different user Jun 29, 2022
@dr2chase dr2chase added the NeedsFix label Jun 30, 2022
@seankhliao seankhliao added the GoCommand label Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand NeedsFix
Projects
None yet
Development

No branches or pull requests

4 participants