-
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: do not update 'go.mod' automatically if the changes are only cosmetic #34822
Comments
Would it be a reasonable analogy to say this is like running the |
Yes, except that the |
The analogy above doesn't work: compiler doesn't change the code in case of compilation errors even if they are obvious; go build doesn't reformat the code: one has to run a dedicated command for that explicitly. IMHO it is hard to integrate with tools behaving like this. Every client will have to check and handle go.mod changes and roll them back if they are undesired. The go.mod file might not be under my control. If I want to list modules I will have to revert changes in go.mod again and again. I understand the intention of this behavior: to keep go.mod in a good shape and to add mandatory entries there, it is totally reasonable to have this behavior by default, but it would be great to have a mode with this logic disabled. |
That'd be |
Change https://golang.org/cl/204521 mentions this issue: |
Updates #30185 Updates #33326 Updates #34822 Change-Id: Ie13651585898d1bbbf4f779b97ee50b6c7e7ad50 Reviewed-on: https://go-review.googlesource.com/c/go/+/204521 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Jay Conrod <jayconrod@google.com>
Change https://golang.org/cl/204821 mentions this issue: |
Updates golang/go#34822 Change-Id: If6981c8673c2843f5075d6d9a478bcf80f26e2fb Reviewed-on: https://go-review.googlesource.com/c/mod/+/204821 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Change https://golang.org/cl/204877 mentions this issue: |
Change https://golang.org/cl/204878 mentions this issue: |
Updates #34822 Change-Id: I189d93ebd3ce6cd1b8f1e29336876fd82a7cfff7 Reviewed-on: https://go-review.googlesource.com/c/go/+/204877 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Change https://golang.org/cl/205497 mentions this issue: |
The previous behavior put the new 'go' directive at the end of the file, which is not where anybody actually puts it, and that in turn complicates the regression tests for golang/go#34822. Updates golang/go#34822 Change-Id: Ic275eb6999fc0db7e72e2d9636b77c9e3d919539 Reviewed-on: https://go-review.googlesource.com/c/mod/+/205497 Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Jay Conrod <jayconrod@google.com>
Also revert an incidental 'gofmt' of a vendored file from CL 205240. Updates #34822 Change-Id: I82a015d865db4d865b4776a8013312f25dbb9181 Reviewed-on: https://go-review.googlesource.com/c/go/+/205539 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Change https://golang.org/cl/205539 mentions this issue: |
Change https://golang.org/cl/219237 mentions this issue: |
… 'go list' Discovered while investigating #37197. Updates #33326 Updates #34822 Change-Id: I38b136a4ee762a580a554125066b9778491295f2 Reviewed-on: https://go-review.googlesource.com/c/go/+/219237 Run-TryBot: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
#29452, #33779, and #31870 all describe issues due to cosmetic changes in the
go.mod
file (specifically, newlines). CL 186557 changed thego
command to properly omit versions already implied by the module graph.It is possible that future changes to the
go
command will similarly add or remove redundant or non-essential information from thego.mod
file. (For example, #25898 (comment) suggests adding a comment for pseudo-versions indicating the corresponding non-semver tag, if any.)It is annoying and sometimes intrusive for the
go
command to make unnecessary edits to thego.mod
file.go mod tidy
should apply cosmetic edits to tidy up the file: that is part of its purpose. However, for other commands, I suggest:The
go
command should not overwrite thego.mod
file if it contains only formatting changes (spacing, newlines, ordering, grouping, etc.) or removes redundant-but-not-misleading information (such as arequire
line that specifies an indirect dependency already implied by some other indirect dependency).If
-mod=readonly
is set, thego
command should not fail if thego.mod
file contains additional comment-only changes (such as the addition or removal of an// indirect
comment), or omits helpful-but-unnecessary information (such as arequire
line for a direct dependency whose version is already implied by an indirect one, but contrast cmd/go: update to '@latest' when promoting an indirect dependency to a direct one? #34534).CC @jayconrod
The text was updated successfully, but these errors were encountered: