summaryrefslogtreecommitdiffstats
path: root/roles/git/checks/files
diff options
context:
space:
mode:
authorMathieu Bridon <bochecha@fedoraproject.org>2014-09-23 16:00:01 +0200
committerPierre-Yves Chibon <pingou@pingoured.fr>2014-10-27 10:48:12 +0100
commit3681259c21dafc8fc23b81f0fe9c75a81f8a06b7 (patch)
tree921d346084deb72efb83963a73951a7f4e8c0b18 /roles/git/checks/files
parent16ffb744be3e4b99cc1f3170b7ea76abdfbe7a53 (diff)
downloadansible-3681259c21dafc8fc23b81f0fe9c75a81f8a06b7.tar.gz
ansible-3681259c21dafc8fc23b81f0fe9c75a81f8a06b7.tar.xz
ansible-3681259c21dafc8fc23b81f0fe9c75a81f8a06b7.zip
git/checks: Check for the update hooks
We are now setting up distgit (and possibily other things like Fedora Hosted) to use a more elaborate system of update hooks. This updates the checking script so it is capable of ensuring this set up.
Diffstat (limited to 'roles/git/checks/files')
-rwxr-xr-xroles/git/checks/files/check-perms.py71
1 files changed, 70 insertions, 1 deletions
diff --git a/roles/git/checks/files/check-perms.py b/roles/git/checks/files/check-perms.py
index 31d421567..322db57ab 100755
--- a/roles/git/checks/files/check-perms.py
+++ b/roles/git/checks/files/check-perms.py
@@ -10,7 +10,8 @@ import optparse
from stat import *
from subprocess import call, PIPE, Popen
-ALL_CHECKS = ['bare', 'shared', 'mail-hook', 'fedmsg-hook', 'perms', 'post-update-hook']
+ALL_CHECKS = ['bare', 'shared', 'mail-hook', 'fedmsg-hook', 'perms',
+ 'post-update-hook', 'update-hook']
DEFAULT_CHECKS = ['bare', 'shared', 'perms', 'post-update-hook']
OBJECT_RE = re.compile('[0-9a-z]{40}')
@@ -307,6 +308,66 @@ def check_git_perms(path, fix=False):
return False
return True
+def check_update_hooks(gitdir, fix=False):
+ """Check our update hooks
+
+ This ensures that the Git repository at `gitdir` is set up with the proper
+ update hooks.
+
+ If it isn't, and if `fix` is True, this actually fixes the problem.
+ """
+ chained_hooks_dir = os.path.join(gitdir, 'hooks', 'update-chained.d')
+ chained_hooks = {'update-gitolite': '/usr/share/gitolite/hooks/common/update',
+ 'update-block-push-origin': '/usr/share/git-core/update-block-push-origin',
+ }
+
+ if not os.path.isdir(chained_hooks_dir):
+ if fix:
+ os.makedirs(chained_hooks_dir)
+
+ else:
+ raise ValueError('chained hooks not set up')
+
+ for name, goodpath in chained_hooks.items():
+ hook = os.path.join(chained_hooks_dir, name)
+
+ if not os.path.exists(hook):
+ if fix:
+ os.symlink(goodpath, hook)
+
+ else:
+ raise ValueError('%s chained update hook not set up' % name)
+
+ realpath = os.path.realpath(hook)
+ if realpath != goodpath:
+ if fix:
+ os.unlink(hook)
+ os.symlink(goodpath, hook)
+
+ else:
+ raise ValueError('invalid %s chained update hook' % name)
+
+
+ goodpath = '/usr/share/git-core/update-chained'
+ hook = os.path.join(gitdir, 'hooks', 'update')
+
+ if not os.path.exists(hook):
+ if fix:
+ os.symlink(goodpath, hook)
+
+ else:
+ raise ValueError('no update hook set up')
+
+ realpath = os.path.realpath(hook)
+
+ if realpath != goodpath:
+ if fix:
+ os.unlink(hook)
+ os.symlink(goodpath, hook)
+
+ else:
+ raise ValueError('invalid update hook (%s)' % hook)
+
def main():
usage = '%prog [options] [gitroot]'
parser = optparse.OptionParser(usage=usage)
@@ -407,6 +468,14 @@ def main():
if not check_git_perms(path, fix=opts.fix):
problems.append(path)
+ if 'update-hook' in checks:
+ try:
+ check_update_hooks(gitdir, fix=opts.fix)
+
+ except Exception as e:
+ error('%s: %s' % (gitdir, e))
+ problems.append(gitdir)
+
if problems:
raise SystemExit('%d problems remain unfixed' % len(problems))