Skip to content
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

proposal: cmd/go: add go mod tidy -diff #67242

Closed
samthanawalla opened this issue May 7, 2024 · 1 comment
Closed

proposal: cmd/go: add go mod tidy -diff #67242

samthanawalla opened this issue May 7, 2024 · 1 comment

Comments

@samthanawalla
Copy link
Contributor

samthanawalla commented May 7, 2024

Proposal Details

Proposal:

Summarizing #27005 adding go mod tidy -diff would:

  • cause tidy to exit with a non-zero code if updates to go.mod or go.sum are needed, instead of modifying the files.
  • print the diff between the tidy go.mod and the current go.mod
  • print the diff between the tidy go.sum and the current go.sum

Motivation:

  • "integrated to tools like pre-commit hooks to make sure that we don't commit untidied go.mod and go.sum files into version control"
  • more transparency around go mod tidy

Discussion:

go mod tidy -check was discussed which would:

  • cause tidy to exit with a non-zero code if updates to go.mod or go.sum are needed, instead of modifying the files.
  • no diff information
  • @rsc had concerns that it would "encourage a mindset of "go.sum and go.mod are a black box that no one understands" without the diff context

Example:

go.mod

module example.com

main.go

package main

import "rsc.io/quote"

func main() {
	println(quote.Hello())
}
$ go mod tidy -diff
diff old go.mod new go.mod
        --- old go.mod
        +++ new go.mod
        @@ -1,1 +1,11 @@
         module example.com
        +
        +go 1.23
        +
        +require rsc.io/quote v1.5.2
        +
        +require (
        +       golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c // indirect
        +       rsc.io/sampler v1.3.0 // indirect
        +       rsc.io/testonly v1.0.0 // indirect
        +)

$ echo $?
1

Implementation pointers:

  • A new flag would need to be added to src/cmd/go/internal/modcmd/tidy.go
  • src/cmd/go/internal/modload/load.go
  • src/cmd/go/internal/modload/init.go
  • Use the internal diff package: src/internal/diff/diff.go
@rsc
Copy link
Contributor

rsc commented May 8, 2024

Duplicate of #27005, -diff is fine.

@rsc rsc closed this as completed May 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Incoming
Development

No branches or pull requests

3 participants