pre-commit: command: `go install` fails with: error obtaining VCS status: exit status 128 while installing check

search you tried in the issue tracker

error obtaining VCS status: exit status

describe your issue

I was just running the pre-commit checks. It looks like the failures started after the update.

git commit -am "My ultimate commit"

Output:

[INFO] Installing environment for https://github.com/stackrox/kube-linter.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/opt/homebrew/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/fatih/color v1.13.0
    go: downloading github.com/Masterminds/sprig/v3 v3.2.3
    go: downloading github.com/pkg/errors v0.9.1
    ...
    go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.

I have also tried to run: pre-commit clean but it did not help.

pre-commit --version

pre-commit 3.0.0

.pre-commit-config.yaml

repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.4.0
    hooks:
      - id: check-added-large-files
      - id: check-merge-conflict
      - id: detect-aws-credentials
        args:
          - "--allow-missing-credentials"
      - id: detect-private-key
      - id: end-of-file-fixer
      - id: mixed-line-ending
      - id: trailing-whitespace
  - repo: https://github.com/stackrox/kube-linter
    rev: 0.5.1
    hooks:
      - id: kube-linter
        args: [lint, --config, .kube-linter.yaml]
  - repo: https://github.com/adrienverge/yamllint.git
    rev: v1.28.0
    hooks:
      - id: yamllint
        args: [-c=.yamllint]
  - repo: https://github.com/Yelp/detect-secrets
    rev: v1.4.0
    hooks:
      - id: detect-secrets
        args:
          [
            "--disable-plugin",
            "KeywordDetector",
            "--baseline",
            ".secrets.baseline",
          ]
        exclude: package.lock.json

~/.cache/pre-commit/pre-commit.log (if present)

version information

pre-commit version: 3.0.0
git --version: git version 2.39.1
sys.version:
    3.11.1 (main, Dec 23 2022, 09:28:24) [Clang 14.0.0 (clang-1400.0.29.202)]
