-function mirror () {
- for arg in "$@" ; do
- FAILED=0 # reset previous failure if any
-
- NAME=$(basename ${arg} | sed s/.git$//g)
- GIT_NAME=${NAME}.git
- REPO_DIR=${LOCAL_MIRROR_DIR}/${NAME}
- MIRROR_REPO=${MIRROR_GIT}/${GIT_NAME}
- MASTER_REPO=${MASTER_GIT}/${GIT_NAME}
-
-
- # if there is no remote repository it may be that we only have
- # the repository locally and don't need to mirror
- git ls-remote $MIRROR_REPO &> /dev/null
- if [ $? -eq 0 ]; then
- if [ -d ${REPO_DIR} ]; then
- msg "pulling from ${NAME}"
- run "git fetch origin --tags" ${REPO_DIR}
- run "git fetch origin" ${REPO_DIR}
- merge_all_branches $NAME origin $REPO_DIR
- if [ $? -ne 0 ]; then
- error "git-mirror.sh failed" "Can not fetch from ${MASTER_REPO}" $REPO_DIR
- fi
- else
- msg "mirroring ${NAME} for the first time"
- run "git clone ${MIRROR_REPO}" ${LOCAL_MIRROR_DIR}
- run "git remote add local_master ${MASTER_REPO}" ${REPO_DIR}
- fi
-
- msg "pushing ${NAME} to local master"
- run "git fetch local_master --tags" ${REPO_DIR}
- run "git fetch local_master" ${REPO_DIR}
- merge_all_branches $NAME local_master $REPO_DIR
- if [ $FAILED -ne 0 ]; then
- pushd ${REPO_DIR} > /dev/null
- STATUS_OUT=$(git status)
- popd > /dev/null
- error "git-mirror.sh failed on ${MIRROR_REPO}" "STATUS:\n$STATUS_OUT \n\n------------\n FAILED COMMANDS:\n$FAILED_CMDS" $REPO_DIR
- else
- run "git push --tags local_master" ${REPO_DIR}
- push_all_branches $NAME local_master origin $REPO_DIR
-
- # success, remove previous check file if any
- CHECK_FILE=$REPO_DIR/$NOTIFIED_FILE
- rm -f $CHECK_FILE
- fi
- fi
- done
-}
+function mirror_repo () {
+ local repo=$1; shift
+ FAILED_CMDS=() # reset previous failure if any
+
+ NAME=$(basename ${repo} ".git")
+ GIT_NAME=${NAME}.git
+ REPO_DIR=${LOCAL_MIRROR_DIR}/${NAME}
+ REMOTE_REPO=${REMOTE_GIT}/${GIT_NAME}
+ MASTER_REPO=${MASTER_GIT}/${GIT_NAME}
+
+ # if the local master is a symlink (like /git/vserver-reference.git -> sliceref.git)
+ # then skip it
+ # we use this for either aliases (like vserver-reference and sliceimage) or
+ # for repos managed in other locations (like /git-slave) but where
+ # the symlink is needed so they get served by git-daemon
+ [ -h ${MASTER_REPO} ] && return
+
+ # if there is no remote repository it may be that we only have
+ # the repository locally and don't need to mirror
+ git ls-remote $REMOTE_REPO &> /dev/null || return
+
+ if [ -d ${REPO_DIR} ] ; then
+ msg "pulling from ${NAME}"
+ run ${REPO_DIR} git fetch origin --tags
+ run ${REPO_DIR} git fetch origin
+ merge_all_branches $REPO_DIR $NAME origin
+ if [ -n "$FAILED_CMDS" ]; then
+ # format mail body
+ body="Can not fetch from ${MASTER_REPO}\n\n------------\n FAILED COMMANDS:\n"
+ for line in "${FAILED_CMDS[@]}"; do body="$body$line\n"; done
+ notify $REPO_DIR "git-mirror.sh failed to merge remote with module ${NAME}" "$body"
+ return
+ fi
+ else
+ msg "mirroring ${NAME} for the first time"
+ run ${LOCAL_MIRROR_DIR} git clone ${REMOTE_REPO}
+ run ${REPO_DIR} git remote add local_master ${MASTER_REPO}
+ fi