Gitpython检查repo克隆

时间:2017-08-03 03:48:55

标签: python django gitpython

我正在使用Django Rest Framework,构建一些与git repository交互的功能。 我正在使用gitpython。 现在,我使用clone_from来克隆远程存储库。

repo = Repo.clone_from("REMOTE_REPOSITORY", "LOCAL_PATH")

但有时它会因某些网络连接问题而失败。 我怎么知道repo是否正确克隆?

1 个答案:

答案 0 :(得分:2)

您可以尝试将命令包装在块中,除了块

try: repo = Repo.clone_from("REMOTE_REPOSITORY", "LOCAL_PATH") except git.exc.InvalidGitRepositoryError: ....

捕获上面的示例异常。 http://gitpython.readthedocs.io/en/stable/reference.html#module-git.exc

提供完整的例外列表
相关问题