本Linux shell脚本可以实现从远程服务器将代码更新到本地服务器上,提示开始实现把本地代码上传到远程服务器上(注意:# repo forall -c git push 53lo klink_weitf:klink 前的“#” 去掉 即可上传,53lo 为远程仓库名,klink_weitf为本地自己分支,klink为远程分支(与本地公测分支同名)),同时注意如果有修改没有提交,本脚本不会更新代码,如果代码自己分支与本地公测分支发送冲突,脚本不会上传代码。代码如下:sync.sh
#!/bin/bash
##########################################
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Check status:repo status"
repo status | tee status.log
STATUS=`cat status.log`
for i in $STATUS; do
if [ "$i" == "-m" ];then
break;
fi
done
if [ "$i" != "-m" ];then
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "checkout mtk:repo checkout mtk"
repo checkout mtk
if [ $? -eq 0 ]; then
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Update project files:repo sync"
repo sync
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "checkout klink:repo checkout klink"
repo checkout klink
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Pull code:repo forall -c git pull 53lo klink"
repo forall -c git pull 53lo klink
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "checkout klink_weitf:repo checkout klink_weitf"
repo checkout klink_weitf
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Merge code:repo forall -c git merge klink"
repo forall -c git merge klink
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Check status:repo status"
repo status | tee status.log
STATUS=`cat status.log`
for j in $STATUS
do
# echo $j
if [ "$j" == "-m" ];then
break
fi
done
# if [ "$j" != "-m" ];then
# modified by weitf @20150802
if [ "$j" != "Um" ];then
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Push code:repo forall -c git push 53lo klink_weitf:klink"
# repo forall -c git push 53lo klink_weitf:klink
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Push code:push finish!!!"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "sync finish($(date -d "today" +"%Y.%m.%d %H:%M:%S"))!!!"
else
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Merge error: CONFLICT!!!!($(date -d "today" +"%Y.%m.%d %H:%M:%S"))"
fi
# else
# echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
# echo "error:sync error!!!!($(date -d "today" +"%Y.%m.%d %H:%M:%S"))"
# echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
# echo "checkout klink_weitf:repo checkout klink_weitf"
# repo checkout klink_weitf
# echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
# echo "Check status:repo status"
# repo status
# echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
# echo "Commit error:no commit($(date -d "today" +"%Y.%m.%d %H:%M:%S"))"
fi
else
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "error:sync error!!!!($(date -d "today" +"%Y.%m.%d %H:%M:%S"))"
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "checkout klink_weitf:repo checkout klink_weitf"
repo checkout klink_weitf
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Check status:repo status"
repo status
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Commit error:no commit($(date -d "today" +"%Y.%m.%d %H:%M:%S"))"
fi