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

go get -mod=readonly updates go.mod #31273

Closed
davecheney opened this issue Apr 5, 2019 · 7 comments
Closed

go get -mod=readonly updates go.mod #31273

davecheney opened this issue Apr 5, 2019 · 7 comments

Comments

@davecheney
Copy link
Contributor

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

% go version
go version devel +964fe4b80f Thu Apr 4 00:26:24 2019 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

What did you do?

As part of my make test target I run

go get -mod=readonly honnef.co/go/tools/cmd/staticcheck

What did you expect to see?

go.mod is not modified

What did you see instead?

go.mod is modified.

This is a problem because I do not want to record the version of honnef.co/go/tools/cmd/staticcheck that was used in my go.mod file. I explicitly want to leave this version floating so that i automatically receive updates to that tool. I want to do this because this tool is not part of my project, its part of the tools I use to test my project, when they are updated, I want to receive those updates without go get dirtying go.mod every time I run my make check target

@cuonglm
Copy link
Member

cuonglm commented Apr 5, 2019

it's expected, as go get still be allowed to update go.mod, even with -mod=readonly, from go help modules:

If invoked with -mod=readonly, the go command is disallowed from the implicit
automatic updating of go.mod described above. Instead, it fails when any changes
to go.mod are needed. This setting is most useful to check that go.mod does
not need updates, such as in a continuous integration and testing system.
The "go get" command remains permitted to update go.mod even with -mod=readonly,
and the "go mod" commands do not take the -mod flag (or any other build flags).

@davecheney
Copy link
Contributor Author

@cuonglm thank you for your reply.

  1. go get -mod=readonly does not appear to exit as you described above. The command completes without error.
  2. Please consider my use case

This is a problem because I do not want to record the version of honnef.co/go/tools/cmd/staticcheck that was used in my go.mod file. I explicitly want to leave this version floating so that i automatically receive updates to that tool. I want to do this because this tool is not part of my project, its part of the tools I use to test my project, when they are updated, I want to receive those updates without go get dirtying go.mod every time I run my make check target

Is there a way to achieve this without dirtying my local copy of go.mod ?

@cuonglm
Copy link
Member

cuonglm commented Apr 5, 2019

@davecheney

go get -mod=readonly does not appear to exit as you described above. The command completes without error.

It does if you use go build instead of go get. As the doc said, go command is disallowed, but go get is allowed.

Is there a way to achieve this without dirtying my local copy of go.mod ?

I don't know anyway in current version. Maybe you just run that go get, after doing your check, do:

git checkout go.mod go.sum

@davecheney
Copy link
Contributor Author

Thank you for your reply

Doing a checkout of go.mod as part of my development workflow will make it impossible to run make check when I have updated other dependant modules. Is there a way to say "don't update go.mod"? Can I change permissions on the file? Will that work?

@cuonglm
Copy link
Member

cuonglm commented Apr 5, 2019

@davecheney how about disable go modules for that check only:

GO111MODULE=off go get honnef.co/go/tools/cmd/staticcheck

@davecheney
Copy link
Contributor Author

davecheney commented Apr 5, 2019 via email

@bcmills
Copy link
Contributor

bcmills commented Apr 8, 2019

The behavior of go get is intentional (see @rsc's comment in #26850 (comment)).

An option specifically for installing tools without affecting go.mod is discussed in #30515. If I understand correctly, that is exactly the use-case you describe here, so I'm closing this as a duplicate of #30515, but please do let me know if I've missed something.

@bcmills bcmills closed this as completed Apr 8, 2019
@golang golang locked and limited conversation to collaborators Apr 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants