sourcetree 与 python 挂钩

问题描述 投票:0回答:2

我有一个 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
//...

但是如果我直接从终端提交,钩子就会按预期工作。

有什么建议来修复源树上的提交吗?

python git atlassian-sourcetree gitpython
2个回答
2
投票

尝试将其添加到您的 git hook 文件中:

export PATH=/usr/local/bin:$PATH

查看此 SourceTree 问题


0
投票

最可能的原因是名为 SourceTree 的应用程序不是通过缺少模块的环境启动的。当你使用终端时,很有可能你已经激活了一个python虚拟环境。

  1. 关闭SourceTree
  2. 打开终端
  3. 在终端中激活您在开发项目时使用的虚拟环境(如果您不知道我在说什么,请跳过这一步并希望它能正常工作)
  4. 在命令提示符下启动 SourceTree

现在 SourceTree 正在一个缺少模块的环境下运行,所以一切都会好起来的。

© www.soinside.com 2019 - 2024. All rights reserved.