git repository mirror shell, ssh must be synced to both repositories first.
This file contains 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
CODING_URL=git@e.coding.net:xiangzhitech/ | |
GITLAB_URL=git@xiangzhi.iask.in: | |
coding_repos=(songdujingdian/sdx.git wx-open-platform/wx-api.git) | |
gitlab_repos=(songdujingdian/sdx.git xqnet/mp-assistant.git) | |
sync_branch=(dev dev) | |
WORK_DIR=~ | |
if [ ! -d "repository" ]; then | |
mkdir repository | |
fi | |
echo `date` - Start job | |
for((i=0; i < ${#coding_repos[@]}; i++)); do | |
cd ${WORK_DIR} | |
repo=${coding_repos[i]##*/} | |
echo start sync $repo | |
if [ ! -d "repository/${repo}" ]; then | |
echo "clone .." | |
if [ ${sync_branch[i]} == "mirror" ];then | |
git clone --mirror ${CODING_URL}${coding_repos[i]} repository/${repo} | |
else | |
git clone ${CODING_URL}${coding_repos[i]} repository/${repo} | |
fi | |
fi | |
cd repository/${repo} | |
has_remote=`git remote|grep target` | |
if [ -z $has_remote ]; then | |
echo "add remote target .." | |
if [ ${sync_branch[i]} == "mirror" ];then | |
git remote add --mirror=push target ${GITLAB_URL}${gitlab_repos[i]} | |
else | |
git remote add target ${GITLAB_URL}${gitlab_repos[i]} | |
fi | |
fi | |
echo 'fetch ..' | |
git fetch --prune origin | |
if [ ${sync_branch[i]} == "mirror" ];then | |
echo 'push --mirror ..' | |
git push --mirror target | |
else | |
echo 'push to branch ..' | |
if [ `git symbolic-ref --short -q HEAD` != ${sync_branch[i]} ]; then | |
git checkout ${sync_branch[i]} | |
fi | |
git merge origin/${sync_branch[i]} | |
git push -f target ${sync_branch[i]} | |
fi | |
done | |
echo `date` - Done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment