python - 阻止 GitPython 在尝试克隆不存在的远程存储库时询问凭据

标签 python gitpython

在下面的程序片段中,我从远程位置克隆了一个现有的存储库,它工作正常。

然后我尝试克隆一个不存在的存储库,这次调用 git.Repo.clone_from() 从键盘请求名称和密码。

在我的应用程序中,等待键盘输入时发生阻塞是非常不可取的,因此如果存储库不存在,我希望调用 git.Repo.clone_from() 来抛出异常。

有什么方法可以导致这种情况发生,或者在我尝试克隆它之前以某种方式检测现有 URL 上是否存在 git 存储库?

import git, shutil

DIRECTORY = '/tmp/clone'


def clone(url):
    print(url)
    shutil.rmtree(DIRECTORY, ignore_errors=True)
    git.Repo.clone_from(url=url, to_path=DIRECTORY, b='master')


clone('https://github.com/ManiacalLabs/BiblioPixelAnimations.git/')
clone('https://github.com/ManiacalLabs/NONEXISTENT.git/')

最佳答案

输入空的用户名和密码应该可以解决问题

clone('https://:@github.com/ManiacalLabs/BiblioPixelAnimations.git/')
clone('https://:@github.com/ManiacalLabs/NONEXISTENT.git/')

请注意,github.com 之前有 :@

关于python - 阻止 GitPython 在尝试克隆不存在的远程存储库时询问凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44482990/

相关文章:

python - 从 UTC 偏移获取时区缩写

python-3.x - Python git 包获取标签并提交

python - GitPython:确定在特定提交中删除的文件

python - 使用 GitPython,我该怎么做 git submodule update --init

python - 在python中找不到git可执行文件

python - 如何为 GitPython 克隆/pull 函数编写单元测试?

python - unittest 将变量作为参数传递

python - 如何使用 Opencv 模糊/羽化图像中对象的边缘?

python - 如何在 python 中呈现 HTML?

python - 列表索引必须不是列表