3 MIRROR_GIT="git://git.planet-lab.org"
5 LOCAL_MIRROR_DIR="/git-mirror"
11 echo "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx $@"
16 echo "[ERROR] xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx $@"
22 COMMAND="$1 &> /dev/null"
29 pushd ${REPO} > /dev/null
34 function merge_all_branches () {
39 pushd $REPO_DIR > /dev/null
40 BRANCHES=$(git branch -r | grep $REMOTE | grep -v HEAD | sed "s/.*\///g" | grep -v master)
43 run "git checkout master" ${REPO_DIR}
44 run "git merge --ff $REMOTE/master" ${REPO_DIR}
45 for BRANCH in $BRANCHES ; do
46 run "git branch $BRANCH $REMOTE/$BRANCH" ${REPO_DIR}
47 run "git checkout $BRANCH" ${REPO_DIR}
48 run "git merge --ff $REMOTE/$BRANCH" ${REPO_DIR}
52 function push_all_branches () {
57 pushd $REPO_DIR > /dev/null
58 BRANCHES=$(git branch -r | grep $REMOTE | grep -v HEAD | sed "s/.*\///g" | grep -v master)
61 run "git push $REMOTE master:master" ${REPO_DIR}
62 for BRANCH in $BRANCHES ; do
63 run "git push $REMOTE $BRANCH:$BRANCH" ${REPO_DIR}
69 NAME=$(basename ${arg} | sed s/.git$//g)
71 REPO_DIR=${LOCAL_MIRROR_DIR}/${NAME}
72 MIRROR_REPO=${MIRROR_GIT}/${GIT_NAME}
73 MASTER_REPO=${MASTER_GIT}/${GIT_NAME}
75 # if there is no remote repository it may be that we only have
76 # the repository locally and don't need to mirror
77 git ls-remote $MIRROR_REPO &> /dev/null
82 msg "pulling from ${NAME}"
83 run "git fetch origin --tags" ${REPO_DIR}
84 run "git fetch origin" ${REPO_DIR}
85 merge_all_branches $NAME origin $REPO_DIR
88 error "Can not fetch from ${MASTER_REPO}"
91 msg "mirroring ${NAME} for the first time"
92 run "git clone ${MIRROR_REPO}" ${LOCAL_MIRROR_DIR}
93 run "git remote add local_master ${MASTER_REPO}" ${REPO_DIR}
96 msg "pushing ${NAME} to local master"
97 run "git fetch local_master --tags" ${REPO_DIR}
98 run "git fetch local_master" ${REPO_DIR}
99 merge_all_branches $NAME local_master $REPO_DIR
102 error "Can not fetch from ${MIRROR_REPO}"
104 run "git push --tags local_master" ${REPO_DIR}
105 push_all_branches $NAME local_master $REPO_DIR
112 while getopts ":hq" opt
120 echo "USAGE: $0 [-q] REPONAME*"
124 echo "Invalid option: -$OPTARG" >&2