From a28756babd9ad0c86025ed74ebc71429f011be3f Mon Sep 17 00:00:00 2001 From: Mathieu Bridon Date: Fri, 23 Jan 2015 11:57:09 +0100 Subject: [PATCH] git/check-perms: Adapt the script to the Gitolite3 VREF stuff --- roles/git/checks/files/check-perms.py | 61 ++++++--------------------- 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/roles/git/checks/files/check-perms.py b/roles/git/checks/files/check-perms.py index dad70a86bf..bf906a19a5 100755 --- a/roles/git/checks/files/check-perms.py +++ b/roles/git/checks/files/check-perms.py @@ -308,65 +308,32 @@ def check_git_perms(path, fix=False): return False return True -def check_update_hooks(gitdir, fix=False): +def check_gitolite_update_hook(gitdir, fix=False): """Check our update hooks This ensures that the Git repository at `gitdir` is set up with the proper - update hooks. + update hook for Gitolite. 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': '/etc/gitolite/hooks/common/update', - 'update-block-push-origin': '/usr/share/git-core/update-block-push-origin', - } + gitolite_hook = '/etc/gitolite/hooks/common/update' + update_hook = os.path.join(gitdir, 'hooks', 'update') - if not os.path.isdir(chained_hooks_dir): + if not os.path.exists(update_hook): if fix: - os.makedirs(chained_hooks_dir) + os.symlink(gitolite_hook, update_hook) + return - else: - raise ValueError('chained hooks not set up') + raise ValueError('No update hook 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 os.path.realpath(update_hook) != gitolite_hook: if fix: - os.symlink(goodpath, hook) + os.unlink(update_hook) + os.symlink(gitolite_hook, update_hook) + return - else: - raise ValueError('no update hook set up') + raise ValueError('Update hook does not point to the Gitolie one') - 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]' @@ -470,7 +437,7 @@ def main(): if 'update-hook' in checks: try: - check_update_hooks(gitdir, fix=opts.fix) + check_gitolite_update_hook(gitdir, fix=opts.fix) except Exception as e: error('%s: %s' % (gitdir, e))