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

cmd/go: add mod tidy -check #27005

fishy opened this issue Aug 15, 2018 · 9 comments


Copy link

commented Aug 15, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.11rc1 darwin/amd64

Does this issue reproduce with the latest release?


What operating system and processor architecture are you using (go env)?


What did you do?

  • Remove lines from go.mod and go.sum files
  • Run go mod tidy to add them back

What did you expect to see?

go mod tidy should return non-zero as it made changes. This way it could be 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

What did you see instead?

go mod tidy returned zero


This comment has been minimized.

Copy link

commented Aug 15, 2018

Non-zero exit codes are usually for errors, so having it behave like this by default would be counter-intuitive.

Perhaps it could have something similar to gofmt, which has the -l and -d flags to tell if any changes were made.


This comment has been minimized.

Copy link

commented Aug 15, 2018

If the files are successfully added why wouldn't you want to see a 0 status code? This means that the following script would fail:

#!/usr/bin/env bash
set -e
go mod tidy  # <-- non 0 return code
echo 'we never get here'

This comment has been minimized.

Copy link

commented Aug 15, 2018

That makes sense. How about maybe make it optional? e.g. when it's executed with a flag it should return non-zero when it made any changes.


This comment has been minimized.

Copy link

commented Aug 15, 2018

@gopherbot, please add label modules

@gopherbot gopherbot added the modules label Aug 15, 2018

@rsc rsc changed the title modules: `go mod tidy` should return non-zero when it made changes to go.mod and/or go.sum files cmd/go: add mod tidy -check Aug 18, 2018


This comment has been minimized.

Copy link

commented Aug 18, 2018

We could think about adding a flag that means "don't do the update, but fail if one is needed".
Not sure exactly what to call it but I put -check in the description. Needs more thought.

@rsc rsc added this to the Go1.12 milestone Aug 18, 2018

@rsc rsc added the NeedsDecision label Aug 18, 2018

@bcmills bcmills modified the milestones: Go1.12, Go1.13 Oct 24, 2018

radeksimko added a commit to terraform-providers/terraform-provider-acme that referenced this issue Feb 19, 2019
Remove govendor references
 - 'go mod verify' is not that useful and isn't equivalent to govendor status.
 - 'go mod tidy -v' does not return non-zero exit code when dependencies aren't tidy
 - We might add 'go mod tidy -check' at some point, when it becomes a thing.
   See golang/go#27005
   Until then it's better to keep provider setup aligned though.

This comment has been minimized.

Copy link

commented Feb 25, 2019

@rsc regarding your comment in #26850

You could use 'go list all -mod=readonly' to check that at least for the current GOOS/GOARCH no changes are needed.

go list all -mod=readonly causes changes for me to go.sum without erroring.

Is this a bug?


This comment has been minimized.

Copy link

commented Apr 24, 2019

When this is implemented, we should run this on the TryBots (#31640).

Ideally go mod tidy -check would not access the network, since it will commonly be run in CI environments where network access is restricted. We might want to do so to provide diagnostics though. GOPROXY=off is still a good signal that we shouldn't access the network.


This comment has been minimized.

Copy link

commented May 23, 2019

This is a feature that we would like to see for our CI environment as well (we want to verify that go.mod and go.sum are in the proper state for all submissions for all possible build constraints).

I echo the sentiment expressed by @jayconrod that it would be ideal if this check could be performed without network access -- is it feasible for the -check mode to verify only that no change needs to be made without making network queries? My intuition is that the information provided by the source code, go.mod and go.sum should be sufficient to make this determination, but I'm not completely sure about this.

@andybons andybons modified the milestones: Go1.13, Go1.14 Jul 8, 2019


This comment has been minimized.

Copy link

commented Jul 22, 2019

It's would be useful to reduce git conflict in lint scenario

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
You can’t perform that action at this time.