[英]Pre-commit error: cannot spawn .git/hooks/pre-commit: No such file or directory
我認為這是一個 Windows/WSL/Linux 問題。 任何人都能夠提供幫助,因為當我安裝預提交並嘗試提交時,我得到了錯誤:
> git -c user.useConfigOnly=true commit --quiet --allow-empty-message --file -
error: cannot spawn .git/hooks/pre-commit: No such file or directory
所有軟件和操作都在wsl2
或 vscode 終端(連接到 wsl)上進行
git clone
(我可以從 vscode 提交、分支等)pre-commit run -a
運行成功pre-commit install
(表示安裝成功)python3
已安裝並在wsl
上工作查看.git
我可以看到鈎子文件夾和下面的預提交文件:
#!/home/linuxbrew/.linuxbrew/opt/pre-commit/libexec/bin/python3
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03
import os
import sys
# we try our best, but the shebang of this script is difficult to determine:
# - macos doesn't ship with python3
# - windows executables are almost always `python.exe`
# therefore we continue to support python2 for this small script
if sys.version_info < (3, 3):
from distutils.spawn import find_executable as which
else:
from shutil import which
# work around https://github.com/Homebrew/homebrew-core/issues/30445
os.environ.pop('__PYVENV_LAUNCHER__', None)
# start templated
INSTALL_PYTHON = '/home/linuxbrew/.linuxbrew/opt/pre-commit/libexec/bin/python3'
ARGS = ['hook-impl', '--config=.pre-commit-config.yaml', '--hook-type=pre-commit']
# end templated
ARGS.extend(('--hook-dir', os.path.realpath(os.path.dirname(__file__))))
ARGS.append('--')
ARGS.extend(sys.argv[1:])
DNE = '`pre-commit` not found. Did you forget to activate your virtualenv?'
if os.access(INSTALL_PYTHON, os.X_OK):
CMD = [INSTALL_PYTHON, '-mpre_commit']
elif which('pre-commit'):
CMD = ['pre-commit']
else:
raise SystemExit(DNE)
CMD.extend(ARGS)
if sys.platform == 'win32': # https://bugs.python.org/issue19124
import subprocess
if sys.version_info < (3, 7): # https://bugs.python.org/issue25942
raise SystemExit(subprocess.Popen(CMD).wait())
else:
raise SystemExit(subprocess.call(CMD))
else:
os.execvp(CMD[0], CMD)
這是一個 VSCode 問題.. 進行手動 vscode 提交使用 windows git,因此在 windows 中查找 python3。如果我使用 wsl 終端並運行 git 命令,它們會工作並使用pre-commit
猜猜我的問題是,有沒有辦法將 vscode git 與 wsl 一起使用,還是必須使用 windows?
@Staggerlee011,查看您的腳本,您似乎缺少腳本頂部的#!/bin/sh
。 將此添加到我的預提交腳本,保存並運行提交成功。 老實說,我不知道這可能是解決方案,因為它看起來像一條評論,但確實如此。 不過仔細想想,似乎Git識別並處理了它。
好的!
所以這純粹是一個 vscode / wsl 集成問題,與pre-commit
無關。
它是由使用 windows git 的 vscode 引起的,而我在wsl
上安裝了 pre-commit 和所有工具。
因此,您可以通過使用擴展名讓 VSCode 使用 WSL git 存儲庫和應用程序: wsl - remote
您也許還可以使用git.path:
更新settings.json
:但我還沒有測試過!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.