Skip to content

Conversation

@scop
Copy link
Contributor

@scop scop commented May 2, 2020

Empty local golang installs seem to fail when trying to use go modules in additional_dependencies. Test config:

repos:
  - repo: local
    hooks:
      - id: shfmt
        name: shfmt
        language: golang
        additional_dependencies: [mvdan.cc/sh/v3/cmd/shfmt]
        entry: shfmt
        args: [-w]
        types: [shell]
      - id: misspell
        name: misspell
        language: golang
        additional_dependencies: [github.com/client9/misspell/cmd/misspell]
        entry: misspell
        args: [-error]
        types: [text]

misspell is there just to represent something that's not a go module, and to see this change didn't break it (it didn't).

With pre-commit 2.3.0 shfmt setup fails for me with golang 1.12, 1.13, and 1.14 with:

An unexpected error has occurred: CalledProcessError: command: ('/usr/bin/go', 'get', 'mvdan.cc/sh/v3/cmd/shfmt')
return code: 1
expected return code: 0
stdout: (none)
stderr:
    package mvdan.cc/sh/v3/cmd/shfmt: cannot find package "mvdan.cc/sh/v3/cmd/shfmt" in any of:
    	/usr/lib/go-1.14/src/mvdan.cc/sh/v3/cmd/shfmt (from $GOROOT)
    	/home/scop/.cache/pre-commit/repoetpe3oez/golangenv-default/src/mvdan.cc/sh/v3/cmd/shfmt (from $GOPATH)

After this change, it works out of the box for me with go 1.13 and 1.14. For 1.12 this isn't enough, it would additionally need GO111MODULE=on in the environment, after that it'd work too. I left it out of this PR because I'm not quite sure if it would cause problems with some "conventional" installs pointed to upstream repos that provide a hook config. For this particular test it would not cause any problems with 1.13 or 1.14 though.

@scop scop force-pushed the golang-empty-dummy-module branch from a008606 to e2ed732 Compare May 2, 2020 18:02
Copy link
Member

@asottile asottile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asottile asottile merged commit 5ed3f56 into pre-commit:master May 2, 2020
@scop scop deleted the golang-empty-dummy-module branch May 2, 2020 22:05
@asottile
Copy link
Member

thanks again for fixing this, this has been released as part of v2.4.0 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants