| |
@@ -12,6 +12,7 @@
|
| |
import shutil
|
| |
import wtforms
|
| |
|
| |
+ from pagure.exceptions import FileNotFoundException
|
| |
from pagure import APP, get_repo_path
|
| |
|
| |
|
| |
@@ -69,13 +70,11 @@
|
| |
# Install the main post-receive file
|
| |
postreceive = os.path.join(hookfolder, cls.hook_type)
|
| |
if not os.path.exists(postreceive):
|
| |
- shutil.copyfile(
|
| |
- os.path.join(hook_files, cls.hook_type),
|
| |
- postreceive)
|
| |
- os.chmod(postreceive, 0755)
|
| |
+ os.symlink(os.path.join(hook_files, cls.hook_type),
|
| |
+ postreceive)
|
| |
|
| |
@classmethod
|
| |
- def install(cls, project, dbobj): # pragma: no cover
|
| |
+ def base_install(cls, repopaths, dbobj, hook_name, filein):
|
| |
''' Method called to install the hook for a project.
|
| |
|
| |
:arg project: a ``pagure.model.Project`` object to which the hook
|
| |
@@ -84,14 +83,41 @@
|
| |
information.
|
| |
|
| |
'''
|
| |
- pass
|
| |
+ for repopath in repopaths:
|
| |
+ if not os.path.exists(repopath):
|
| |
+ raise FileNotFoundException('Repo %s not found' % repopath)
|
| |
+
|
| |
+ hook_files = os.path.join(
|
| |
+ os.path.dirname(os.path.realpath(__file__)), 'files')
|
| |
+
|
| |
+ # Make sure the hooks folder exists
|
| |
+ hookfolder = os.path.join(repopath, 'hooks')
|
| |
+ if not os.path.exists(hookfolder):
|
| |
+ os.makedirs(hookfolder)
|
| |
+
|
| |
+ # Install the hook itself
|
| |
+ hook_file = os.path.join(repopath, 'hooks', cls.hook_type + '.'
|
| |
+ + hook_name)
|
| |
+
|
| |
+ if not os.path.exists(hook_file):
|
| |
+ os.symlink(
|
| |
+ os.path.join(hook_files, filein),
|
| |
+ hook_file
|
| |
+ )
|
| |
|
| |
@classmethod
|
| |
- def remove(cls, project): # pragma: no cover
|
| |
+ def base_remove(cls, repopaths, hook_name):
|
| |
''' Method called to remove the hook of a project.
|
| |
|
| |
:arg project: a ``pagure.model.Project`` object to which the hook
|
| |
should be installed
|
| |
|
| |
'''
|
| |
- pass
|
| |
+ for repopath in repopaths:
|
| |
+ if not os.path.exists(repopath):
|
| |
+ raise FileNotFoundException('Repo %s not found' % repopath)
|
| |
+
|
| |
+ hook_path = os.path.join(repopath, 'hooks', cls.hook_type + '.'
|
| |
+ + hook_name)
|
| |
+ if os.path.exists(hook_path):
|
| |
+ os.unlink(hook_path)
|
| |
Fixes https://pagure.io/pagure/issue/901 + Create symlink for post/pre-receive script and add x permission in git.