【发布时间】:2019-03-25 23:24:42
【问题描述】:
使用 Python 和 GitPython,以及来自不同用户的 git 存储库列表,我需要检查存储库是否存在以及它是否是公共的。
考虑到这一点并考虑到 GitHub,如果它要求提供用户名和密码,我知道该存储库超出了我的标准。因此,我可以忽略它。
import git
class User():
def __init__(self, a, b, c):
self.name = a
self.git_user = b
self.git_repos = c
user = User('John', 'john1234', 'fake_one')
try:
git.Repo.clone_from(f'https://github.com/{user.git_user}/' + \
f'{user.git_repos}.git', f'temp/{user.name}/')
except git.exc.GitError:
print(f'ERROR! {user.name}: {user.git_user}/{user.git_repos} does not exist')
此代码有效,到目前为止,当存储库未作为公共存储库时,我使用任何用户名和相应的密码(包括空密码)输入。有没有办法忽略(通过发送空字符串)或捕获(一些例外?)用户名/密码的东西?
请注意,如果我可以检查(公共)存储库的存在,我可以使用此信息来防止不适当的“克隆”...
【问题讨论】: