@@ -260,6 +260,25 @@ execute() {
260
260
fi
261
261
}
262
262
263
+ retry () {
264
+ local tries=" $1 " n=" $1 " pause=2
265
+ shift
266
+ if ! " $@ "
267
+ then
268
+ while [[ $(( -- n)) -gt 0 ]]
269
+ do
270
+ warn " $( printf " Trying again in %d seconds: %s" " ${pause} " " $( shell_join " $@ " ) " ) "
271
+ sleep " ${pause} "
272
+ (( pause *= 2 ))
273
+ if " $@ "
274
+ then
275
+ return
276
+ fi
277
+ done
278
+ abort " $( printf " Failed %d times doing: %s" " ${tries} " " $( shell_join " $@ " ) " ) "
279
+ fi
280
+ }
281
+
263
282
execute_sudo () {
264
283
local -a args=(" $@ " )
265
284
if [[ " ${EUID:- ${UID} } " != " 0" ]] && have_sudo_access
@@ -939,8 +958,8 @@ ohai "Downloading and installing Homebrew..."
939
958
else
940
959
quiet_progress=(" --quiet" )
941
960
fi
942
- execute " ${USABLE_GIT} " " fetch" " ${quiet_progress[@]} " " --force" " origin"
943
- execute " ${USABLE_GIT} " " fetch" " ${quiet_progress[@]} " " --force" " --tags" " origin"
961
+ retry 5 " ${USABLE_GIT} " " fetch" " ${quiet_progress[@]} " " --force" " origin"
962
+ retry 5 " ${USABLE_GIT} " " fetch" " ${quiet_progress[@]} " " --force" " --tags" " origin"
944
963
945
964
execute " ${USABLE_GIT} " " remote" " set-head" " origin" " --auto" > /dev/null
946
965
@@ -975,7 +994,7 @@ ohai "Downloading and installing Homebrew..."
975
994
execute " ${USABLE_GIT} " " config" " remote.origin.fetch" " +refs/heads/*:refs/remotes/origin/*"
976
995
execute " ${USABLE_GIT} " " config" " --bool" " core.autocrlf" " false"
977
996
execute " ${USABLE_GIT} " " config" " --bool" " core.symlinks" " true"
978
- execute " ${USABLE_GIT} " " fetch" " --force" " ${quiet_progress[@]} " \
997
+ retry 5 " ${USABLE_GIT} " " fetch" " --force" " ${quiet_progress[@]} " \
979
998
" origin" " refs/heads/master:refs/remotes/origin/master"
980
999
execute " ${USABLE_GIT} " " remote" " set-head" " origin" " --auto" > /dev/null
981
1000
execute " ${USABLE_GIT} " " reset" " --hard" " origin/master"
0 commit comments