Repository: go
Issue: cmd/go: `go build` fails to read vcs info when .git is owned by a different user
Labels: help wanted,NeedsFix,GoCommand,BadErrorMessage

<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.18.3 linux/amd64
</pre>

### Does this issue reproduce with the latest release?
yes

### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ 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
</pre></details>

### What did you do?

tried to build a program with a git repository in root, program stated:
```bash
$ 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
```bash
$ 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
"](https://user-images.githubusercontent.com/22552258/175511454-8b71583f-c30f-4546-a667-6925f9b19fea.png)

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->



### 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.