在Gerrit上建立repo代码库

MuYusen 于 2023-07-27 发布 本文总阅读量

在Gerrit上建立repo代码库

像AOSP和Automotive的仓库一般是使用repo管理的多库形式,所以当项目开始时,我们需要将我们的代码推到Gerrit服务器上。

一般有两种方法:一种是直接将代码镜像下载或者复制到Gerrit服务器的git目录下面,另一种是下载一套源码,然后git push到Gerrit上的指定仓库的特定分支。

为了能统一控制权限,建议在Gerrit服务器上先建立个父项目(EX:code),并在git目录下建一个code目录。

以下详述两种方法和基本命令,以AGL代码为例。

repo mirror 方式

下载mirror 格式代码

repo init 命令后面加上 –mirror 参数

repo init -b <<branch name>> -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo --mirror
repo sync

gerrit flush-caches

mirror代码下载之后,在Gerrit web上还看不到这些仓库,需要清一下缓存让Gerrit服务加载到这些仓库。

ssh -p 29418 review.example.com gerrit flush-caches --all

修改权限

使用repo forall 命令批量设置仓库父项目,方便权限控制。

repo forall -c 'echo $REPO_PROJECT;ssh -p 29418 review.example.com gerrit set-project-parent --parent code code/$REPO_PROJECT;'

优缺点

源代码 push 方式

下载源代码

    repo init -b <<branch name>> -u https://gerrit.automotivelinux.org/gerrit/AGL/AGL-repo
    repo sync

使用repo forall 命令在Gerrit上新建仓库

repo forall -c 'echo $REPO_PROJECT;ssh -p 29418 review.example.com gerrit create-project code/$REPO_PROJECT --parent code;'

git push 代码到分支

repo forall -c 'echo $REPO_PROJECT;git push review.example.com:29418/code/$REPO_PROJECT -o skip-validation HEAD:refs/heads/branchname;'

优缺点

不论使用哪种方式,最后都需要修改manifest文件或gitconfig文件,方便从我们的Gerrit服务器上下载代码。