1

I am working on a project where pre-commit==2.15.0 was added to the python requirements file. I installed the requirements. Now when I try to do a git commit I get the following error:

An unexpected error has occurred: ExecutableNotFoundError: Executable `/bin/sh` not found
Check the log at C:\Users\username\.cache\pre-commit\pre-commit.log

In my pre-commit log I have:

pre-commit version: 2.15.0
sys.version:
    3.9.0 (tags/v3.9.0:9cf6752, Oct  5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)]
sys.executable: c:\users\username\appdata\local\programs\python\python39\python.exe
os.name: nt
sys.platform: win32

Traceback (most recent call last):
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\error_handler.py", line 65, in error_handler
    yield
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\main.py", line 368, in main
    return hook_impl(
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\commands\hook_impl.py", line 231, in hook_impl
    retv, stdin = _run_legacy(hook_type, hook_dir, args)
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\commands\hook_impl.py", line 42, in _run_legacy
    cmd = normalize_cmd((legacy_hook, *args))
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\parse_shebang.py", line 82, in normalize_cmd
    exe = normexe(cmd[0])
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\parse_shebang.py", line 61, in normexe
    _error('not found')
  File "c:\users\username\appdata\local\programs\python\python39\lib\site-packages\pre_commit\parse_shebang.py", line 51, in _error
    raise ExecutableNotFoundError(f'Executable `{orig}` {msg}')
pre_commit.parse_shebang.ExecutableNotFoundError: Executable `/bin/sh` not found

I work in Windows where my teammates work on Macs.

It looks like precommit is trying to reference the /bin/sh script which is not in Windows. How do I get this precommit working?

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
afriedman111
  • 1,925
  • 4
  • 25
  • 42

1 Answers1

4

your previous git hook is using a non-portable shebang (#!/bin/sh) (in your case this file will be located at .git/hooks/pre-commit.legacy -- originally .git/hooks/pre-commit)

if you adjust the tool to use #!/usr/bin/env sh then pre-commit will be able to run it (even on windows)

alternatively, if you don't want to use pre-commit in migration mode run pre-commit install --force

you're also using an outdated version of pre-commit which may be contributing to your issues -- so I'd recommend upgrading that was well


disclaimer: I created pre-commit

anthony sottile
  • 61,815
  • 15
  • 148
  • 207
  • Hi @anthony-sottile, we are using 2.20.0, in 2022 dec we are seeing the similar issue. While running pre-commit it says Executable '/bin/sh' not found. We have tried above solution, I am wondering is there a new solution here? – Piyush Saxena Dec 13 '22 at 14:24
  • if it says `/bin/sh` and you have changed it to `/usr/bin/env sh` then you haven't changed all of them / in the right spot -- keep looking – anthony sottile Dec 13 '22 at 17:03