Changeset - 98deccab042c
[Not reviewed]
stable
0 1 0
Thomas De Schampheleire - 7 years ago 2019-04-10 21:54:50
thomas.de_schampheleire@nokia.com
hooks: add intermediate function _get_git_hook_interpreter

The logic to determine the right interpreter for Git hooks is about to
change and possibly become more complex.
Split it off in a separate function so such changes do not require extra
code duplication and preserve the readability of the code.
1 file changed with 13 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/model/scm.py
Show inline comments
 
@@ -720,6 +720,17 @@ class ScmModel(object):
 

	
 
        return choices, hist_l
 

	
 
    def _get_git_hook_interpreter(self):
 
        """Return a suitable interpreter for Git hooks.
 

	
 
        Return a suitable string to be written in the POSIX #! shebang line for
 
        Git hook scripts so they invoke Kallithea code with the right Python
 
        interpreter and in the right environment.
 
        """
 
        # FIXME This may not work on Windows and may need a shell wrapper script.
 
        return (sys.executable
 
                or 'python2')
 

	
 
    def install_git_hooks(self, repo, force_create=False):
 
        """
 
        Creates a kallithea hook inside a git repository
 
@@ -734,11 +745,11 @@ class ScmModel(object):
 
        if not os.path.isdir(loc):
 
            os.makedirs(loc)
 

	
 
        tmpl_post = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
 
        tmpl_post = "#!/usr/bin/env %s\n" % self._get_git_hook_interpreter()
 
        tmpl_post += pkg_resources.resource_string(
 
            'kallithea', os.path.join('config', 'post_receive_tmpl.py')
 
        )
 
        tmpl_pre = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
 
        tmpl_pre = "#!/usr/bin/env %s\n" % self._get_git_hook_interpreter()
 
        tmpl_pre += pkg_resources.resource_string(
 
            'kallithea', os.path.join('config', 'pre_receive_tmpl.py')
 
        )
0 comments (0 inline, 0 general)