Changeset - fff835606650
[Not reviewed]
default
0 1 0
Mads Kiilerich (mads) - 5 years ago 2021-01-11 13:29:23
mads@kiilerich.com
Grafted from: ee201f55599a
hooks: improve hook installation logging
1 file changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
kallithea/model/scm.py
Show inline comments
 
@@ -679,18 +679,18 @@ class ScmModel(object):
 
            'kallithea', os.path.join('templates', 'py', 'git_pre_receive_hook.py')
 
        )
 

	
 
        for h_type, tmpl in [('pre-receive', tmpl_pre), ('post-receive', tmpl_post)]:
 
            hook_file = os.path.join(hooks_path, h_type)
 
            other_hook = False
 
            log.debug('Installing git hook in repo %s', repo)
 
            log.debug('Installing git hook %s in repo %s', h_type, repo.path)
 
            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')
 
                log.debug('hook file %s exists, checking if it is from kallithea', hook_file)
 
                with open(hook_file, 'rb') as f:
 
                    data = f.read()
 
                    matches = re.search(br'^KALLITHEA_HOOK_VER\s*=\s*(.*)$', data, flags=re.MULTILINE)
 
                    if matches:
 
                        ver = safe_str(matches.group(1))
 
                        log.debug('Found Kallithea hook - it has KALLITHEA_HOOK_VER %s', ver)
 
@@ -700,13 +700,13 @@ class ScmModel(object):
 
            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:
 
                log.debug('writing %s hook file !', h_type)
 
                log.debug('writing hook file %s', hook_file)
 
                try:
 
                    fh, fn = tempfile.mkstemp(prefix=hook_file + '.tmp.')
 
                    os.write(fh, tmpl.replace(b'_TMPL_', safe_bytes(kallithea.__version__)))
 
                    os.close(fh)
 
                    os.chmod(fn, 0o777 & ~umask)
 
                    os.rename(fn, hook_file)
0 comments (0 inline, 0 general)