running pre-commit python package in Windows gives ExecutableNotFoundError: Executable `/bin/sh`
running pre-commit python package in Windows gives ExecutableNotFoundError: Executable `/bin/sh`
我正在处理一个项目,其中 pre-commit==2.15.0
被添加到 python 需求文件中。我安装了要求。现在,当我尝试执行 git commit
时,出现以下错误:
An unexpected error has occurred: ExecutableNotFoundError: Executable `/bin/sh` not found
Check the log at C:\Users\username\.cache\pre-commit\pre-commit.log
在我的预提交日志中我有:
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
我在 Windows 工作,我的队友在 Mac 上工作。
看起来 precommit 正在尝试引用不在 Windows 中的 /bin/sh
脚本。我如何让这个预提交工作?
您之前的 git 挂钩使用 non-portable shebang (#!/bin/sh
)(在您的情况下,此文件将位于 .git/hooks/pre-commit.legacy
-- 最初 .git/hooks/pre-commit
)
如果您调整工具以使用 #!/usr/bin/env sh
那么 pre-commit 将能够 运行 它(即使在 windows 上)
或者,如果您不想在迁移模式下使用 pre-commit
运行 pre-commit install --force
您还在使用 pre-commit
的过时版本,这可能会导致您遇到问题 - 所以我建议您进行升级
免责声明:我创建了 pre-commit
我正在处理一个项目,其中 pre-commit==2.15.0
被添加到 python 需求文件中。我安装了要求。现在,当我尝试执行 git commit
时,出现以下错误:
An unexpected error has occurred: ExecutableNotFoundError: Executable `/bin/sh` not found
Check the log at C:\Users\username\.cache\pre-commit\pre-commit.log
在我的预提交日志中我有:
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
我在 Windows 工作,我的队友在 Mac 上工作。
看起来 precommit 正在尝试引用不在 Windows 中的 /bin/sh
脚本。我如何让这个预提交工作?
您之前的 git 挂钩使用 non-portable shebang (#!/bin/sh
)(在您的情况下,此文件将位于 .git/hooks/pre-commit.legacy
-- 最初 .git/hooks/pre-commit
)
如果您调整工具以使用 #!/usr/bin/env sh
那么 pre-commit 将能够 运行 它(即使在 windows 上)
或者,如果您不想在迁移模式下使用 pre-commit
运行 pre-commit install --force
您还在使用 pre-commit
的过时版本,这可能会导致您遇到问题 - 所以我建议您进行升级
免责声明:我创建了 pre-commit