From 9452e4ec0941fbee163e35ebdcd6ca6ee7df55cb Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 22 Aug 2009 18:17:46 -0700 Subject: Automatically install Gerrit Code Review's commit-msg hook Most users of repo are also using Gerrit Code Review, and will want the commit-msg hook to be automatically installed into their local projects so that Change-Ids are assigned when commits are created, not when they are first uploaded. (cherry picked from commit a949fa5d202f0a1f812d7630f3e5bf0f02ca4e98 but squashed with latest hook script from version 2.1.2) Change-Id: Ie68b2d60ac85d8c2285d2e1e6a4536eb76695547 Signed-off-by: Shawn O. Pearce --- project.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'project.py') diff --git a/project.py b/project.py index 3d1783f8..ff896d01 100644 --- a/project.py +++ b/project.py @@ -1055,13 +1055,27 @@ class Project(object): if not os.path.exists(hooks): os.makedirs(hooks) for stock_hook in repo_hooks(): - dst = os.path.join(hooks, os.path.basename(stock_hook)) + name = os.path.basename(stock_hook) + + if name in ('commit-msg') and not self.remote.review: + # Don't install a Gerrit Code Review hook if this + # project does not appear to use it for reviews. + # + 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(relpath(stock_hook, dst), dst) except OSError, e: - if e.errno == errno.EEXIST: - pass - elif e.errno == errno.EPERM: + if e.errno == errno.EPERM: raise GitError('filesystem must support symlinks') else: raise -- cgit v1.2.3-54-g00ecf