-
Notifications
You must be signed in to change notification settings - Fork 17.5k
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: 'mod tidy' sometimes adds new, unnecessary require sections #67948
Labels
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Comments
/cc @matloob @samthanawalla per owners |
matloob
added
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
GoCommand
cmd/go
labels
Jun 12, 2024
I can probably offer another example: https://github.com/siemens/turtlefinder/blob/f21b66938827bb8d9ec1a720b34c870465e5620e/go.mod The third require section in this case has even a mix of direct and indirect if I understand it correctly. |
klauspost
added a commit
to klauspost/mc
that referenced
this issue
Jul 3, 2024
Combine into direct and indirect sections. See golang/go#67948 for why this is a mess. Enables running `go mod tidy` without blowing up things.
harshavardhana
pushed a commit
to minio/mc
that referenced
this issue
Jul 3, 2024
Combine into direct and indirect sections. See golang/go#67948 for why this is a mess. Enables running `go mod tidy` without blowing up things.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Go version
go version go1.22.3 linux/amd64
Output of
go env
in your module/workspace:What did you do?
This is spun off of #56471. That proposal suggests having
go mod tidy
automatically join multiplerequire
sections. However, there's an underlying bug wherego mod tidy
itself is often responsible for these multiple sections. This issue is about the bug.On a large private Go module at work, we have three
require
sections. These were all created bygo mod tidy
. The first one has direct dependencies and the second and thirdrequire
sections have indirect dependencies.We can reproduce the error easily: if we delete the second
require
section (the first of the two indirect sections) and then rungo mod tidy
, it recreates the separate indirectrequire
section rather than adding the missing entries to the existingrequire
section.I cannot share the work code, but by looking through issues linked to #56471, I located a public repo where the same issue occurred. Here's how to reproduce the issue using that repo:
What did you see happen?
go mod tidy
added a new extra indirectrequire
section.What did you expect to see?
I would expect
go mod tidy
to add entries to the existingrequire
section.More generally: if I only ever edit go.mod automatically, never by hand, I would expect the Go tool to maintain at most two
require
sections (one direct and one indirect).Note that it is somewhat possible to work around the issue. If you manually join the two
require
sections,go mod tidy
will keep them together as one large section (it won't split them up). But this manual work shouldn't be required. Also, it's only temporary: future additions to the code may causego mod tidy
to add new sections togo.mod
.The text was updated successfully, but these errors were encountered: