Changeset - 5e501b6ee639
[Not reviewed]
default
0 3 0
domruf - 10 years ago 2016-04-29 16:53:49
dominikruf@gmail.com
hooks: if available, use sys.executable as executable for git hooks

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.
3 files changed with 5 insertions and 4 deletions:
0 comments (0 inline, 0 general)
kallithea/config/post_receive_tmpl.py
Show inline comments
 
#!/usr/bin/env python2
 
import os
 
import sys
 

	
 
try:
 
    import kallithea
 
    KALLITHEA_HOOK_VER = '_TMPL_'
 
    os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
 
    from kallithea.lib.hooks import handle_git_post_receive as _handler
 
except ImportError:
 
    if os.environ.get('RC_DEBUG_GIT_HOOK'):
 
        import traceback
 
        print traceback.format_exc()
kallithea/config/pre_receive_tmpl.py
Show inline comments
 
#!/usr/bin/env python2
 
import os
 
import sys
 

	
 
try:
 
    import kallithea
 
    KALLITHEA_HOOK_VER = '_TMPL_'
 
    os.environ['KALLITHEA_HOOK_VER'] = KALLITHEA_HOOK_VER
 
    from kallithea.lib.hooks import handle_git_pre_receive as _handler
 
except ImportError:
 
    if os.environ.get('RC_DEBUG_GIT_HOOK'):
 
        import traceback
 
        print traceback.format_exc()
kallithea/model/scm.py
Show inline comments
 
@@ -17,24 +17,25 @@ kallithea.model.scm
 

	
 
Scm model for Kallithea
 

	
 
This file was forked by the Kallithea project in July 2014.
 
Original author and date, and relevant copyright and licensing information is below:
 
:created_on: Apr 9, 2010
 
:author: marcink
 
:copyright: (c) 2013 RhodeCode GmbH, and others.
 
:license: GPLv3, see LICENSE.md for more details.
 
"""
 

	
 
import os
 
import sys
 
import posixpath
 
import re
 
import time
 
import traceback
 
import logging
 
import cStringIO
 
import pkg_resources
 
from os.path import join as jn
 

	
 
from sqlalchemy import func
 
from pylons.i18n.translation import _
 

	
 
@@ -735,28 +736,30 @@ class ScmModel(BaseModel):
 
        Creates a kallithea hook inside a git repository
 

	
 
        :param repo: Instance of VCS repo
 
        :param force_create: Create even if same name hook exists
 
        """
 

	
 
        loc = jn(repo.path, 'hooks')
 
        if not repo.bare:
 
            loc = jn(repo.path, '.git', 'hooks')
 
        if not os.path.isdir(loc):
 
            os.makedirs(loc)
 

	
 
        tmpl_post = pkg_resources.resource_string(
 
        tmpl_post = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
 
        tmpl_post += pkg_resources.resource_string(
 
            'kallithea', jn('config', 'post_receive_tmpl.py')
 
        )
 
        tmpl_pre = pkg_resources.resource_string(
 
        tmpl_pre = "#!/usr/bin/env %s\n" % sys.executable or 'python2'
 
        tmpl_pre += pkg_resources.resource_string(
 
            'kallithea', jn('config', 'pre_receive_tmpl.py')
 
        )
 

	
 
        for h_type, tmpl in [('pre', tmpl_pre), ('post', tmpl_post)]:
 
            _hook_file = jn(loc, '%s-receive' % h_type)
 
            has_hook = False
 
            log.debug('Installing git hook in repo %s', repo)
 
            if os.path.exists(_hook_file):
 
                # let's take a look at this hook, maybe it's kallithea ?
 
                log.debug('hook exists, checking if it is from kallithea')
 
                with open(_hook_file, 'rb') as f:
 
                    data = f.read()
0 comments (0 inline, 0 general)