-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Description
This is basically the same issue as #29058, but the default behavior has changed, so it may be worth reopening the discussion.
Since 1.14, the go command may use the vendor directory by default (without the -mod=vendor flag) if the go version in go.mod is 1.14 or higher and vendor/modules.txt is present. The go command reports an error if go.mod and vendor/modules.txt are out of sync.
Two commands primarily change go.mod: go mod tidy and go get. When these commands make changes, they break vendor builds until go mod vendor is run again.
We've avoided rebuilding the vendor directory implicitly, since the go command currently deletes the entire folder, loads the import graph, and recreates it from scratch. That may cause developers to lose local changes (like a patch being prepared for a dependency).
I propose some new behavior:
- We need a mechanism to detect local changes to
vendor. That probably means comparing the contents of each package directory to the corresponding directory in the module cache. That would help us implement cmd/go: allow verifying vendored code #27348. go getwould add or update packages in the vendor directory automatically if it's present. Only packages needed to build the packages named on the command line would be affected.go mod tidywould implicitly rebuild the vendor directory.go mod vendorwould be a no-op aftergo mod tidy.- Any command that modifies the vendor directory would report an error if local changes would be overwritten. We might want a flag to force overwrite, or the developer could run
git checkoutorrm -rf vendorfirst. - No change to
go buildand other commands.-mod=readonlyand-mod=modwould continue to ignore the vendor directory.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status