上传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

 

转载于:https://www.cnblogs.com/eastnapoleon/p/6595952.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值