admin管理员组

文章数量:1391969

I'm using some pre-commit hooks for Buf to help me check Protobuf files before compiling them to Go:

repos:
  - repo: 
    rev: v4.4.0 # Use the ref you want to point at
    hooks:
      # Git style
      - id: check-added-large-files
        args: ["--maxkb=512"]
      - id: check-merge-conflict
      - id: check-vcs-permalinks
      - id: forbid-new-submodules

      # Common errors
      - id: end-of-file-fixer
      - id: check-yaml
        args: [--allow-multiple-documents]
      - id: check-merge-conflict
      - id: check-executables-have-shebangs

      # Cross platform
      - id: check-case-conflict

  - repo: 
    rev: v0.53.0
    hooks:
      - id: protolint
        files: protos/.

  - repo: 
    rev: 0.23.3
    hooks:
      - id: check-github-workflows

  - repo: 
    rev: v1.50.1
    hooks:
      - id: buf-dep-update
      - id: buf-dep-prune
      - id: buf-breaking
        args: ["--against", ".git/subdir=start/protos"]

I'm not sure why, but when I run this locally, I always get the following error message:

An unexpected error has occurred: AssertionError: For now, pre-commit requires system-installed golang

I can tell this is happening at the Buf pre-commit hook as I can remove it and the process runs properly. However, I do have Go installed already:

> go version
  go version go1.24.1 linux/amd64
> which go
  /usr/local/go/bin/go

Trying this locally:

> which go && pre-commit run
/usr/local/go/bin/go
[INFO] Installing environment for .
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: AssertionError: For now, pre-commit requires system-installed golang
Check the log at /home/{user}/.cache/pre-commit/pre-commit.log

Since go isn't installed in the home directory, I don't see how this wouldn't work. And it does run properly on GitHub. How can I get this pre-commit hook to run properly?

I'm using some pre-commit hooks for Buf to help me check Protobuf files before compiling them to Go:

repos:
  - repo: https://github/pre-commit/pre-commit-hooks
    rev: v4.4.0 # Use the ref you want to point at
    hooks:
      # Git style
      - id: check-added-large-files
        args: ["--maxkb=512"]
      - id: check-merge-conflict
      - id: check-vcs-permalinks
      - id: forbid-new-submodules

      # Common errors
      - id: end-of-file-fixer
      - id: check-yaml
        args: [--allow-multiple-documents]
      - id: check-merge-conflict
      - id: check-executables-have-shebangs

      # Cross platform
      - id: check-case-conflict

  - repo: https://github/yoheimuta/protolint
    rev: v0.53.0
    hooks:
      - id: protolint
        files: protos/.

  - repo: https://github/python-jsonschema/check-jsonschema
    rev: 0.23.3
    hooks:
      - id: check-github-workflows

  - repo: https://github/bufbuild/buf
    rev: v1.50.1
    hooks:
      - id: buf-dep-update
      - id: buf-dep-prune
      - id: buf-breaking
        args: ["--against", ".git/subdir=start/protos"]

I'm not sure why, but when I run this locally, I always get the following error message:

An unexpected error has occurred: AssertionError: For now, pre-commit requires system-installed golang

I can tell this is happening at the Buf pre-commit hook as I can remove it and the process runs properly. However, I do have Go installed already:

> go version
  go version go1.24.1 linux/amd64
> which go
  /usr/local/go/bin/go

Trying this locally:

> which go && pre-commit run
/usr/local/go/bin/go
[INFO] Installing environment for https://github/bufbuild/buf.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: AssertionError: For now, pre-commit requires system-installed golang
Check the log at /home/{user}/.cache/pre-commit/pre-commit.log

Since go isn't installed in the home directory, I don't see how this wouldn't work. And it does run properly on GitHub. How can I get this pre-commit hook to run properly?

Share Improve this question edited Mar 14 at 1:39 Woody1193 asked Mar 13 at 8:57 Woody1193Woody1193 8,0628 gold badges61 silver badges123 bronze badges 2
  • 1 How are you running this hook locally? Can you add which go to the local execution and share the result with us? – Mureinik Commented Mar 13 at 13:16
  • @Mureinik I'm running it by calling pre-commit run – Woody1193 Commented Mar 14 at 1:32
Add a comment  | 

1 Answer 1

Reset to default 3

one of your language: golang hooks sets language_version: ... to some value.

the version of pre-commit you're using is too old to understand language_version: -- you'll need to upgrade to at least version 3.0.0 (released 2023-01-23)


disclaimer: I wrote pre-commit

本文标签: gitbuf precommit expecting systeminstalled go but it isStack Overflow