我认为这是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
运行succesfullypre-commit install
来提交、分支等等)(说安装程序是successful)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
。
我想我的问题是,是否有一种方法可以在wsl中使用vscode git,还是必须使用windows?
发布于 2021-03-02 15:19:50
好的!
因此,这纯粹是一个vscode / wsl集成问题,与pre-commit
无关。
这是由于vscode使用windows git,而我在wsl
上安装了预提交和所有工具。
因此,您可以通过使用扩展名: VSCode使wsl - remote
使用WSL git repos和应用程序。
您可能也可以用settings.json
更新git.path:
,但我还没有测试过!
https://stackoverflow.com/questions/66441021
复制相似问题