git: retry if http request failed
This is a wrapper around git commands, it recognizes when a command fails and retries
git retry [-v] [-c COUNT] [-d DELAY] [-e] — <git_subcommand>
More information on this can be found here.
You could run a script like this instead of calling git directly.
#!/bin/bash
REALGIT=/usr/bin/git
RETRIES=3
DELAY=10
COUNT=1
while [ $COUNT -lt $RETRIES ]; do
$REALGIT $*
if [ $? -eq 0 ]; then
RETRIES=0
break
fi
let COUNT=$COUNT+1
sleep $DELAY
done
Is there a way to tell git to retry if the http request failed?
No git itself, it does not support natively that feature.
But interestingly enough, the idea of wrapping a git command in order to retry its execution has been done before: see "git-retry
(1) Manual Page ", part of depot_tools, a collection of tools for dealing with Chromium development.
The shell wrapper git-retry
calls the python script git_retry.py
with the following options:
'-v', '--verbose', default=0,
Increase verbosity; can be specified multiple times
'-c', '--retry-count', default=GitRetry.DEFAULT_RETRY_COUNT (5),
Number of times to retry (default=5)
'-d', '--delay', default=GitRetry.DEFAULT_DELAY_SECS (3.0)
Specifies the amount of time (in seconds) to wait between successive retries (default=3 sec.). This can be zero.
'-D', '--delay-factor', default=2
The exponential factor to apply to delays in between successive failures (default=%default). If this is zero, delays will increase linearly. Set this to one to have a constant (non-increasing) delay.
Note: a git clone for a repo with submodule will always try to clone a submodule twice (one retry). See "Is there any way to continue Git clone from the point where it failed?".