Open randall77 opened 6 days ago
@matloob
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
We did this intentionally, though I agree it's a bit awkward and we might potentially need to add a feature to help users with checked in go.mod
files.
Since -mod=readonly
is the default mode for build commands, the normal workflow in a single module, outside of a workspace, is to run go get
/go mod tidy
to make required changes to go.mod
files and also update go.sum files before doing builds that require those changes.
If the -mod=readonly
behavior also made go.work.sum
read only, another command would have to be run after go get
and go mod tidy
change go.mod files to ensure that go.work.sum
contains all the relevant sums. (We wouldn't want go get
and go mod tidy
to make the modifications themselves because those commands operate on a single module level and a single module can participate in multiple workspaces) This command would add significant friction to users of workspaces for not much benefit.
The most important goal of the mod=readonly
mode (as I understand it) is that doing operations like builds and lists should not (surprisingly) change the set of requirements of a module in turn changing the actual code that's built. The operation that changes the build is put into into a separate command so that it is done explicitly. Since go.sum
is also checked in, and only needs to be changed when module dependencies are changed, it makes sense to have the rule apply to both go.mod and go.sum.
When we started working on workspaces, the intention was that go.work
(and go.work.sum
) files would only be checked in in very rare circumstances. We still encourage users to consider carefully if they should check in go.work files because it does cause a lot of headaches, but it seems now like we need to address some of those headaches.
I do think that the current behavior is the best behavior for most users, but perhaps we should add a command (maybe called go work tidy
that will ensure that the go.work.sum
file is complete for the all
pattern). Then CI could check that that command doesn't make any changes, and in the use case where you clone oscar and do a build there would be no modifications to go.work.sum because it would already be updated?
Go version
go1.23.2
Output of
go env
in your module/workspace:What did you do?
What did you see happen?
go.work.sum
file has changes to it.What did you expect to see?
go.work.sum
file unchanged, because the-mod=readonly
flag was given.