首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >预提交错误:无法生成..git/hooks/预提交:没有这样的文件或目录

预提交错误:无法生成..git/hooks/预提交:没有这样的文件或目录
EN

Stack Overflow用户
提问于 2021-03-02 14:10:39
回答 2查看 1.2K关注 0票数 2

我认为这是Windows/WSL/Linux的问题。当我安装预提交并尝试提交时,任何能够提供帮助的人都会得到错误:

代码语言:javascript
运行
复制
> 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运行succesfully
  • pre-commit install来提交、分支等等)(说安装程序是successful)
  • python3安装并在wsl

上工作)

.git中,我可以看到钩子文件夹和预提交文件,如下所示:

代码语言:javascript
运行
复制
#!/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?

EN

Stack Overflow用户

发布于 2021-03-02 15:19:50

好的!

因此,这纯粹是一个vscode / wsl集成问题,与pre-commit无关。

这是由于vscode使用windows git,而我在wsl上安装了预提交和所有工具。

因此,您可以通过使用扩展名: VSCode使wsl - remote使用WSL git repos和应用程序。

您可能也可以用settings.json更新git.path:,但我还没有测试过!

票数 0
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66441021

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档