尝试在本地提交时预提交导致以下错误

Pre-commit causing the following error when trying to commit locally

我正在做一个项目,需要使用预提交。 在做了一个小的代码更改后,我尝试提交更改(在我的本地 git 存储库中)。我收到以下错误:

dmk@DESKTOP-I1DLS2O:~/Markus$ git commit -m "Removed Grouping#marking_completed?"
[INFO] Installing environment for https://github.com/rubocop/rubocop.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
An unexpected error has occurred: CalledProcessError: command: ('gem', 'build', 'rubocop.gemspec')
return code: 1
expected return code: 0
stdout:
    Executable `ruby` not found
stderr: (none)
Check the log at /home/dmk/.cache/pre-commit/pre-commit.log

这是日志:

版本信息

pre-commit version: 2.19.0
git --version: git version 2.25.1
sys.version:
    3.8.10 (default, Mar 15 2022, 12:22:08) 
    [GCC 9.4.0]
sys.executable: /usr/bin/python3
os.name: posix
sys.platform: linux

错误信息

An unexpected error has occurred: CalledProcessError: command: ('gem', 'build', 'rubocop.gemspec')
return code: 1
expected return code: 0
stdout:
    Executable `ruby` not found
stderr: (none)
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 361, in main
    return hook_impl(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/commands/hook_impl.py", line 238, in hook_impl
    return retv | run(config, store, ns)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/commands/run.py", line 414, in run
    install_hook_envs(to_install, store)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/repository.py", line 79, in _hook_install
    lang.install_environment(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/languages/ruby.py", line 133, in install_environment
    helpers.run_setup_cmd(
  File "/usr/local/lib/python3.8/dist-packages/pre_commit/languages/helpers.py", line 51, 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 146, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('gem', 'build', 'rubocop.gemspec')
return code: 1
expected return code: 0
stdout:
    Executable `ruby` not found
stderr: (none)

其他信息: 我正在做一个 Rails 项目。 我正在使用 WSL 2。 我正在使用 Docker.

如果您需要任何其他信息,请告诉我。

您的 linux 安装似乎没有 ruby 可执行文件(pre-commit 当前需要 language_version 未指定 language: ruby 挂钩)

您可以通过 sudo apt install ruby-dev

在 ubuntu/debian 上安装一个

免责声明:我创建了 pre-commit