3 ADMINS="Talip-Baris.Metin@inria.fr"
4 MIRROR_GIT="git://git.planet-lab.org"
6 LOCAL_MIRROR_DIR="/git-mirror"
13 echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx $@"
20 echo "[ERROR] xxxxxxxxxxx $@" | mail -s "$@" $admin
27 COMMAND="$1 &> /dev/null"
34 pushd ${REPO} > /dev/null
43 function run_ignore_errors () {
49 function merge_all_branches () {
54 pushd $REPO_DIR > /dev/null
55 BRANCHES=$(git branch -r | grep $REMOTE | grep -v HEAD | sed "s/.*\///g" | grep -v master)
58 run "git checkout master" ${REPO_DIR}
59 run "git merge --ff $REMOTE/master" ${REPO_DIR}
60 for BRANCH in $BRANCHES ; do
61 run_ignore_errors "git branch $BRANCH $REMOTE/$BRANCH" ${REPO_DIR}
62 run "git checkout $BRANCH" ${REPO_DIR}
63 run "git merge --ff $REMOTE/$BRANCH" ${REPO_DIR}
67 function push_all_branches () {
72 pushd $REPO_DIR > /dev/null
73 BRANCHES=$(git branch -r | grep $REMOTE | grep -v HEAD | sed "s/.*\///g" | grep -v master)
76 run "git push $REMOTE master:master" ${REPO_DIR}
77 for BRANCH in $BRANCHES ; do
78 run "git push $REMOTE $BRANCH:$BRANCH" ${REPO_DIR}
84 FAILED=0 # reset previous failure if any
86 NAME=$(basename ${arg} | sed s/.git$//g)
88 REPO_DIR=${LOCAL_MIRROR_DIR}/${NAME}
89 MIRROR_REPO=${MIRROR_GIT}/${GIT_NAME}
90 MASTER_REPO=${MASTER_GIT}/${GIT_NAME}
93 # if there is no remote repository it may be that we only have
94 # the repository locally and don't need to mirror
95 git ls-remote $MIRROR_REPO &> /dev/null
100 msg "pulling from ${NAME}"
101 run "git fetch origin --tags" ${REPO_DIR}
102 run "git fetch origin" ${REPO_DIR}
103 merge_all_branches $NAME origin $REPO_DIR
106 error "Can not fetch from ${MASTER_REPO}"
109 msg "mirroring ${NAME} for the first time"
110 run "git clone ${MIRROR_REPO}" ${LOCAL_MIRROR_DIR}
111 run "git remote add local_master ${MASTER_REPO}" ${REPO_DIR}
114 msg "pushing ${NAME} to local master"
115 run "git fetch local_master --tags" ${REPO_DIR}
116 run "git fetch local_master" ${REPO_DIR}
117 merge_all_branches $NAME local_master $REPO_DIR
120 error "git-mirror.sh failed on ${MIRROR_REPO}"
122 run "git push --tags local_master" ${REPO_DIR}
123 push_all_branches $NAME local_master $REPO_DIR
130 while getopts ":hq" opt
138 echo "USAGE: $0 [-q] REPONAME*"
142 echo "Invalid option: -$OPTARG" >&2