mongo/evergreen/retry_git.sh
Zack Winter 7ccc14bf91 SERVER-101034 Use rules_lint shfmt formatter (#38448)
GitOrigin-RevId: e8ef1ba2000e12fa2cd5a115a9ceeab92332e938
2025-07-16 01:55:34 +00:00

31 lines
564 B
Bash
Executable File

#!/usr/bin/env bash
#
# Description:
# This executes a git command with a retry. Helpful to retry commands
# like fetch in cases where there is flaky networking.
#
# Usage:
# retry_git.sh <args...>
#
REALGIT=$(which git)
RETRIES=5
DELAY=2
COUNT=0
while [ $COUNT -lt $RETRIES ]; do
"$REALGIT" "$@"
CODE=$?
if [ $CODE -eq 0 ]; then
RETRIES=0
break
fi
((COUNT = COUNT + 1))
if [ $COUNT -lt $RETRIES ]; then
echo "Git command failed, retrying in $DELAY seconds..." >&2
fi
sleep $DELAY
done
exit "$CODE"