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: fail if the user tries to modify the GOMOD environment variable #51217

Open
mvdan opened this issue Feb 15, 2022 · 5 comments · May be fixed by #51954
Open

cmd/go: fail if the user tries to modify the GOMOD environment variable #51217

mvdan opened this issue Feb 15, 2022 · 5 comments · May be fixed by #51954
Labels
GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mvdan
Copy link
Member

mvdan commented Feb 15, 2022

See #51171 (comment). The user likely wants to either use -modfile, or cd into the right directory to enter or leave a module. Right now, a command like GOMOD=foo.mod go list will happily ignore GOMOD=foo.mod.

cc @bcmills @matloob

@bcmills bcmills added GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done. labels Feb 15, 2022
@bcmills bcmills added this to the Backlog milestone Feb 15, 2022
@mvdan
Copy link
Member Author

mvdan commented Feb 23, 2022

Open question; if one does the equivalent of source <(go env) to import all of go env into the current shell environment (aka go env >env.txt && source env.txt), one can end up with the equivalent of GOMOD=${PWD}/go.mod. So perhaps we shouldn't fail if GOMOD is set but the path is precisely the same as the go.mod file we are meant to be using.

In other words: to ensure we don't error out when we don't really have to, we could only error if GOMOD is set to a path that means the user is trying to change what go.mod file we're meant to be using.

@bcmills
Copy link
Contributor

bcmills commented Feb 23, 2022

Perhaps!

I have also argued in the past that we should actually allow the user to actually change the “main module” for a go invocation by setting GOMOD explicitly.
(That would be a bit, but not entirely, redundant with the -C flag proposed in #50332.)

@mvdan
Copy link
Member Author

mvdan commented Feb 23, 2022

I'd also be fine with that :)

@bstncartwright
Copy link

Is this available to be worked on? I'd love to pick this up as a new contributor. 😃

bstncartwright added a commit to bstncartwright/go that referenced this issue Mar 25, 2022
GOMOD was previously silently ignored. now fails if the user tries to modify
the GOMOD environment variable and it is not the same as the module file
that would be used.

Fixes golang#51217
@gopherbot
Copy link

Change https://go.dev/cl/395915 mentions this issue: cmd/go: fail if the user tries to modify the GOMOD environment variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants