Last active
March 22, 2017 09:36
-
-
Save guessi/16a9b3c9824c8e547fc054ca13f038bb to your computer and use it in GitHub Desktop.
a simple helper script for mirroring from one to another
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
if [ $# -ne 2 ]; then | |
cat <<-EOF | |
Usage: reposync.sh <src-repo-uri> <target-repo-uri> | |
EOF | |
exit 1 | |
fi | |
SRC=$1 | |
DST=$2 | |
TEMPDIR="$(pwd)/migration" | |
REPOSITORY="$(echo ${1} | cut -d '/' -f 2 | cut -d'.' -f1)" | |
cat <<-EOF | |
==> [INFO] SOURCE: ${SRC} | |
==> [INFO] TARGET: ${DST} | |
==> [INFO] WORKSPACE: ${TEMPDIR}/${REPOSITORY} | |
EOF | |
echo "==> Stage 1: cloning source repository" | |
if [ ! -d "${TEMPDIR}/${REPOSITORY}" ]; then | |
git clone --quiet --mirror $1 ${TEMPDIR}/${REPOSITORY} | |
fi | |
echo | |
pushd ${TEMPDIR}/${REPOSITORY} >/dev/null | |
echo "==> Stage 2: detect repository status" | |
git log --oneline -n 1 >/dev/null | |
echo "==> Stage 3: removing garbage contents" | |
git fetch --all --prune --quiet | |
for ref in $(git show-ref | egrep 'refs/(pull|changes|notes|users)/.*' | awk '{print$2}'); do | |
git update-ref -d ${ref} | |
done | |
echo "==> Stage 4: pushing to target repository" | |
git push --mirror $2 | |
echo | |
popd >/dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment