上传Android代码到gerrit服务器

1. 配置default.xml

default.xml是跟Android代码配套的,可参考google Android源码下的default.xml(.repo/manifests/default.xml)进行修改。

新建仓库all/manifest.git,

1
ssh -p 29418 [email protected] gerrit create-project --empty-commit all/manifest

clone到本地,

1
git clone ssh: //[email protected]:29418/all/manifest.git

配置default.xml,

1
2
cd manifest
vi  default .xml

内容如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?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>

上传到远程仓库,

1
2
3
git add .
git comm -am  "add default.xml"
git push origin master

 

2. 创建git仓库

进入Android代码目录,新建脚本文件,

1
cd src<br>vi gerrit_create.sh

内容如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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仓库,

1
. gerrit_create.sh

 

3. 上传代码到远程仓库

新建脚本gerrit_push.sh

1
vi gerrit_push.sh

内容如下,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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代码,

1
. gerrit_push.sh

 

4. 下载代码

1
2
3
4
mkdir -p ../des
cd ../des
repo init -u ssh: //[email protected]:29418/all/manifest.git
repo sync -f -j8

猜你喜欢

转载自blog.csdn.net/u013463707/article/details/79551657