我有一个 git 钩子,“commit-msg”
它看起来像:
#!/bin/sh
python .git/hooks/Foo.py
在我的 Foo.py 中
我有:
import git
# doing some stuff based on git (evaluating latest changes)
当我使用 sourcetree 提交时,如果无法运行挂钩(它也不会提交)
//...
Traceback (most recent call last):
File ".git/hooks/Foo.py", line 2, in <module>
import git
ImportError: No module named git
//...
但是如果我直接从终端提交,钩子就会按预期工作。
有什么建议来修复源树上的提交吗?
最可能的原因是名为 SourceTree 的应用程序不是通过缺少模块的环境启动的。当你使用终端时,很有可能你已经激活了一个python虚拟环境。
现在 SourceTree 正在一个缺少模块的环境下运行,所以一切都会好起来的。