Reputation: 9825
Setup:
golang 1.12.14
go build -mod=vendor
Issue: When new dependencies are added to go.mod
the vendor folder isn't updated and people are committing code and forgetting to run go mod vendor
to update the folder. My understanding is that since -mod=vendor
specifies to use packages from the vendor
folder, the go.mod
file will have discrepancies from what we are actually using when building the project.
Question: Should go mod vendor
be added to a pre-commit hook?
Upvotes: 1
Views: 2266
Reputation: 5197
As of Go 1.14, the go
command automatically checks for consistency between the vendor
directory and the go.mod
file whenever the vendor
directory is used. In addition, it uses the vendor
directory by default if the module specifies go 1.14
or higher (see https://tip.golang.org/doc/go1.14#go-command).
As of today, the oldest supported version of the Go toolchain is Go 1.15.13.
So if you upgrade to a supported version of the Go toolchain, it should not be necessary to run go mod vendor
as a pre-commit hook. The go
command itself will flag inconsistencies whenever the vendor
directory is used.
Upvotes: 2