Skip to content

Commit 112ca76

Browse files
authored
Merge pull request #938 from gromgit/retry-git-fetch
2 parents 8ad7a47 + deb02e2 commit 112ca76

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

install.sh

+22-3
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,25 @@ execute() {
260260
fi
261261
}
262262

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+
263282
execute_sudo() {
264283
local -a args=("$@")
265284
if [[ "${EUID:-${UID}}" != "0" ]] && have_sudo_access
@@ -939,8 +958,8 @@ ohai "Downloading and installing Homebrew..."
939958
else
940959
quiet_progress=("--quiet")
941960
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"
944963

945964
execute "${USABLE_GIT}" "remote" "set-head" "origin" "--auto" >/dev/null
946965

@@ -975,7 +994,7 @@ ohai "Downloading and installing Homebrew..."
975994
execute "${USABLE_GIT}" "config" "remote.origin.fetch" "+refs/heads/*:refs/remotes/origin/*"
976995
execute "${USABLE_GIT}" "config" "--bool" "core.autocrlf" "false"
977996
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[@]}" \
979998
"origin" "refs/heads/master:refs/remotes/origin/master"
980999
execute "${USABLE_GIT}" "remote" "set-head" "origin" "--auto" >/dev/null
9811000
execute "${USABLE_GIT}" "reset" "--hard" "origin/master"

0 commit comments

Comments
 (0)