上传项目代码到 Gerrit

1)创建项目

手动创建

确认 Gerrit 配置文件中确认 git 仓库的存放地址 gerrit.basePath,在服务器端运行:

git --git-dir=$base_path/project.git init

重启服务即可看到项目,也可以通过 ssh 刷新项目列表缓存:

ssh {username}@{gerrit_server} gerrit flush-caches --cache project_list

该种方式不会自动分配项目权限,需要在网页端手动编辑处理。

通过 ssh 创建

Caller must be a member of 'Administrators' group, or granted the 'Create Project' capability.

为了使用方便,建议配置本地 ssh 客户端, ~/.ssh/config

Host gerrit-expound
  Hostname code.expound.cc
  Port 29418	# curl https://code.expound.cc/ssh_info
  User git-test # username in Settring/Profile Section
ssh gerrit-expound gerrit create-project tool.git --description "'Tools used by build system'"

参数说明:https://gerrit-review.googlesource.com/Documentation/cmd-create-project.html

其他创建方式

  • 在网页端,BROWSE > Repositories 页面,点击新建按钮新建代码仓库;
  • via the Create Project REST endpoint

2)配置成员及权限

需要在 Administrators 用户组的用户才可以进行用户组的创建和成员管理。

同时创建 Team Group & Team Admin Group,将 Team Group 的所有权移交给 Team Admin Group 是最佳实践;

所有项目权限都继承于 All-Projects,可以把它当作系统全局配置,可以快速从项目模板中继承权限。

  • 对外开源的项目: open-project-template
    • 对所有用户(匿名和注册用户)可读;
    • 所有注册用户可提交修改;
  • 公司内部的项目: bussiness-project-template
    • 所有注册用户可读和可提交修改;
    • 匿名用户无法查看;
  • 指定团队的项目: team-project-template
  • 无需 Code Review 的项目: no-code-review-project-template

管理组成员可向所有项目直接 push 代码,无需经过 review 流程;

3)同步代码

从远程仓库拉取项目最新代码:

git clone https://code.expound.cc/open-project-template

# 或者 fetch 指定分支
mkdir open-project-template
cd open-project-template/ && git init
git clone https://code.expound.cc/open-project-template
git checkout FETCH_HEAD

项目如果已有代码库,直接推送本地代码:

git clone https://code.expound.cc/open-project-template
git push -u origin main