Changeset - 1bafb2d07709
[Not reviewed]
stable
0 3 0
Thomas De Schampheleire - 7 years ago 2019-04-08 21:32:57
thomas.de_schampheleire@nokia.com
hooks: make the Python interpreter for Git hooks configurable as 'git_hook_interpreter' (Issue #333)

Commit 5e501b6ee639 introduced the use of 'sys.executable' as interpreter
for git hooks instead of 'python2' with the following argument:

"Windows doesn't necessarily have "python2" available in $PATH, but we
still want to make sure we don't end up invoking a python3. Using the
absolute path seems more safe."

But, sys.executable does not necessarily point to Python. When Kallithea is
started under uWSGI, sys.executable points to the uwsgi executable. As a
result, the interpreter encoded in the git hooks on the server repositories
would be:

#!/path/to/uwsgi

And pushing to such repo would result in following client errors:

$ git push
Password for 'http://user@localhost:5050':
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 241 bytes | 241.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: unable to load configuration from hooks/pre-receive
To http://localhost:5050/gitrepo-new
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'http://user@localhost:5050/gitrepo-new'

Fix this problem by introducing a configuration setting 'git_hook_interpreter'
that allow administrators to specify which Python interpreter to use.

A subsequent commit will cause its value to be filled in automatically when
generating a new ini file, but an administrator can always override it.
3 files changed with 25 insertions and 1 deletions:
0 comments (0 inline, 0 general)
development.ini
Show inline comments
 
@@ -117,6 +117,15 @@ use_htsts = false
 
## number of commits stats will parse on each iteration
 
commit_parse_limit = 25
 

	
 
## Path to Python executable to be used for git hooks.
 
## This value will be written inside the git hook scripts as the text
 
## after '#!' (shebang). When empty or not defined, the value of
 
## 'sys.executable' at the time of installation of the git hooks is
 
## used, which is correct in many cases but for example not when using uwsgi.
 
## If you change this setting, you should reinstall the Git hooks via
 
## Admin > Settings > Remap and Rescan.
 
# git_hook_interpreter = /srv/kallithea/venv/bin/python2
 

	
 
## path to git executable
 
git_path = git
 

	
kallithea/lib/paster_commands/template.ini.mako
Show inline comments
 
@@ -211,6 +211,18 @@ use_htsts = false
 
<%text>## number of commits stats will parse on each iteration</%text>
 
commit_parse_limit = 25
 

	
 
<%text>## Path to Python executable to be used for git hooks.</%text>
 
<%text>## This value will be written inside the git hook scripts as the text</%text>
 
<%text>## after '#!' (shebang). When empty or not defined, the value of</%text>
 
<%text>## 'sys.executable' at the time of installation of the git hooks is</%text>
 
<%text>## used, which is correct in many cases but for example not when using uwsgi.</%text>
 
<%text>## If you change this setting, you should reinstall the Git hooks via</%text>
 
<%text>## Admin > Settings > Remap and Rescan.</%text>
 
# git_hook_interpreter = /srv/kallithea/venv/bin/python2
 
%if git_hook_interpreter:
 
git_hook_interpreter = ${git_hook_interpreter}
 
%endif
 

	
 
<%text>## path to git executable</%text>
 
git_path = git
 

	
kallithea/model/scm.py
Show inline comments
 
@@ -727,8 +727,11 @@ class ScmModel(object):
 
        Git hook scripts so they invoke Kallithea code with the right Python
 
        interpreter and in the right environment.
 
        """
 
        # Note: sys.executable might not point at a usable Python interpreter. For
 
        # example, when using uwsgi, it will point at the uwsgi program itself.
 
        # FIXME This may not work on Windows and may need a shell wrapper script.
 
        return (sys.executable
 
        return (kallithea.CONFIG.get('git_hook_interpreter')
 
                or sys.executable
 
                or '/usr/bin/env python2')
 

	
 
    def install_git_hooks(self, repo, force_create=False):
0 comments (0 inline, 0 general)