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

Tom*_*rly 2 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/')
Run Code Online (Sandbox Code Playgroud)

Shr*_*yak 5

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

clone('https://:@github.com/ManiacalLabs/BiblioPixelAnimations.git/')
clone('https://:@github.com/ManiacalLabs/NONEXISTENT.git/')
Run Code Online (Sandbox Code Playgroud)

:@注意前面有github.com