-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/go: mod tidy -go=1.17
should move indirect dependencies to the second require part
#47733
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
Comments
Can you share your go.mod? |
Sure here is my
|
I can confirm this finding. I've also noticed another "weird" behaviour: while the second part is generated during |
go mod tidy -go=1.17
should move indirect dependencies to the second require partmod tidy -go=1.17
should move indirect dependencies to the second require part
@gopherbot Please backport to 1.17. This is annoying behavior in a new feature, and the fix shouldn't be very disruptive. |
Backport issue(s) opened: #47756 (for 1.17). Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases. |
Change https://golang.org/cl/343431 mentions this issue: |
Change https://golang.org/cl/343432 mentions this issue: |
I don't know if it's related but in some projects I now have three require blocks which I don't think is explicitly mentioned in this issue before. The first one has mixed direct and indirect dependencies, the second one only has direct dependencies and the third one only has indirect dependencies. The bottom sections are added by The release notes only speaks about a second section for indirect dependencies so I don't know if having three sections is considered a bug or not.
If it's supposed to be three sections that I am sorry for making a noise about it if it isn't maybe EDIT: It is possible that |
…ntly SetRequireSeparateIndirect now makes a stronger attempt to keep automatically added requirements in two blocks: one containing only direct requirements and one containing only indirect requirements. SetRequireSeparateIndirect will find or add these two blocks (commented blocks are left alone). New requirements are added to one of these two blocks. Existing requirements may be moved between these two blocks if their markings change. SetRequireSeparateIndirect attempts to preserve existing structure in the file by not adding requirements to or moving requirements from blocks with block-level comments and blocks other than the last uncommented direct-only and indirect-only block. As an exception to aid with migration, if the file contains a single uncommented block of requirements (as would the be the case if the user started with a 1.16 go.mod file, changed the go directive to 1.17, then ran 'go mod tidy'), SetRequireSeparateIndirect will split the block into direct-only and indirect-only blocks. This is a change in behavior, but it has no semantic effect, and it should result in cleaner, more stable go.mod files. For golang/go#47563 For golang/go#47733 Change-Id: Ifa20bb084c6bdaf1e00140600380857de8afa320 Reviewed-on: https://go-review.googlesource.com/c/mod/+/343431 Trust: Jay Conrod <jayconrod@google.com> Trust: Bryan C. Mills <bcmills@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
Change https://golang.org/cl/348576 mentions this issue: |
When reading go.mod, SetRequireSeparateIndirect will insert new requirements into the last uncommented direct-only or indirect-only block OR line. If the last such statement is a line, SetRequireSeparateIndirect converts it to a block before inserting new requirements. Cleanup will convert it back to a line later if no requirements are inserted. For golang/go#47733 Change-Id: Id8ee3b0ce2d005488ddb3d9a5349115bd93938e7 Reviewed-on: https://go-review.googlesource.com/c/mod/+/348576 Trust: Jay Conrod <jayconrod@google.com> Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
The command ´go mod tidy´ [1] can be used to update the ´go.mod` file so that it contains exactly the actually used dependencies. Doing so results in all indirect dependencies being added to the ´go.mod´ file with a trailing comment, ´// indirect´, to indicate that it is an indirect dependency, see also [2]. As ´go mod graph´ does not interprete these comments, its output graph contains edges between the main module and each indirect dependency. Skip these edges to avoid flattening the dependency tree. [1] https://go.dev/ref/mod#go-mod-tidy [2] golang/go#47733 (comment) Signed-off-by: Frank Viernau <frank_viernau@epam.com>
The command `go mod tidy` [1] can be used to update the `go.mod` file so that it contains exactly the actually used dependencies. Doing so results in all indirect dependencies being added to the `go.mod` file with a trailing comment, `// indirect`, to indicate that it is an indirect dependency, see also [2]. As `go mod graph` does not interprete these comments, its output graph contains edges between the main module and each indirect dependency. Skip these edges to avoid flattening the dependency tree. [1] https://go.dev/ref/mod#go-mod-tidy [2] golang/go#47733 (comment) Signed-off-by: Frank Viernau <frank_viernau@epam.com>
The command `go mod tidy` [1] can be used to update the `go.mod` file so that it contains exactly the actually used dependencies. Doing so results in all indirect dependencies being added to the `go.mod` file with a trailing comment, `// indirect`, to indicate that it is an indirect dependency, see also [2]. As `go mod graph` does not interprete these comments, its output graph contains edges between the main module and each indirect dependency. Skip these edges to avoid flattening the dependency tree. [1] https://go.dev/ref/mod#go-mod-tidy [2] golang/go#47733 (comment) Signed-off-by: Frank Viernau <frank_viernau@epam.com>
The command `go mod tidy` [1] can be used to update the `go.mod` file so that it contains exactly the actually used dependencies. Doing so results in all indirect dependencies being added to the `go.mod` file with a trailing comment, `// indirect`, to indicate that it is an indirect dependency, see also [2]. As `go mod graph` does not interprete these comments, its output graph contains edges between the main module and each indirect dependency. Skip these edges to avoid flattening the dependency tree. [1] https://go.dev/ref/mod#go-mod-tidy [2] golang/go#47733 (comment) Signed-off-by: Frank Viernau <frank_viernau@epam.com>
The command `go mod tidy` [1] can be used to update the `go.mod` file so that it contains exactly the actually used dependencies. Doing so results in all indirect dependencies being added to the `go.mod` file with a trailing comment, `// indirect`, to indicate that it is an indirect dependency, see also [2]. As `go mod graph` does not interprete these comments, its output graph contains edges between the main module and each indirect dependency. Skip these edges to avoid flattening the dependency tree. [1] https://go.dev/ref/mod#go-mod-tidy [2] golang/go#47733 (comment) Signed-off-by: Frank Viernau <frank_viernau@epam.com>
The command `go mod tidy` [1] can be used to update the `go.mod` file so that it contains exactly the actually used dependencies. Doing so results in all indirect dependencies being added to the `go.mod` file with a trailing comment, `// indirect`, to indicate that it is an indirect dependency, see also [2]. As `go mod graph` does not interprete these comments, its output graph contains edges between the main module and each indirect dependency. Skip these edges to avoid flattening the dependency tree. [1] https://go.dev/ref/mod#go-mod-tidy [2] golang/go#47733 (comment) Signed-off-by: Frank Viernau <frank_viernau@epam.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
ran
go mod tidy -go=1.17
as described on https://golang.org/doc/go1.17What did you expect to see?
I expected to see that the
// indirect
dependencies in mygo.mod
file get moved to the second indirectrequire
part of the file.What did you see instead?
Some new indirect dependencies were added but the old
// indirect
are left untouched. If I remove the indirect entries from the firstrequire
block and run the command again, they are only added to the bottom. This is no deal breaker but I think this could be improved to make the go.mod file a bit clearer by also moving all previous indirects to the second block.The text was updated successfully, but these errors were encountered: