changeset 8737:1089fac66e81

git: detect existing symlink hooks before overwriting - only update plain files If the existing hook is a symlink, the hook is not what we put in place, and we should stay away - no matter if it points at something that looks like a Kallithea hook.
author Mads Kiilerich <mads@kiilerich.com>
date Wed, 04 Nov 2020 13:17:27 +0100
parents 6a90b1ebea2c
children 7b809e4a1ea5
files kallithea/model/scm.py
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/model/scm.py	Wed Nov 04 13:19:18 2020 +0100
+++ b/kallithea/model/scm.py	Wed Nov 04 13:17:27 2020 +0100
@@ -686,7 +686,10 @@
             hook_file = os.path.join(hooks_path, h_type)
             other_hook = False
             log.debug('Installing git hook in repo %s', repo)
-            if os.path.exists(hook_file):
+            if os.path.islink(hook_file):
+                log.debug("Found symlink hook at %s", hook_file)
+                other_hook = True
+            elif os.path.isfile(hook_file):
                 log.debug('hook exists, checking if it is from kallithea')
                 with open(hook_file, 'rb') as f:
                     data = f.read()
@@ -697,7 +700,9 @@
                     else:
                         log.debug('Found non-Kallithea hook at %s', hook_file)
                         other_hook = True
-
+            elif os.path.exists(hook_file):
+                log.debug("Found hook that isn't a regular file at %s", hook_file)
+                other_hook = True
             if other_hook and not force:
                 log.warning('skipping overwriting hook file %s', hook_file)
             else: