Add support for Go 1.16
See original GitHub issueGo 1.16 now rejects empty go.mod
files (c.f. https://github.com/golang/go/commit/d4986e0e1d6e03e1b92e905ca5e01b4c223fbeb3). This means that golang
hooks cannot be installed anymore:
$ pre-commit install-hooks
[INFO] Initializing environment for local.
[INFO] Installing environment for local.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/usr/local/bin/go', 'get', './...')
return code: 1
expected return code: 0
stdout: (none)
stderr:
go: no module declaration in go.mod. To specify the module path:
go mod edit -module=example.com/mod
Check the log at /Users/rdraoui/.cache/pre-commit/pre-commit.log
I could get it to work by changing pre_commit/resources/empty_template_go.mod
from an empty file to:
module example/mod
But I’m not all that familiar with how modules work in different Go versions, so maybe making that change has some other implications that I don’t know about. This Go Wiki entry seems to suggest that empty go.mod
files are legal, but maybe it’s outdated… (c.f: https://github.com/pre-commit/pre-commit/pull/1428#pullrequestreview-404547009)
The fix is compatible with Go 1.15.
I tried validating the fix by running the test suite (pytest tests -k golang
), but I can’t get it to pass with Go 1.15 and current master
branch either.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
this is the minimal patch to fix
repo: local
for golang (as far as I can tell, all other usages ofgo
work already):the testsuite however uses classical gopath-based modules which apparently are outright broken by go 1.16 unless
GO111MODULE=auto
is set (which is outside the control of pre-commit)hmm yeah it might just be that we need to copy the repo remote along here: https://github.com/pre-commit/pre-commit/blob/f3de91c2bb2d5dfefa2e9ad737cfa516964fe85e/pre_commit/languages/golang.py#L72-L73