上传Android代码到gerrit服务器
1. 配置default.xml
default.xml是跟Android代码配套的,可参考google Android源码下的default.xml(.repo/manifests/default.xml)进行修改。
新建仓库all/manifest.git,
ssh -p 29418 admin@192.168.130.10 gerrit create-project --empty-commit all/manifest
clone到本地,
git clone ssh://admin@192.168.130.10:29418/all/manifest.git
配置default.xml,
cd manifest vi default.xml
内容如下,
<?xml version="1.0" encoding="UTF-8"?> <manifest> <remote name="origin" fetch=".." /> <default revision="master" remote="origin" sync-j="8" /> <project path="build" name="platform/build" groups="pdk" > <copyfile src="core/root.mk" dest="Makefile" /> </project> ... ... </manifest>
上传到远程仓库,
git add . git comm -am "add default.xml" git push origin master
2. 创建git仓库
进入Android代码目录,新建脚本文件,
cd src
vi gerrit_create.sh
内容如下:
LOCAL_PATH=`pwd` MANIFEST_XML_FILE=$LOCAL_PATH/../manifest/default.xml USER_NAME="admin" SERVER_IP="192.168.130.10" SERVER_PORT="29418" OUTPUT_PROJECT_LIST_FILE_NAME=$LOCAL_PATH/project_list_name OUTPUT_PROJECT_LIST_FILE_PATH=$LOCAL_PATH/project_list_path function getNameAndPath() { echo > $OUTPUT_PROJECT_LIST_FILE_NAME echo > $OUTPUT_PROJECT_LIST_FILE_PATH while read LINE do command_line=`echo $LINE | grep "<project"` if [ "$command_line" ] then #echo $LINE reposity_name_sec=${LINE#*name=\"} reposity_path_sec=${LINE#*path=\"} if [ "$reposity_name_sec" ] && [ "$reposity_path_sec" ] then reposity_name=${reposity_name_sec%%\"*} reposity_path=${reposity_path_sec%%\"*} echo "$reposity_name" >> $OUTPUT_PROJECT_LIST_FILE_NAME echo "$reposity_path" >> $OUTPUT_PROJECT_LIST_FILE_PATH fi fi done < $MANIFEST_XML_FILE } function creatEmptyGerritProject() { for i in `cat $OUTPUT_PROJECT_LIST_FILE_NAME`; do echo $i echo "ssh -p $SERVER_PORT $USER_NAME@$SERVER_IP gerrit create-project --empty-commit $i" ssh -p $SERVER_PORT $USER_NAME@$SERVER_IP gerrit create-project --empty-commit $i done } function removeFiles() { rm -rf $LOCAL_PATH/project_list_name rm -rf $LOCAL_PATH/project_list_path } getNameAndPath creatEmptyGerritProject removeFiles
运行脚本,创建git仓库,
. gerrit_create.sh
3. 上传代码到远程仓库
新建脚本gerrit_push.sh
vi gerrit_push.sh
内容如下,
LOCAL_PATH=`pwd` MANIFEST_XML_FILE=$LOCAL_PATH/../manifest/default.xml USER_NAME="admin" SERVER_IP="192.168.130.10" SERVER_PORT="29418" function pushLocalToRemote() { while read LINE do cd $LOCAL_PATH command_line=`echo $LINE | grep "<project"` if [ "$command_line" ] then #echo $LINE reposity_name_sec=${LINE#*name=\"} reposity_path_sec=${LINE#*path=\"} if [ "$reposity_name_sec" ] && [ "$reposity_path_sec" ] then reposity_name=${reposity_name_sec%%\"*} reposity_path=${reposity_path_sec%%\"*} src_path=$LOCAL_PATH/$reposity_path if [ -d "$src_path" ]; then cd $src_path echo `pwd` rm -rf .git rm -rf .gitignore git init git remote add origin ssh://$USER_NAME@$SERVER_IP:$SERVER_PORT/$reposity_name.git git pull origin master git add -A . git commit -am "init commit" git push origin master cd - fi fi fi done < $MANIFEST_XML_FILE } pushLocalToRemote
运行脚本,push代码,
. gerrit_push.sh
4. 下载代码
mkdir -p ../des cd ../des repo init -u ssh://admin@192.168.130.10:29418/all/manifest.git repo sync -f -j8
posted on 2017-03-21 18:09 EastJason 阅读(4010) 评论(0) 编辑 收藏 举报