From 3976d7bec4dfdb331f1e275e650c1bc85e62bc92 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: May 27 2014 09:21:00 +0000 Subject: Add a global set_up method for the hooks This method install the post-receive shell script allowing us to have multiple post-receive hooks per project. --- diff --git a/progit/hooks/__init__.py b/progit/hooks/__init__.py index 2f17749..10f2e3d 100644 --- a/progit/hooks/__init__.py +++ b/progit/hooks/__init__.py @@ -8,6 +8,10 @@ """ +import os + +from progit import APP + class BaseHook(object): ''' Base class for progit's hooks. ''' @@ -16,6 +20,26 @@ class BaseHook(object): form = None @classmethod + def set_up(cls, project): + ''' Install the generic post-receive hook that allow us to call + multiple post-receive hooks as set per plugin. + ''' + repopath = os.path.join(APP.config['GIT_FOLDER'], project.path) + if project.is_fork: + repopath = os.path.join(APP.config['FORK_FOLDER'], project.path) + + hook_files = os.path.join( + os.path.dirname(os.path.realpath(__file__)), 'files') + + # Install the main post-receive file + postreceive = os.path.join(repopath, 'hooks', 'post-receive') + if not os.path.exists(postreceive): + shutil.copyfile( + os.path.join(hook_files, 'post-receive'), + postreceive) + os.chmod(postreceive, 0755) + + @classmethod def install(cls, project): ''' Method called to install the hook for a project.