Retry git clone/fetch on errors
A network error may cause failure. Retry it 5 times like we already do with curl and its retry argument. Instead of adding another cache layer only to make it reliable, it seems fitting to make the existing cache layer reliable. Change-Id: Ic319c5b8997741b99f3343cc856a8f012c9a0de7 Signed-off-by: Michal Nasiadka <mnasiadka@gmail.com>
This commit is contained in:

committed by
Michal Nasiadka

parent
5e0f026078
commit
cd70f344c0
@@ -120,7 +120,25 @@ function get_repos_for_element(){
|
||||
|
||||
if [ ! -e "$CACHE_PATH" ] ; then
|
||||
echo "Caching $REPONAME from $REPOLOCATION in $CACHE_PATH"
|
||||
git clone -q $REPOLOCATION $CACHE_PATH.tmp
|
||||
attempt=1
|
||||
success=0
|
||||
max_attempts=5
|
||||
while [[ $success == 0 ]] && [ $attempt -le $max_attempts ]; do
|
||||
set +e
|
||||
git clone -q $REPOLOCATION $CACHE_PATH.tmp
|
||||
if [ $? -eq 0 ]; then
|
||||
success=1
|
||||
else
|
||||
echo "Attempt $attempt failed. Trying again..."
|
||||
rm -rf $CACHE_PATH.tmp
|
||||
attempt=$((attempt + 1))
|
||||
fi
|
||||
set -e
|
||||
done
|
||||
if [ $success != 1 ]; then
|
||||
echo "The git clone command failed after $max_attempts attempts."
|
||||
exit 1
|
||||
fi
|
||||
mv ${CACHE_PATH}{.tmp,}
|
||||
fi
|
||||
|
||||
@@ -139,8 +157,25 @@ function get_repos_for_element(){
|
||||
# not permit arbitrary sha fetching from remote servers.
|
||||
# This is a separate fetch to the prior one as the prior
|
||||
# one will fail when REPOREF is a SHA1.
|
||||
git -C ${CACHE_PATH} fetch -q --prune --update-head-ok $REPOLOCATION \
|
||||
+refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
|
||||
attempt=1
|
||||
success=0
|
||||
max_attempts=5
|
||||
while [[ $success == 0 ]] && [ $attempt -le $max_attempts ]; do
|
||||
set +e
|
||||
git -C $CACHE_PATH fetch -q --prune --update-head-ok \
|
||||
$REPOLOCATION +refs/heads/*:refs/heads/* +refs/tags/*:refs/tags/*
|
||||
if [ $? -eq 0 ]; then
|
||||
success=1
|
||||
else
|
||||
echo "Attempt $attempt failed. Trying again..."
|
||||
attempt=$((attempt + 1))
|
||||
fi
|
||||
set -e
|
||||
done
|
||||
if [ $success != 1 ]; then
|
||||
echo "The command failed after $max_attempts attempts."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
# Ensure that we have a reference to the revision.
|
||||
if [ "$REPOREF" != "*" ] ; then
|
||||
|
Reference in New Issue
Block a user