如何处理gitpython克隆异常?

时间:2016-03-14 02:04:04

标签: python git gitpython

我正在尝试使用GitPython编写批处理克隆脚本,但是我找不到一个有效的hanlding示例,例如git url not exsits,download interupt等。

我怎么能真正做到这一点?

我现有的代码:

giturl = 'https://github.com/'+username+'/'+hwName+'.git'
targeturl = os.path.join(hwfolder,username+'-'+hwName)
try:
    repo = Repo.clone_from(giturl, targeturl, branch='master')
except:
    #git url not reachable
    #download interupt
    #target local path problem

1 个答案:

答案 0 :(得分:1)

For starters

  

exception git.exc.GitError

     

所有包例外的基类

然后,谁说你来处理所有或任何例外?你只能合理地处理那些你可以做一些聪明的事情。底层git和TCP堆栈已经足够智能,可以处理不可靠连接等瞬态问题,因此如果失败,您通常不能再次尝试,希望这次碰巧正常工作。

出于批处理作业的目的,只需向上游传播错误,以便脚本正常失败。例如。在.bat文件中,您需要编写类似<command> || exit 1的内容,以便脚本在出错时终止而不是盲目地继续。

现在,在你的3个具体案例中:

相关问题