push gerrit but without auto added "Changed-id"

来源:互联网 发布:淘宝护肤品店铺介绍 编辑:程序博客网 时间:2024/06/11 07:04

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了。

0 0
原创粉丝点击