Skip to content

Commit

Permalink
Merge pull request #78 from johnbieren/rhtaprel_643
Browse files Browse the repository at this point in the history
feat(RHTAPREL-643): add git function to push with retries
  • Loading branch information
johnbieren authored Oct 31, 2023
2 parents b596085 + 3788c11 commit 6fe50b6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions utils/git-functions
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,43 @@ git_rebase() {
git rebase "${NAME}"/"${REVISION}"
}

git_push_with_retries() {
OPTIONS=$(getopt -l "branch:,retries:,url:" -o "b:r:u:" -a -- "$@")
eval set -- "$OPTIONS"
while true; do
case "$1" in
-b|--branch)
shift
BRANCH=$1
;;
-r|--retries)
shift
RETRIES=$1
;;
-u|--url)
shift
URL=$1
;;
--)
shift
break
;;
esac
shift
done

attempt=0
until [ "$attempt" -gt "$RETRIES" ] ; do
git push "$URL" && break
attempt=$((attempt+1))
git pull --rebase origin $BRANCH
done
if [ "$attempt" -gt "$RETRIES" ] ; then
echo "Max retries exceeded."
return 1
fi
}

git_functions_init() {
# an actual user should be set
[ -z "${GIT_AUTHOR_NAME}" ] || [ -z "${GIT_AUTHOR_EMAIL}" ] && git_functions_usage && return 1
Expand Down

0 comments on commit 6fe50b6

Please sign in to comment.