简体   繁体   中英

Gitpython check repo cloned

I am working with Django Rest Framework, build some functionality interacts with git repository. I am using gitpython. Now, I used clone_from to clone remote repository.

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?

You can wrap your command in a try, except block

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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