Changeset - 1089fac66e81
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 5 years ago 2020-11-04 13:17:27
mads@kiilerich.com
Grafted from: 78453a6e04f1
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.
1 file changed with 7 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/model/scm.py
Show inline comments
 
@@ -686,7 +686,10 @@ class ScmModel(object):
 
            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 @@ class ScmModel(object):
 
                    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:
0 comments (0 inline, 0 general)