You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go 1.16 now rejects empty go.mod files (c.f. golang/go@d4986e0). 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: #1428 (review))
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.
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)
In addition, adding the file testing/resources/golang_hooks_repo/go.mod with content module golang-hello-world makes the tests pass under all combinations of Go [1.15|1.16] + GO111MODULE=[""|"on"|"auto"]
Activity
asottile commentedon Feb 24, 2021
hmmm what an annoying change, why would they do this -- the patch seems unrelated to the issue it closes
asottile commentedon Feb 24, 2021
this is the minimal patch to fix
repo: localfor golang (as far as I can tell, all other usages ofgowork already):the testsuite however uses classical gopath-based modules which apparently are outright broken by go 1.16 unless
GO111MODULE=autois set (which is outside the control of pre-commit)rafikdraoui commentedon Feb 25, 2021
In addition, adding the file
testing/resources/golang_hooks_repo/go.modwith contentmodule golang-hello-worldmakes the tests pass under all combinations ofGo [1.15|1.16]+GO111MODULE=[""|"on"|"auto"]I can make a PR if you want.
asottile commentedon Feb 25, 2021
sure! it seems surprising that such a
testingfile is necessary -- makes me think that all hook-producers will need to do the same as wellI wonder if there's something with our temporary
GOPATHsetup that might need adjusting as wellbut yeah feel free to send a PR to get the ball rolling!
asottile commentedon Feb 25, 2021
hmm yeah it might just be that we need to copy the repo remote along here:
pre-commit/pre_commit/languages/golang.py
Lines 72 to 73 in f3de91c