Repository: pre-commit/pre-commit

Issue:
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.

```shell
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

```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.
```


Discussion:
it works fine for me in both 2.21 and 3.0 -- do you have any other `GO` environment variables or other things interfering?
I am not sure what the cause might be.

One thing I have noticed is when I was doing interactive rebase with renaming commit, the pre-commit check installation/initialization succeeded - what comes to my mind - maybe some timeouts?

```
❯ git rebase -i origin/master
[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...
[INFO] Installing environment for https://github.com/adrienverge/yamllint.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
[INFO] Installing environment for https://github.com/Yelp/detect-secrets.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
check for added large files..........................(no files to check)Skipped
check for merge conflicts............................(no files to check)Skipped
detect aws credentials...............................(no files to check)Skipped
detect private key...................................(no files to check)Skipped
fix end of files.....................................(no files to check)Skipped
mixed line ending....................................(no files to check)Skipped
trim trailing whitespace.............................(no files to check)Skipped
KubeLinter...........................................(no files to check)Skipped
yamllint.............................................(no files to check)Skipped
Detect secrets.......................................(no files to check)Skipped
[detached HEAD 57ca14ed] stuff
 Date: Thu Jan 26 09:48:21 2023 +0100
 5 files changed, 67 insertions(+), 12 deletions(-)
Successfully rebased and updated refs/heads/feat/stuff.
```

## Additional information:

Git version:  `2.39.1`

This is my `go env`
```shell
$ go env

GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/.../Library/Caches/go-build"
GOENV="/Users/.../Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/.../go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/.../go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.19.5/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.19.5/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.5"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jh/6dnhwcxn5m592yf4_l1nkr_r0000gn/T/go-build2822682343=/tmp/go-build -gno-record-gcc-switches -fno-common"
```
my guess is the error was needing to upgrade macos CLT or whatever. either way it's working now
I'm facing this error right now on my Linux box while it works perfectly on my macOS box.

```
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/main.py", line 366, in main
    return hook_impl(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/commands/hook_impl.py", line 254, in hook_impl
    return retv | run(config, store, ns)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/commands/run.py", line 437, in run
    install_hook_envs(to_install, store)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/repository.py", line 239, in install_hook_envs
    _hook_install(hook)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/repository.py", line 86, in _hook_install
    lang.install_environment(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/languages/golang.py", line 152, in install_environment
    helpers.run_setup_cmd(prefix, ('go', 'install', './...'), env=env)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/languages/helpers.py", line 49, in run_setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/util.py", line 115, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/home/zedtux/.cache/pre-commit/repo56ywbt73/golangenv-default/.go/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/rs/zerolog v1.26.1
    ...
        go: downloading golang.org/x/text v0.3.6
    go: downloading github.com/mattn/go-isatty v0.0.14
    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'm running Elementary OS 6 (Ubuntu Focal like) and I did install it using `pip`.
can you share the same information as above? -- generally this failure isn't a pre-commit problem and is instead a misconfiguration of `go`
Sure, here it is :

## Additional information:

Git version: `2.25.1`

`go env` fails for me as it is not installed!
yeah I need your config and everything else too
Oops, sorry :

## pre-commit --version

`pre-commit 3.0.4`

## .pre-commit-config.yaml

```yaml
repos:
- repo: https://github.com/antonbabenko/pre-commit-terraform
  rev: v1.77.1 # Get the latest from: https://github.com/antonbabenko/pre-commit-terraform/releases
  hooks:
    - id: terraform_fmt
    - id: terraform_docs
    - id: terraform_tfsec
    - id: terraform_validate
- repo: https://github.com/zricethezav/gitleaks
  rev: v8.15.3
  hooks:
    - id: gitleaks
```

## ~/.cache/pre-commit/pre-commit.log if present

### version information

```
pre-commit version: 3.0.4
git --version: git version 2.25.1
sys.version:
    3.8.10 (default, Nov 14 2022, 12:59:47) 
    [GCC 9.4.0]
sys.executable: /usr/bin/python3
os.name: posix
sys.platform: linux
```

### error information

```
An unexpected error has occurred: CalledProcessError: command: ('/home/zedtux/.cache/pre-commit/repo56ywbt73/golangenv-default/.go/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/rs/zerolog v1.26.1
    go: downloading github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb
    go: downloading github.com/gitleaks/go-gitdiff v0.8.0
    go: downloading github.com/spf13/viper v1.8.1
    go: downloading github.com/spf13/cobra v1.2.1
    go: downloading github.com/charmbracelet/lipgloss v0.5.0
    go: downloading github.com/petar-dambovaliev/aho-corasick v0.0.0-20211021192214-5ab2d9280aa9
    go: downloading github.com/fatih/semgroup v1.2.0
    go: downloading github.com/h2non/filetype v1.1.3
    go: downloading github.com/spf13/pflag v1.0.5
    go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
    go: downloading github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68
    go: downloading github.com/lucasb-eyer/go-colorful v1.2.0
    go: downloading github.com/mattn/go-runewidth v0.0.13
    go: downloading github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0
    go: downloading github.com/fsnotify/fsnotify v1.4.9
    go: downloading github.com/hashicorp/hcl v1.0.0
    go: downloading github.com/magiconair/properties v1.8.5
    go: downloading github.com/mitchellh/mapstructure v1.4.1
    go: downloading github.com/pelletier/go-toml v1.9.3
    go: downloading github.com/spf13/afero v1.6.0
    go: downloading github.com/spf13/cast v1.3.1
    go: downloading github.com/spf13/jwalterweatherman v1.1.0
    go: downloading github.com/subosito/gotenv v1.2.0
    go: downloading gopkg.in/ini.v1 v1.62.0
    go: downloading gopkg.in/yaml.v2 v2.4.0
    go: downloading github.com/rivo/uniseg v0.2.0
    go: downloading golang.org/x/sys v0.0.0-20211110154304-99a53858aa08
    go: downloading golang.org/x/text v0.3.6
    go: downloading github.com/mattn/go-isatty v0.0.14
    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 "/usr/local/lib/python3.8/dist-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/main.py", line 366, in main
    return hook_impl(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/commands/hook_impl.py", line 254, in hook_impl
    return retv | run(config, store, ns)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/commands/run.py", line 437, in run
    install_hook_envs(to_install, store)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/repository.py", line 239, in install_hook_envs
    _hook_install(hook)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/repository.py", line 86, in _hook_install
    lang.install_environment(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/languages/golang.py", line 152, in install_environment
    helpers.run_setup_cmd(prefix, ('go', 'install', './...'), env=env)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/languages/helpers.py", line 49, in run_setup_cmd
    cmd_output_b(*cmd, cwd=prefix.prefix_dir, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/util.py", line 115, in cmd_output_b
    raise CalledProcessError(returncode, cmd, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/home/zedtux/.cache/pre-commit/repo56ywbt73/golangenv-default/.go/bin/go', 'install', './...')
return code: 1
stdout: (none)
stderr:
    go: downloading github.com/rs/zerolog v1.26.1
    go: downloading github.com/lucasjones/reggen v0.0.0-20200904144131-37ba4fa293bb
    go: downloading github.com/gitleaks/go-gitdiff v0.8.0
    go: downloading github.com/spf13/viper v1.8.1
    go: downloading github.com/spf13/cobra v1.2.1
    go: downloading github.com/charmbracelet/lipgloss v0.5.0
    go: downloading github.com/petar-dambovaliev/aho-corasick v0.0.0-20211021192214-5ab2d9280aa9
    go: downloading github.com/fatih/semgroup v1.2.0
    go: downloading github.com/h2non/filetype v1.1.3
    go: downloading github.com/spf13/pflag v1.0.5
    go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
    go: downloading github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68
    go: downloading github.com/lucasb-eyer/go-colorful v1.2.0
    go: downloading github.com/mattn/go-runewidth v0.0.13
    go: downloading github.com/muesli/termenv v0.11.1-0.20220204035834-5ac8409525e0
    go: downloading github.com/fsnotify/fsnotify v1.4.9
    go: downloading github.com/hashicorp/hcl v1.0.0
    go: downloading github.com/magiconair/properties v1.8.5
    go: downloading github.com/mitchellh/mapstructure v1.4.1
    go: downloading github.com/pelletier/go-toml v1.9.3
    go: downloading github.com/spf13/afero v1.6.0
    go: downloading github.com/spf13/cast v1.3.1
    go: downloading github.com/spf13/jwalterweatherman v1.1.0
    go: downloading github.com/subosito/gotenv v1.2.0
    go: downloading gopkg.in/ini.v1 v1.62.0
    go: downloading gopkg.in/yaml.v2 v2.4.0
    go: downloading github.com/rivo/uniseg v0.2.0
    go: downloading golang.org/x/sys v0.0.0-20211110154304-99a53858aa08
    go: downloading golang.org/x/text v0.3.6
    go: downloading github.com/mattn/go-isatty v0.0.14
    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.
```
can you share `env | grep -Ei '(GIT|PRE_COMMIT|GO)' | sort`, your `~/.gitconfig` and `ls -al ~/.cache/pre-commit` ?
## env | grep -Ei '(GIT|PRE_COMMIT|GO)' | sort

```
$ env | grep -Ei '(GIT|PRE_COMMIT|GO)' | sort
TF_VAR_OAUTH2_PASS=[redacted]
```

## ~/.gitconfig

```
 [user]
	name = Guillaume Hain
	email = zedtux@zedroot.org
	signingkey = BC63F4AEB4B5092E3104C289D2B2A8B99474CF36

[color]
	branch = auto
	status = auto
	diff = auto
	ui = always

[alias]
	st = "!git_stash_check; rails_project_cleaner.sh; git status -sb"
	ci = commit
	co = checkout
	restore = checkout HEAD --
	uncommit = reset --soft HEAD^
	l = log --decorate --show-signature
	lg = log --decorate --graph --show-signature
        master = checkout master
        develop = checkout develop
        staging = checkout staging
	cir = "!git_make_a_new_release"
	branches = branch -a
        spull = submodule foreach git pull
	changedfiles = "!git diff --name-only $GIT_DEFAULT_BRANCH `git rev-parse --abbrev-ref HEAD`"
        rmbranches = "!git branch --merged ${GIT_DEFAULT_BRANCH:-master} | grep -v ${GIT_DEFAULT_BRANCH:-master} | xargs git branch -D"
	refreshbranches = remote update origin --prune
[push]
	default = tracking
	followTags = true

[status]
	showUntrackedFiles = all

[pack]
	threads = 2

[core]
	editor = nano
	quotepath = false
[mergetool]
	keepBackup = false
	prompt = false
[branch]
	autosetupmerge = true
[filter "media"]
	clean = git-media-clean %f
	smudge = git-media-smudge %f
[difftool]
	prompt = false
[commit]
	gpgsign = true
[filter "lfs"]
	clean = git-lfs clean %f
	smudge = git-lfs smudge %f
	required = true
[merge]
	tool = meld
[gpg]
	program = gpg
[merge "ours"]
	driver = true
```

## ls -al ~/.cache/pre-commit

```
ls -al ~/.cache/pre-commit
total 48
drwxrwxr-x  4 zedtux zedtux  4096 Feb 15 21:11 .
drwxr-xr-x 26 zedtux zedtux  4096 Feb 15 21:28 ..
drwx------ 10 zedtux zedtux  4096 Feb 15 21:18 repo56ywbt73
drwx------  8 zedtux zedtux  4096 Feb 15 21:10 repovpqakma5
-rw-------  1 zedtux zedtux 20480 Feb 15 21:10 db.db
-rw-rw-r--  1 zedtux zedtux     0 Feb 15 21:10 .lock
-rw-rw-r--  1 zedtux zedtux  5917 Feb 15 21:18 pre-commit.log
-rw-rw-r--  1 zedtux zedtux   109 Feb 15 21:10 README
```
tried reproducing in docker and didn't really get anywhere -- any chance you could strace and see what `git` command go is running and why it fails?
I'm getting this on MacOS so I can't use strace for me is failing on the same package just a slightly different version.

```
    go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
    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.
    error obtaining VCS status: exit status 128
    	Use -buildvcs=false to disable VCS stamping.
```
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](https://github.com/pre-commit/pre-commit/blob/bb49560dc99a65608c8f9161dd71467af163c0d1/pre_commit/languages/golang.py#L152), 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:

* https://github.com/golang/go/issues/49004
* https://github.com/microsoft/CBL-Mariner/issues/3273
* https://www.reddit.com/r/golang/comments/x5e3ld/how_to_set_buildvcsfalse_as_default/

## 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'm encountering this on Linux, too.

```
$ git commit -av
[INFO] Initializing environment for https://github.com/mrtazz/checkmake.git.
[INFO] Initializing environment for https://github.com/executablebooks/mdformat.
[INFO] Initializing environment for https://github.com/executablebooks/mdformat:mdformat-gfm.
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Installing environment for https://github.com/mrtazz/checkmake.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/colin/.cache/pre-commit/repoy46vmwin/golangenv-default/.go/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.
Check the log at /home/colin/.cache/pre-commit/pre-commit.log
```

```
$ pre-commit --version
pre-commit 3.2.2
$ git --version
git version 2.34.1
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy
```
can you strace and figure out why git is mad? 
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?
there shouldn't be a difference -- I haven't been able to reproduce the findings either way
`strace git commit -av` output:

```
access(".git/hooks/pre-commit", X_OK)   = 0
pipe2([3, 5], 0)                        = 0
openat(AT_FDCWD, "/dev/null", O_RDWR|O_CLOEXEC) = 7
fcntl(7, F_GETFD)                       = 0x1 (flags FD_CLOEXEC)
fcntl(7, F_SETFD, FD_CLOEXEC)           = 0
rt_sigprocmask(SIG_SETMASK, ~[RTMIN RT_1], [], 8) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f23925eaa10) = 10579
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
close(5)                                = 0
read(3, "", 8)                          = 0
close(3)                                = 0
close(7)                                = 0
wait4(10579, [INFO] Installing environment for https://github.com/mrtazz/checkmake.git.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('/home/colin/.cache/pre-commit/repoyeyfjm3j/golangenv-default/.go/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.
Check the log at /home/colin/.cache/pre-commit/pre-commit.log
[{WIFEXITED(s) && WEXITSTATUS(s) == 3}], 0, NULL) = 10579
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=10579, si_uid=1000, si_status=3, si_utime=149, si_stime=61} ---
unlink("/home/colin/Source/homebrew-size-analysis/.git/index.lock") = 0
getpid()                                = 10578
exit_group(1)                           = ?
+++ exited with 1 +++
```

but I think strace isn't attaching to the process(es) launched from `.git/hooks/pre-commit`, so I altered that to inject strace:

     exec strace --output pre-commit.strace.log "$INSTALL_PYTHON" -mpre_commit "${ARGS[@]}"

The output log is 22 MB. I'm pretty lost in it with the time I have available right now. I've attached it as a ~2.9 MB gzip. Hopefully I'm not leaking anything in this; this Linux system is actually WSL and there's virtually nothing on it.

[pre-commit.strace.log.gz](https://github.com/pre-commit/pre-commit/files/11223562/pre-commit.strace.log.gz)
I think with `-ff` and `-o` you can get it to follow subprocesses which  might help?
> 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
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`.
I just ran into this. I believe the cause is the fact `go install` is called with a copy of the environment https://github.com/pre-commit/pre-commit/blob/15bd0c7993587dc7d739ac6b1ab939eb9639bc1e/pre_commit/languages/golang.py#L144 which can contain `GIT_INDEX_FILE` when `git commit` is being run. Here's a reproduction using `pre-commit` (tested on `pre-commit 3.3.3`, `go version go1.21.6 linux/amd64`, though I expect the same behaviour for any Go version >= `1.18` when [Go started including VCS info in builds](https://go.dev/doc/go1.18#go-version)):

```bash
repo="$(mktemp --directory)"
git init "$repo"
cd "$repo"
cat <<EOF >.pre-commit-config.yaml
repos:
    # repo doesn't matter, anything using Go
-   repo: https://github.com/segmentio/golines
    rev: v0.10.0
    hooks:
    -   id: golines
EOF
git add .pre-commit-config.yaml
pre-commit install
# setup some fresh caches to ensure we do a full download+build
mkdir gocache gomodcache pre-commit-cache
GOFLAGS='-x' GOCACHE="$PWD/gocache" GOMODCACHE="$PWD/gomodcache" PRE_COMMIT_HOME="$PWD/pre-commit-cache" git commit --all --message 'Install pre-commit'
```

`GOFLAGS='-x'` forces `go` to print commands as it runs them and reports:

```
    <--- SNIP: a bunch of download logs --->
    cd /tmp/tmp.o1rMm1SgXK/pre-commit-cache/repopbyr_tp4
    git status --porcelain
    # cd /tmp/tmp.o1rMm1SgXK/pre-commit-cache/repopbyr_tp4; git status --porcelain
    fatal: unable to read 715dc4303df786fdbed5723d06fcca76ba0c9138
    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.
Check the log at /tmp/tmp.o1rMm1SgXK/pre-commit-cache/pre-commit.log
```

Note the line `fatal: unable to read 715dc4303df786fdbed5723d06fcca76ba0c9138`:  `/tmp/tmp.o1rMm1SgXK/pre-commit-cache/repopbyr_tp4` is the clone of the repo we're trying to build, but `715dc4303df786fdbed5723d06fcca76ba0c9138` is a blob in the repo we're committing in. 

Maybe the env needs to be cleaned with something like https://github.com/pre-commit/pre-commit/blob/15bd0c7993587dc7d739ac6b1ab939eb9639bc1e/pre_commit/git.py#L27 before running `go install`? Or, as others have noted setting the `buildvcs` build flag: `go install -buildvcs=false ./...`

Here's a standalone reproduction, install this under `.git/hooks/pre-commit` and run `go commit -a` with `GOCACHE` and `GOMODCACHE` pointing to some clean caches (like above, so `go` actually tries to build something, and doesn't just reuse the cache):

```bash
#!/usr/bin/env bash

set -o errexit -o pipefail -o nounset

dest="$(mktemp --directory)"
trap 'rm -rf -- "$dest"' EXIT
# ensure GIT_INDEX_FILE is unset during clone, I believe `pre-commit` does this
# otherwise things can fail earlier on, or (confusingly) work fine
env --unset GIT_INDEX_FILE git clone --depth 1 https://github.com/segmentio/golines "$dest"

cd "$dest"
GOFLAGS='-x -v' go install ./...
```

NOTE: I found this didn't reproduce unless the `-a/--all` flag was passed to `git commit`: in this case `GIT_INDEX_FILE` would be an absolute path like `GIT_INDEX_FILE=/tmp/repo/.git/index.lock` but otherwise might be a relative path like: `GIT_INDEX_FILE=.git/index` in which case things can actually work.

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

Resolving patch:
diff --git a/pre_commit/languages/golang.py b/pre_commit/languages/golang.py
--- a/pre_commit/languages/golang.py
+++ b/pre_commit/languages/golang.py
@@ -23,6 +23,7 @@
 from pre_commit.envcontext import envcontext
 from pre_commit.envcontext import PatchesT
 from pre_commit.envcontext import Var
+from pre_commit.git import no_git_env
 from pre_commit.prefix import Prefix
 from pre_commit.util import cmd_output
 from pre_commit.util import rmtree
@@ -141,7 +142,7 @@ def install_environment(
     else:
         gopath = env_dir
 
-    env = dict(os.environ, GOPATH=gopath)
+    env = no_git_env(dict(os.environ, GOPATH=gopath))
     env.pop('GOBIN', None)
     if version != 'system':
         env['GOROOT'] = os.path.join(env_dir, '.go')


Test patch:
diff --git a/tests/languages/golang_test.py b/tests/languages/golang_test.py
--- a/tests/languages/golang_test.py
+++ b/tests/languages/golang_test.py
@@ -7,10 +7,16 @@
 
 import pre_commit.constants as C
 from pre_commit import lang_base
+from pre_commit.commands.install_uninstall import install
 from pre_commit.envcontext import envcontext
 from pre_commit.languages import golang
 from pre_commit.store import _make_local_repo
+from pre_commit.util import cmd_output
+from testing.fixtures import add_config_to_repo
+from testing.fixtures import make_config_from_repo
 from testing.language_helpers import run_language
+from testing.util import cmd_output_mocked_pre_commit_home
+from testing.util import git_commit
 
 
 ACTUAL_GET_DEFAULT_VERSION = golang.get_default_version.__wrapped__
@@ -134,3 +140,28 @@ def test_local_golang_additional_deps(tmp_path):
 def test_golang_hook_still_works_when_gobin_is_set(tmp_path):
     with envcontext((('GOBIN', str(tmp_path.joinpath('gobin'))),)):
         test_golang_system(tmp_path)
+
+
+def test_during_commit_all(tmp_path, tempdir_factory, store, in_git_dir):
+    hook_dir = tmp_path.joinpath('hook')
+    hook_dir.mkdir()
+    _make_hello_world(hook_dir)
+    hook_dir.joinpath('.pre-commit-hooks.yaml').write_text(
+        '-   id: hello-world\n'
+        '    name: hello world\n'
+        '    entry: golang-hello-world\n'
+        '    language: golang\n'
+        '    always_run: true\n',
+    )
+    cmd_output('git', 'init', hook_dir)
+    cmd_output('git', 'add', '.', cwd=hook_dir)
+    git_commit(cwd=hook_dir)
+
+    add_config_to_repo(in_git_dir, make_config_from_repo(hook_dir))
+
+    assert not install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
+
+    git_commit(
+        fn=cmd_output_mocked_pre_commit_home,
+        tempdir_factory=tempdir_factory,
+    )