Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- # Time-stamp: <2020-07-20 08:35:15 dhruva>
- #------------------------------------------------------------------------------
- # git repository mirroring based on pre-receive hook
- #
- # Inspired by:
- # https://docs.gitlab.com/ee/user/project/repository/repository_mirroring.html
- #------------------------------------------------------------------------------
- set -e
- # Circumvent push to mirror from quarantine directory
- unset GIT_QUARANTINE_PATH
- error=0
- # Perfrom rollback if previous failed to ensure mirror and primary are in-sync
- function rollback()
- {
- if [ -f ./rollback.sh ]; then
- echo "executing rollback"
- chmod +x ./rollback.sh
- ./rollback.sh
- rm -f rollback.sh
- fi
- }
- # Recover from failed previous push
- rollback
- # Disable bailing on error since we want to rollback
- set +e
- while read oldrev newrev refname; do
- mirror_cmd="git push --quiet --force ../mirror.bare ${newrev}:${refname}"
- echo ${mirror_cmd} >> rollback.sh
- eval ${mirror_cmd} 2>&1
- error=$?
- if [ ${error} != 0 ]; then
- echo "failed to mirror repository, will attempt rollback"
- break
- fi
- done < "${1:-/dev/stdin}"
- # Restore bailing on error since we want to preserve rollback file on error
- set -e
- if [ ${error} != 0 ]; then
- rollback
- fi
- rm -f rollback.sh
- exit ${error}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement