Description
#29452, #33779, and #31870 all describe issues due to cosmetic changes in the go.mod
file (specifically, newlines). CL 186557 changed the go
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 the go.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 the go.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