当用户不是 Windows 11 上克隆回购的所有者时从 gitpython 检索 SHA?

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

我正在使用 gitpython 库在 Windows 11 Enterprise PC 上执行期间获取 Python 代码的 SHA。当我克隆 repo 时,它工作正常。当另一个用户尝试运行代码时,它会失败,除非他们首先在命令行输入“git config --global --add safe.directory”。如果该用户不是 PC 上的管理员,则他们每次登录时都必须在命令行中输入该 git config 命令。

有没有办法在执行时可靠地获取 Python 代码的 SHA,而不管用户是否登录?

这是我用来获取 git SHA 的函数:

import git # note gitpython is what needs to be installed
def gitsha() -> str:
    try:
        repo = git.Repo(search_parent_directories=True)
        sha = repo.head.object.hexsha
        return sha[-8:]
    except:
        return "ERROR"
python windows git gitpython
© www.soinside.com 2019 - 2024. All rights reserved.