Home > Software design >  Pre-commit causing the following error when trying to commit locally
Pre-commit causing the following error when trying to commit locally

Time:05-08

I am working on a project and am required to use pre-commit. After making a small code change, I tried to commit the change (in my local git repo). I got the following error:

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

Here is the log:

version information

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

error information

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)

Other information: I am working on a Rails project. I am using WSL 2. I am using Docker.

Please let me know if you require any other information.

CodePudding user response:

it appears that your linux installation does not have a ruby executable (which pre-commit currently requires when language_version is not specified for language: ruby hooks)

you can install one on ubuntu/debian via sudo apt install ruby-dev


disclaimer: I created pre-commit

  • Related