Setup:
- Our project is using
golang 1.12.14 - We are using
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?
As of Go 1.14, the
gocommand automatically checks for consistency between thevendordirectory and thego.modfile whenever thevendordirectory is used. In addition, it uses thevendordirectory by default if the module specifiesgo 1.14or 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 vendoras a pre-commit hook. Thegocommand itself will flag inconsistencies whenever thevendordirectory is used.