push gerrit but without auto added "Changed-id"

1). 检查子目录.git/hook下面是否有 commit-msg 文件,

https://gerrit-review.googlesource.com/tools/hooks/commit-msg

2). 如果是repo sync 下来的代码,只要检查子目录中是否存在 commit-msg 如果不存在,修改工程目录下面 .repo/manifest.xml,添加review项指定即可。

< remote  name="origin"
 fetch=".."
 review="xxx.git/gerrit" />

注意必须添加上面的 review=”review.source.android.com” 这句。

在.repo/repo/project.py中,有这么一段代码:

def _InitHooks(self):
    hooks = os.path.realpath(self._gitdir_path('hooks'))
    if not os.path.exists(hooks):
      os.makedirs(hooks)
    for <span style="color:#FF0000;">stock_hook</span> in _ProjectHooks():
      name = os.path.basename(stock_hook)

      if name in ('commit-msg',) and not self.remote.review \
            and not self is self.manifest.manifestProject:
        # Don't install a Gerrit Code Review hook if this
        # project does not appear to use it for reviews.
        #
        # Since the manifest project is one of those, but also
        # managed through gerrit, it's excluded
        continue

      dst = os.path.join(hooks, name)
      if os.path.islink(dst):
        continue
      if os.path.exists(dst):
        if filecmp.cmp(stock_hook, dst, shallow=False):
          os.remove(dst)
        else:
          _error("%s: Not replacing %s hook", self.relpath, name)
          continue
      try:
        os.symlink(os.path.relpath(stock_hook, os.path.dirname(dst)), dst)
      except OSError as e:
        if e.errno == errno.EPERM:
          raise GitError('filesystem must support symlinks')
        else:
          raise
什么是_ProjectHooks呢,
def _ProjectHooks():
  """List the hooks present in the 'hooks' directory.

  These hooks are project hooks and are copied to the '.git/hooks' directory
  of all subprojects.

  This function caches the list of hooks (based on the contents of the
  'repo/hooks' directory) on the first call.

  Returns:
    A list of absolute paths to all of the files in the hooks directory.
  """
  global _project_hook_list
  if _project_hook_list is None:
    d = os.path.realpath(os.path.abspath(os.path.dirname(__file__)))
    d = os.path.join(d , 'hooks')
    _project_hook_list = [os.path.join(d, x) for x in os.listdir(d)]
  return _project_hook_list


具体来讲它列举.repo/hooks下的文件,让我们ls一下这个目录

ls hooks/
commit-msg  pre-auto-gc
所以如果用gerrit的话,会把这两个hooks拷贝到对应子项目的.git/hooks下面,这样子你自己在每个子目录下commit代码的时候,都会自动帮你添加Changed-id了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值