sys.executable: /opt/homebrew/Cellar/pre-commit/3.0.0/libexec/bin/python3
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/opt/homebrew/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/fatih/color v1.13.0
    go: downloading github.com/Masterminds/sprig/v3 v3.2.3
    go: downloading github.com/pkg/errors v0.9.1
    go: downloading github.com/ghodss/yaml v1.0.0
    go: downloading github.com/spf13/cobra v1.6.1
    go: downloading github.com/spf13/pflag v1.0.5
    go: downloading github.com/owenrumney/go-sarif/v2 v2.1.2
    go: downloading github.com/spf13/viper v1.14.0
    go: downloading github.com/openshift/api v3.9.0+incompatible
    go: downloading k8s.io/apimachinery v0.25.4
    go: downloading k8s.io/api v0.25.4
    go: downloading github.com/stretchr/testify v1.8.1
    go: downloading helm.sh/helm/v3 v3.10.2
    go: downloading k8s.io/gengo v0.0.0-20211129171323-c02415ce4185
    go: downloading k8s.io/client-go v0.25.4
    go: downloading github.com/mitchellh/mapstructure v1.5.0
    go: downloading gopkg.in/yaml.v2 v2.4.0
    go: downloading github.com/mattn/go-colorable v0.1.13
    go: downloading github.com/mattn/go-isatty v0.0.16
    go: downloading github.com/Masterminds/goutils v1.1.1
    go: downloading github.com/Masterminds/semver/v3 v3.2.0
    go: downloading github.com/google/uuid v1.3.0
    go: downloading github.com/huandu/xstrings v1.3.3
    go: downloading github.com/imdario/mergo v0.3.12
    go: downloading github.com/mitchellh/copystructure v1.2.0
    go: downloading github.com/shopspring/decimal v1.2.0
    go: downloading github.com/spf13/cast v1.5.0
    go: downloading golang.org/x/crypto v0.3.0
    go: downloading github.com/Masterminds/semver v1.5.0
    go: downloading github.com/fsnotify/fsnotify v1.6.0
    go: downloading github.com/spf13/afero v1.9.2
    go: downloading github.com/spf13/jwalterweatherman v1.1.0
    go: downloading github.com/gogo/protobuf v1.3.2
    go: downloading github.com/google/gofuzz v1.2.0
    go: downloading k8s.io/klog/v2 v2.80.1
    go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.2.3
    go: downloading k8s.io/utils v0.0.0-20220922133306-665eaaec4324
    go: downloading sigs.k8s.io/yaml v1.3.0
    go: downloading gopkg.in/inf.v0 v0.9.1
    go: downloading github.com/BurntSushi/toml v1.2.1
    go: downloading github.com/gobwas/glob v0.2.3
    go: downloading github.com/cyphar/filepath-securejoin v0.2.3
    go: downloading github.com/xeipuuv/gojsonschema v1.2.0
    go: downloading k8s.io/apiextensions-apiserver v0.25.2
    go: downloading golang.org/x/sys v0.2.0
    go: downloading github.com/mitchellh/reflectwalk v1.0.2
    go: downloading github.com/subosito/gotenv v1.4.1
    go: downloading github.com/hashicorp/hcl v1.0.0
    go: downloading gopkg.in/ini.v1 v1.67.0
    go: downloading github.com/magiconair/properties v1.8.6
    go: downloading github.com/pelletier/go-toml/v2 v2.0.5
    go: downloading gopkg.in/yaml.v3 v3.0.1
    go: downloading sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2
    go: downloading golang.org/x/text v0.4.0
    go: downloading github.com/davecgh/go-spew v1.1.1
    go: downloading github.com/pmezard/go-difflib v1.0.0
    go: downloading github.com/go-logr/logr v1.2.3
    go: downloading github.com/golang/protobuf v1.5.2
    go: downloading github.com/pelletier/go-toml v1.9.5
    go: downloading github.com/google/gnostic v0.6.9
    go: downloading golang.org/x/net v0.2.0
    go: downloading github.com/json-iterator/go v1.1.12
    go: downloading github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
    go: downloading k8s.io/cli-runtime v0.25.4
    go: downloading github.com/containerd/containerd v1.6.6
    go: downloading github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
    go: downloading github.com/sirupsen/logrus v1.9.0
    go: downloading oras.land/oras-go v1.2.0
    go: downloading google.golang.org/protobuf v1.28.1
    go: downloading k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea
    go: downloading golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
    go: downloading golang.org/x/term v0.2.0
    go: downloading golang.org/x/time v0.0.0-20220609170525-579cf78fd858
    go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
    go: downloading github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f
    go: downloading github.com/modern-go/reflect2 v1.0.2
    go: downloading github.com/evanphx/json-patch v5.6.0+incompatible
    go: downloading github.com/opencontainers/go-digest v1.0.0
    go: downloading github.com/docker/cli v20.10.17+incompatible
    go: downloading github.com/docker/distribution v2.8.1+incompatible
    go: downloading golang.org/x/sync v0.1.0
    go: downloading github.com/docker/docker v20.10.17+incompatible
    go: downloading github.com/docker/go-connections v0.4.0
    go: downloading github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
    go: downloading github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
    go: downloading sigs.k8s.io/kustomize/api v0.12.1
    go: downloading sigs.k8s.io/kustomize/kyaml v0.13.9
    go: downloading github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
    go: downloading github.com/peterbourgon/diskv v2.0.1+incompatible
    go: downloading github.com/moby/locker v1.0.1
    go: downloading google.golang.org/grpc v1.50.1
    go: downloading github.com/emicklei/go-restful/v3 v3.8.0
    go: downloading github.com/docker/docker-credential-helpers v0.6.4
    go: downloading github.com/go-openapi/swag v0.19.14
    go: downloading github.com/go-openapi/jsonreference v0.19.5
    go: downloading github.com/google/btree v1.0.1
    go: downloading github.com/klauspost/compress v1.14.1
    go: downloading github.com/mailru/easyjson v0.7.6
    go: downloading github.com/PuerkitoBio/purell v1.1.1
    go: downloading github.com/go-openapi/jsonpointer v0.19.5
    go: downloading github.com/gorilla/mux v1.8.0
    go: downloading github.com/go-errors/errors v1.0.1
    go: downloading github.com/josharian/intern v1.0.0
    go: downloading google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e
    go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
    go: downloading github.com/docker/go-metrics v0.0.1
    go: downloading github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
    go: downloading github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00
    go: downloading github.com/xlab/treeprint v1.1.0
    go: downloading github.com/docker/go-units v0.4.0
    go: downloading github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
    go: downloading github.com/morikuni/aec v1.0.0
    go: downloading go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5
    go: downloading github.com/prometheus/client_golang v1.13.0
    go: downloading github.com/beorn7/perks v1.0.1
    go: downloading github.com/prometheus/common v0.37.0
    go: downloading github.com/cespare/xxhash/v2 v2.1.2
    go: downloading github.com/prometheus/client_model v0.2.0
    go: downloading github.com/prometheus/procfs v0.8.0
    go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/main.py", line 366, in main
    return hook_impl(
           ^^^^^^^^^^
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/commands/hook_impl.py", line 254, in hook_impl
    return retv | run(config, store, ns)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/commands/run.py", line 436, in run
    install_hook_envs(to_install, store)
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/repository.py", line 239, in install_hook_envs
    _hook_install(hook)
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/repository.py", line 86, in _hook_install
    lang.install_environment(
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/languages/golang.py", line 152, in install_environment
    helpers.run_setup_cmd(prefix, ('go', 'install', './...'), env=env)
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/languages/helpers.py", line 49, in run_setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/opt/homebrew/Cellar/pre-commit/3.0.0/libexec/lib/python3.11/site-packages/pre_commit/util.py", line 115, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/opt/homebrew/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/fatih/color v1.13.0
    go: downloading github.com/Masterminds/sprig/v3 v3.2.3
    go: downloading github.com/pkg/errors v0.9.1
    go: downloading github.com/ghodss/yaml v1.0.0
    go: downloading github.com/spf13/cobra v1.6.1
    go: downloading github.com/spf13/pflag v1.0.5
    go: downloading github.com/owenrumney/go-sarif/v2 v2.1.2
    go: downloading github.com/spf13/viper v1.14.0
    go: downloading github.com/openshift/api v3.9.0+incompatible
    go: downloading k8s.io/apimachinery v0.25.4
    go: downloading k8s.io/api v0.25.4
    go: downloading github.com/stretchr/testify v1.8.1
    go: downloading helm.sh/helm/v3 v3.10.2
    go: downloading k8s.io/gengo v0.0.0-20211129171323-c02415ce4185
    go: downloading k8s.io/client-go v0.25.4
    go: downloading github.com/mitchellh/mapstructure v1.5.0
    go: downloading gopkg.in/yaml.v2 v2.4.0
    go: downloading github.com/mattn/go-colorable v0.1.13
    go: downloading github.com/mattn/go-isatty v0.0.16
    go: downloading github.com/Masterminds/goutils v1.1.1
    go: downloading github.com/Masterminds/semver/v3 v3.2.0
    go: downloading github.com/google/uuid v1.3.0
    go: downloading github.com/huandu/xstrings v1.3.3
    go: downloading github.com/imdario/mergo v0.3.12
    go: downloading github.com/mitchellh/copystructure v1.2.0
    go: downloading github.com/shopspring/decimal v1.2.0
    go: downloading github.com/spf13/cast v1.5.0
    go: downloading golang.org/x/crypto v0.3.0
    go: downloading github.com/Masterminds/semver v1.5.0
    go: downloading github.com/fsnotify/fsnotify v1.6.0
    go: downloading github.com/spf13/afero v1.9.2
    go: downloading github.com/spf13/jwalterweatherman v1.1.0
    go: downloading github.com/gogo/protobuf v1.3.2
    go: downloading github.com/google/gofuzz v1.2.0
    go: downloading k8s.io/klog/v2 v2.80.1
    go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.2.3
    go: downloading k8s.io/utils v0.0.0-20220922133306-665eaaec4324
    go: downloading sigs.k8s.io/yaml v1.3.0
    go: downloading gopkg.in/inf.v0 v0.9.1
    go: downloading github.com/BurntSushi/toml v1.2.1
    go: downloading github.com/gobwas/glob v0.2.3
    go: downloading github.com/cyphar/filepath-securejoin v0.2.3
    go: downloading github.com/xeipuuv/gojsonschema v1.2.0
    go: downloading k8s.io/apiextensions-apiserver v0.25.2
    go: downloading golang.org/x/sys v0.2.0
    go: downloading github.com/mitchellh/reflectwalk v1.0.2
    go: downloading github.com/subosito/gotenv v1.4.1
    go: downloading github.com/hashicorp/hcl v1.0.0
    go: downloading gopkg.in/ini.v1 v1.67.0
    go: downloading github.com/magiconair/properties v1.8.6
    go: downloading github.com/pelletier/go-toml/v2 v2.0.5
    go: downloading gopkg.in/yaml.v3 v3.0.1
    go: downloading sigs.k8s.io/json v0.0.0-20220713155537-f223a00ba0e2
    go: downloading golang.org/x/text v0.4.0
    go: downloading github.com/davecgh/go-spew v1.1.1
    go: downloading github.com/pmezard/go-difflib v1.0.0
    go: downloading github.com/go-logr/logr v1.2.3
    go: downloading github.com/golang/protobuf v1.5.2
    go: downloading github.com/pelletier/go-toml v1.9.5
    go: downloading github.com/google/gnostic v0.6.9
    go: downloading golang.org/x/net v0.2.0
    go: downloading github.com/json-iterator/go v1.1.12
    go: downloading github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415
    go: downloading k8s.io/cli-runtime v0.25.4
    go: downloading github.com/containerd/containerd v1.6.6
    go: downloading github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799
    go: downloading github.com/sirupsen/logrus v1.9.0
    go: downloading oras.land/oras-go v1.2.0
    go: downloading google.golang.org/protobuf v1.28.1
    go: downloading k8s.io/kube-openapi v0.0.0-20220803164354-a70c9af30aea
    go: downloading golang.org/x/oauth2 v0.0.0-20221014153046-6fdb5e3db783
    go: downloading golang.org/x/term v0.2.0
    go: downloading golang.org/x/time v0.0.0-20220609170525-579cf78fd858
    go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
    go: downloading github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f
    go: downloading github.com/modern-go/reflect2 v1.0.2
    go: downloading github.com/evanphx/json-patch v5.6.0+incompatible
    go: downloading github.com/opencontainers/go-digest v1.0.0
    go: downloading github.com/docker/cli v20.10.17+incompatible
    go: downloading github.com/docker/distribution v2.8.1+incompatible
    go: downloading golang.org/x/sync v0.1.0
    go: downloading github.com/docker/docker v20.10.17+incompatible
    go: downloading github.com/docker/go-connections v0.4.0
    go: downloading github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
    go: downloading github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de
    go: downloading sigs.k8s.io/kustomize/api v0.12.1
    go: downloading sigs.k8s.io/kustomize/kyaml v0.13.9
    go: downloading github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
    go: downloading github.com/peterbourgon/diskv v2.0.1+incompatible
    go: downloading github.com/moby/locker v1.0.1
    go: downloading google.golang.org/grpc v1.50.1
    go: downloading github.com/emicklei/go-restful/v3 v3.8.0
    go: downloading github.com/docker/docker-credential-helpers v0.6.4
    go: downloading github.com/go-openapi/swag v0.19.14
    go: downloading github.com/go-openapi/jsonreference v0.19.5
    go: downloading github.com/google/btree v1.0.1
    go: downloading github.com/klauspost/compress v1.14.1
    go: downloading github.com/mailru/easyjson v0.7.6
    go: downloading github.com/PuerkitoBio/purell v1.1.1
    go: downloading github.com/go-openapi/jsonpointer v0.19.5
    go: downloading github.com/gorilla/mux v1.8.0
    go: downloading github.com/go-errors/errors v1.0.1
    go: downloading github.com/josharian/intern v1.0.0
    go: downloading google.golang.org/genproto v0.0.0-20221024183307-1bc688fe9f3e
    go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
    go: downloading github.com/docker/go-metrics v0.0.1
    go: downloading github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
    go: downloading github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00
    go: downloading github.com/xlab/treeprint v1.1.0
    go: downloading github.com/docker/go-units v0.4.0
    go: downloading github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6
    go: downloading github.com/morikuni/aec v1.0.0
    go: downloading go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5
    go: downloading github.com/prometheus/client_golang v1.13.0
    go: downloading github.com/beorn7/perks v1.0.1
    go: downloading github.com/prometheus/common v0.37.0
    go: downloading github.com/cespare/xxhash/v2 v2.1.2
    go: downloading github.com/prometheus/client_model v0.2.0
    go: downloading github.com/prometheus/procfs v0.8.0
    go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
        Use -buildvcs=false to disable VCS stamping.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 23 (10 by maintainers)

Commits related to this issue

Most upvoted comments

I’m encountering this now.

Workaround

I’m able to circumvent this problem by committing once like so:

GOFLAGS=-buildvcs=false git commit -av

After this succeeded, if I run pre-commit clean && pre-commit install-hooks, I don’t see the error again. I’d expect to see it, so I might be doing something odd here. I expected to have to do

GOFLAGS=-buildvcs=false pre-commit install-hooks

after pre-commit clean.

Research and observations

Some research indicates that it’s related to one or more of the following:

  • go 1.18 embeds git information at build time
  • The build directory needing to be in git’s safe.directory

Possible remedies

  1. Do what it says on the tin: add -buildvcs=false here, perhaps with end-user control of it
  2. Maybe the there needs to be a go get && git config --global --add safe.directory ${where_go_get_put_it} && go install ${where_go_get_put_it}; I’m not a Go dev so 🤷

See also:

Requested troubleshooting information

version information

pre-commit version: 3.2.1
git --version: git version 2.40.0
sys.version:
    3.11.2 (main, Feb 16 2023, 02:55:59) [Clang 14.0.0 (clang-1400.0.29.202)]
sys.executable: /opt/homebrew/Cellar/pre-commit/3.2.1/libexec/bin/python3
os.name: posix
sys.platform: darwin

error information

An unexpected error has occurred: CalledProcessError: command: ('/opt/homebrew/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    error obtaining VCS status: exit status 128
    	Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
    	Use -buildvcs=false to disable VCS stamping.
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/main.py", line 381, in main
    return hook_impl(
           ^^^^^^^^^^
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/commands/hook_impl.py", line 271, in hook_impl
    return retv | run(config, store, ns)
                  ^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/commands/run.py", line 442, in run
    install_hook_envs(to_install, store)
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/repository.py", line 248, in install_hook_envs
    _hook_install(hook)
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/repository.py", line 95, in _hook_install
    lang.install_environment(
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/languages/golang.py", line 152, in install_environment
    lang_base.setup_cmd(prefix, ('go', 'install', './...'), env=env)
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/lang_base.py", line 87, in setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/opt/homebrew/Cellar/pre-commit/3.2.1/libexec/lib/python3.11/site-packages/pre_commit/util.py", line 110, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/opt/homebrew/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    error obtaining VCS status: exit status 128
    	Use -buildvcs=false to disable VCS stamping.
    error obtaining VCS status: exit status 128
    	Use -buildvcs=false to disable VCS stamping.

env | grep -Ei '(GIT|PRE_COMMIT|GO)' | sort

FZF_CTRL_T_COMMAND=rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,build}/*" 2> /dev/null
FZF_DEFAULT_COMMAND=rg --files --no-ignore --hidden --follow -g "!{.git,node_modules,build}/*" 2> /dev/null
GIT_PS1_SHOWDIRTYSTATE=true
GIT_PS1_SHOWUNTRACKEDFILES=true
GOPATH=/Users/colin/.go
PATH=/Users/colin/.conscript/bin:/Users/colin/.cache/micromamba/condabin:/Users/colin/.pyenv/shims:/Users/colin/.local/bin:/Users/colin/.bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/opt/llvm/bin:/Library/Java/Home/bin:/Users/colin/.cargo/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/Library/TeX/texbin:/Library/Application Support/CDM/bin:/usr/local/munki:/Applications/kitty.app/Contents/MacOS:/usr/local/opt/rust/bin:/Users/colin/.cabal/bin:/usr/local/heroku/bin:/usr/local/opt/go/libexec/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin:/Library/TeX/texbin:/Library/Application Support/CDM/bin:/usr/local/munki:/Applications/kitty.app/Contents/MacOS
PS1=\[\e]133;k;start_kitty\a\]\[\e]133;A\a\]\[\e]133;k;end_kitty\a\]\[\033[1;37m\][\[\033[1;33m\]\t \[\033[0;32m\]\u@\H \[\033[0;36m\]\w \[\033[1;37m\]]\n\[\e]133;k;start_secondary_kitty\a\]\[\e]133;A;k=s\a\]\[\e]133;k;end_secondary_kitty\a\]\[\033[1;31m\]$(if [ ! -z "`command -v __git_ps1`" ]; then _GITPS1="`__git_ps1`"; if [ ! -z "${_GITPS1}" ]; then echo -n "±${_GITPS1}"; echo -n ' '; fi; fi)\[\033[0;37m\]$(if [ $SHLVL -gt 1 ]; then echo "⇟$SHLVL"; fi)$ \[\e]133;k;start_suffix_kitty\a\]\[\e[5 q\]\[\e]2;\w\a\]\[\e]133;k;end_suffix_kitty\a\]
__CFBundleIdentifier=net.kovidgoyal.kitty

ls -al ~/.cache/pre-commit

$ ls -al ~/.cache/pre-commit
total 56
drwxr-xr-x@  9 colin  staff    288 Apr  3 14:46 .
drwxr-xr-x   9 colin  staff    288 Apr  3 14:46 ..
-rw-r--r--@  1 colin  staff      0 Apr  3 14:46 .lock
-rw-r--r--@  1 colin  staff    109 Apr  3 14:46 README
-rw-------@  1 colin  staff  20480 Apr  3 14:46 db.db
-rw-r--r--@  1 colin  staff   2676 Apr  3 14:46 pre-commit.log
drwx------@ 30 colin  staff    960 Apr  3 14:46 repofs85lks_
drwx------@  9 colin  staff    288 Apr  3 14:46 repogmqgmb7n
drwx------@ 20 colin  staff    640 Apr  3 14:46 reporuqzcd7b

.pre-commit-config.yaml

$ cat .pre-commit-config.yaml
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
  -   repo: https://github.com/pre-commit/pre-commit-hooks
      rev: v4.2.0
      hooks:
        - id: trailing-whitespace
        - id: end-of-file-fixer
        - id: check-yaml
        - id: check-json
        - id: check-added-large-files
        - id: check-case-conflict
        - id: check-executables-have-shebangs
        - id: check-shebang-scripts-are-executable
        - id: check-symlinks
        - id: check-merge-conflict
        - id: destroyed-symlinks
        - id: check-toml

  - repo: https://github.com/comkieffer/pre-commit-xmllint.git
    rev: 1.0.0
    hooks:
      - id: xmllint

  # keep Makefile tidy and neat
  -   repo: https://github.com/mrtazz/checkmake.git
      # check this for updates once in a while, look for tags
      rev: 4e37f3a6ea00208b3f5bd04eaa0f075068237f18
      hooks:
        -   id: checkmake

I can try. I’ve not used strace before, though.

One thing I’ve noticed on this Linux system is that if I run pre-commit install-hooks, the checkmake hook will install correctly and run fine next time I run git commit.

If I run pre-commit clean and then git commit, pre-commit prepares the hooks and fails with the above error. If I then run pre-commit install-hooks and try to commit again, it works.

What’s the difference in environment between when pre-commit needs to install hooks at commit time versus what happens when install-hooks does its thing?

I’ve run into the same problem, this post actually fixed the issue for me too. So running

Running pre-commit install-hooks for some reason is able to download the go-modules when pre-commit is not possible to do so when just running a normal git commit command

finally a reproduction! thank you this should be easy enough to fix with the git helper

I can try. I’ve not used strace before, though.

One thing I’ve noticed on this Linux system is that if I run pre-commit install-hooks, the checkmake hook will install correctly and run fine next time I run git commit.

If I run pre-commit clean and then git commit, pre-commit prepares the hooks and fails with the above error. If I then run pre-commit install-hooks and try to commit again, it works.

What’s the difference in environment between when pre-commit needs to install hooks at commit time versus what happens when install-hooks does its thing?

I’m running into the same issue while running git commit

  • on macOS Ventura 13.4.1,
  • using pre-commit 3.2.0,
  • and git 2.35.1.

This workaround worked for me: prefix the git commit command with GOFLAGS=-buildvcs=false.