-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: most 'go mod' subcommands should not update go.mod, go.sum #45551
Comments
Out of curiosity, would this proposal change the behavior of My main use case for COPY ./go.mod ./go.sum ./
RUN go mod download
COPY ./ ./
RUN go build Such that I can download the dependencies given in In this case, I cannot use |
@zikaeroh I think this proposal would improve things for you, at least a bit. To clarify,
The difference here is that |
Thanks for confirming. I'm alright with even a bad version of |
Change https://golang.org/cl/310073 mentions this issue: |
Change https://golang.org/cl/330913 mentions this issue: |
Change https://golang.org/cl/336151 mentions this issue: |
Change https://golang.org/cl/336152 mentions this issue: |
'go mod graph', 'go mod vendor', 'go mod verify', and 'go mod why' will no longer edit go.mod or go.sum. 'go mod graph', 'go mod verify', and 'go mod why' may still fetch files and look up packages as if they were able to update go.mod. They're useful for debugging and should still work when go.mod is a little broken. This is implemented in modload.setDefaultBuildMod based on command name for now. Super gross. Sorry. This should be fixed with a larger refactoring for #40775. Fixes #45551 Change-Id: If5f225937180d32e9a5dd252c78d988042bbdedf Reviewed-on: https://go-review.googlesource.com/c/go/+/336151 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org>
Change https://golang.org/cl/341933 mentions this issue: |
Change https://golang.org/cl/347150 mentions this issue: |
Change https://go.dev/cl/387920 mentions this issue: |
Fixes #51242 Updates #45551 Change-Id: Iba6e6acd9a94d24e26fcdd125f1022430723ada7 Reviewed-on: https://go-review.googlesource.com/c/go/+/387920 Trust: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org> Trust: Bryan Mills <bcmills@google.com>
As of Go 1.16, all
go mod
subcommands can updatego.mod
andgo.sum
. Some commands are intended to update these files, and that shouldn't change. However, most commands may still perform an automatic update, which may be surprising. Internally,go mod
subcommands run in-mod=mod
mode, even though they don't have a-mod
command line flag.For some commands, updating
go.mod
andgo.sum
is expected:go mod edit
is supposed to editgo.mod
.go mod init
createsgo.mod
and may import information from another dependency management tool.go mod tidy
is supposed to editgo.mod
andgo.sum
.For other commands, updating
go.mod
orgo.sum
may be quite unexpected. The go command should report an error ifgo.mod
orgo.sum
need to be updated.go mod graph
is a query tool. It shouldn't have side effects.go mod vendor
is expected to updatevendor
but notgo.mod
.go mod verify
also shouldn't have side effects.go mod why
, same deal.go mod download
occupies an awkward middle ground. It has always been able to updatego.mod
(probably should not), but it may also add sums of modules in the build list togo.sum
. This is usually unexpected and undesired whengo mod download
is invoked without arguments: users want something likego list all
that populates the module cache with modules needed to build packages in the main module, not including unused dependencies of dependencies. However, we shouldn't entirely preventgo mod download
from updatinggo.sum
, since it's the best way to add a specific sum for a necessary but unused module (for disambiguating an imported package).I'd suggest the following change in behavior for
go mod download
:go mod download
always loads the build list and reports an error ifgo.mod
needs to be updated instead of updating it automatically.go mod download
only adds a hash togo.sum
if the corresponding module is explicitly named on the command line (not simply matched byall
or a wildcard or implied by a lack of arguments) without an explicit version or at the version in the build list.cc @bcmills @matloob
The text was updated successfully, but these errors were encountered: