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: get with GIT_CONFIG ignores env variable #42055

Closed
valery-barysok opened this issue Oct 18, 2020 · 10 comments
Closed

cmd/go: get with GIT_CONFIG ignores env variable #42055

valery-barysok opened this issue Oct 18, 2020 · 10 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@valery-barysok
Copy link

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

$ go version go1.15.2 darwin/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="/Users/user/work/sunnycat/bin"
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/user/go/pkg/mod"
GONOPROXY="github.com/user/*"
GONOSUMDB="github.com/user/*"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPRIVATE="github.com/user/*"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k9/h8z58c7n2wxf9gd6rm0m_bd40000gp/T/go-build919199640=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

export GIT_CONFIG=$(pwd)/.gitconfig
#[url "ssh://git@github.com"]
#	insteadOf = https://github.com

$ go get -u github.com/user/module

What did you expect to see?

go get takes into account GIT_CONFIG env variable

What did you see instead?

# cd .; git clone -- https://github.com/user/module /Users/user/go/src/github.com/user/module
Cloning into '/Users/user/go/src/github.com/user/module'...
fatal: could not read Username for 'https://github.com': terminal prompts disabled
package github.com/user/module: exit status 128
@cagedmantis cagedmantis changed the title go get with GIT_CONFIG env variable cmd/go: get with GIT_CONFIG ignores env variable Oct 21, 2020
@cagedmantis cagedmantis added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Oct 26, 2020
@cagedmantis
Copy link
Contributor

Can you run git config --list --show-origin to ensure the configuration settings are as expected?

@valery-barysok
Copy link
Author

valery-barysok commented Oct 27, 2020

@cagedmantis,
I run this command from different places and it works as expected. I see the configuration setting based on GIT_CONFIG value.
So git command works well but go get does not.

@valery-barysok
Copy link
Author

valery-barysok commented Nov 12, 2020

@cagedmantis, Do you need additional info? It will be great feature for ability to work in multiple environments setup when use direnv or similar.

@valery-barysok
Copy link
Author

valery-barysok commented Nov 15, 2020

I use direnv to manage environment variables depends on current directory and I think the issue arises when go changes directory under the hood while executes go get -u operation. And GIT_CONFIG value changes (clears). @cagedmantis , Could you confirm that there is directory changing during go get -u operation for some reason?

@cagedmantis cagedmantis added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. and removed WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Nov 16, 2020
@cagedmantis cagedmantis added this to the Backlog milestone Nov 16, 2020
@cagedmantis
Copy link
Contributor

@valery-barysok Thanks for the additional information. I am not able to reproduce this, even with some direnv experiments. I am going to loop in the maintainers of the go command for good measure.

/cc @bcmills @jayconrod @matloob

@bcmills
Copy link
Contributor

bcmills commented Nov 17, 2020

@valery-barysok, go get does not change its own working directory, but it does invoke git in a different directory (namely, in the Go module cache).

The go command doesn't know anything about direnv or about the GIT_CONFIG environment variable, so if you're going that route it's on you to ensure that your GIT_CONFIG environment variable is set appropriately for commands executed in the module cache (and, for that matter, in temporary directories).

@bcmills bcmills modified the milestones: Backlog, Unplanned Nov 17, 2020
@bcmills
Copy link
Contributor

bcmills commented Nov 17, 2020

@valery-barysok, can you confirm that your GIT_CONFIG setting applies to subdirectories of $(go env GOMODCACHE)?

@bcmills bcmills added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Nov 17, 2020
@valery-barysok
Copy link
Author

valery-barysok commented Nov 21, 2020

@bcmills, I can confirm that direnv also configured for go env GOMODCACHE in the same way as for dir where i execute go get. As expected it does not work but git clone works in both places. As I understand go get executes git clone and it should work as if i do the same by myself. But it looks like no env variables that provide correct setup of git when executes this command.

@valery-barysok
Copy link
Author

valery-barysok commented Nov 21, 2020

@bcmills, I debugged go source code and seems like issue actually happens inside git itself when go executes git ls-remote -q origin while env and git config --list commands before git ls-remote -q origin provide correct values. It is succeed if I put .gitconfig file to user home directory instead of custom place for this operation.

I will continue to investigate.

@valery-barysok
Copy link
Author

valery-barysok commented Nov 21, 2020

I resolved the issue by using XDG_CONFIG_HOME env variable instead of GIT_CONFIG.

So GIT_CONFIG is wrong way to provide custom place for git config file because it works with limited list of commands.
There is side effect when you use XDG_CONFIG_HOME because other applications respect this env variable and read/write their setting from this place.

@golang golang locked and limited conversation to collaborators Nov 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants