简体   繁体   English

Gitpython检查repo克隆

[英]Gitpython check repo cloned

I am working with Django Rest Framework, build some functionality interacts with git repository. 我正在使用Django Rest Framework,构建一些与git repository交互的功能。 I am using gitpython. 我正在使用gitpython。 Now, I used clone_from to clone remote repository. 现在,我使用clone_from来克隆远程存储库。

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

But sometimes it fails with some network connection problems. 但有时它会因某些网络连接问题而失败。 How can I know repo is cloned correctly or not? 我怎么知道repo是否正确克隆?

You can wrap your command in a try, except block 除了块之外,您可以将命令包装在try中

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

Catching a sample exception above. 捕获上面的示例异常。 A full list of exceptions is available at http://gitpython.readthedocs.io/en/stable/reference.html#module-git.exc http://gitpython.readthedocs.io/en/stable/reference.html#module-git.exc上提供了完整的例外列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM