I'm trying to write a batch clone script with GitPython, however I can't find a valid example of hanlding such as git url not exsits, download interupt etc.
How could I actually do this?
my exsiting code:
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
For starters,
exception git.exc.GitError
Base class for all package exceptions
Then, who said you have to handle all, or any exceptions? You can only reasonably handle those that you can do something intelligent about. The underlying git
and the TCP stack are already smart enough to handle transient problems like an unreliable connection, so if it failed, you can't, as a rule, just try again and hope it happens to work this time.
For the purpose of a batch job, just propagate the error upstream so that your script fails gracefully. E.g. in a .bat
file, you need to write something like <command> || exit 1
for the script to terminate upon error rather than continue blindly.
Now, of your 3 specific cases:
git
fail, all of those cases yield GitCommandError
NoSuchPathError
is only ever raised on Repo
initialization if the path to the local repo doesn't existIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With