0%

gerrit命名空间

Gerrit 命名空间 refs/for/<branch> 用于代码评审,以及相关 alias

namespace

Branches, remote-tracking branches, and tags 等等都是对 commite 的引用(reference),引用都以 refs/...”表示

  • remote branch: origin/git_int(=refs/remotes/origin/git_int)
  • local tag: v2.0(=refs/tags/v2.0)
  • local branch: git_int(=refs/heads/git_int)

refs/for

refs/for/<branch> 用于 gerrit 代码评审

Gerrit uses the refs/for/ prefix to map the concept of “Pushing for Review” to the git protocol.

git 命令 git push origin HEAD:refs/for/<BRANCH_NAME>

refs/changes

提交到 gerrit 的代码如下格式

For the git client, it looks like every push goes to the same branch, such as refs/for/master. In fact, for each commit pushed to this ref, Gerrit creates a new ref under a refs/changes/ namespace, which Gerrit uses to track these commits. These references use the following format: refs/changes/[CD]/[ABCD]/[EF]

  • [CD] is the last two digits of the change number
  • [ABCD] is the change number
  • [EF] is the patch set number

refs/head

refs/head/<branch> 用于绕过评审直接提交代码,可能会因为权限控制导致提交失败

! [remote rejected] master -> master (prohibited by Gerrit)

git 命令 git push origin <BRANCH_NAME>

refs/drafts

草稿箱,仅 owner 以及邀请用户可见

git push origin HEAD:refs/drafts/<BRANCH_NAME>

git alias

[alias]
  ...
  push-for-review = push origin HEAD:refs/for/master
  push-for-review-branch = !git push origin HEAD:refs/for/$1
  push-as-draft = push origin HEAD:refs/drafts/master
  push-as-draft-branch = !git push origin HEAD:refs/drafts/$1
  ...

两个携带参数的 alias 存在问题,git version 2.17.1
git push-for-review-branch test 展开为 git push origin HEAD:refs/for/test test,多了一个参数导致直接合并到git仓库中

$ GIT_TRACE=1 git push-for-review-branch test
To ssh://192.168.110.254:29418/misc
   d9d506f..20c5d70  test -> test
 * [new branch]      HEAD -> refs/for/test