Changeset - 89875fb6739a
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2012-06-06 23:31:52
marcin@python-works.com
fixed issue with git-hook when pushing new heads
1 file changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
rhodecode/lib/hooks.py
Show inline comments
 
@@ -204,54 +204,58 @@ def handle_git_post_receive(repo_path, r
 
    to database and run the logging code. Hacky as sh**t but works. ps.
 
    GIT SUCKS
 

	
 
    :param repo_path:
 
    :type repo_path:
 
    :param revs:
 
    :type revs:
 
    :param env:
 
    :type env:
 
    """
 
    from paste.deploy import appconfig
 
    from sqlalchemy import engine_from_config
 
    from rhodecode.config.environment import load_environment
 
    from rhodecode.model import init_model
 
    from rhodecode.model.db import RhodeCodeUi
 
    from rhodecode.lib.utils import make_ui
 
    from rhodecode.model.db import Repository
 

	
 
    path, ini_name = os.path.split(env['RHODECODE_CONFIG_FILE'])
 
    conf = appconfig('config:%s' % ini_name, relative_to=path)
 
    load_environment(conf.global_conf, conf.local_conf)
 

	
 
    engine = engine_from_config(conf, 'sqlalchemy.db1.')
 
    init_model(engine)
 

	
 
    baseui = make_ui('db')
 
    repo = Repository.get_by_full_path(repo_path)
 

	
 
    _hooks = dict(baseui.configitems('hooks')) or {}
 
    # if push hook is enabled via web interface
 
    if _hooks.get(RhodeCodeUi.HOOK_PUSH):
 

	
 
        extras = {
 
         'username': env['RHODECODE_USER'],
 
         'repository': repo.repo_name,
 
         'scm': 'git',
 
         'action': 'push',
 
         'ip': env['RHODECODE_CONFIG_IP'],
 
        }
 
        for k, v in extras.items():
 
            baseui.setconfig('rhodecode_extras', k, v)
 
        repo = repo.scm_instance
 
        repo.ui = baseui
 
        old_rev, new_rev, ref = revs
 
        if old_rev == EmptyChangeset().raw_id:
 
            cmd = "for-each-ref --format='%(refname)' 'refs/heads/*'"
 
            heads = repo.run_git_command(cmd)[0]
 
            heads = heads.replace(ref, '')
 
            cmd = 'log ' + new_rev + ' --reverse --pretty=format:"%H" --not ' + heads
 
            heads = ' '.join(map(lambda c: c.strip('\n').strip(),
 
                                 heads.splitlines()))
 
            cmd = ('log ' + new_rev +
 
                   ' --reverse --pretty=format:"%H" --not ' + heads)
 
        else:
 
            cmd = 'log ' + old_rev + '..' + new_rev + ' --reverse --pretty=format:"%H"'
 
            cmd = ('log ' + old_rev + '..' + new_rev +
 
                   ' --reverse --pretty=format:"%H"')
 
        git_revs = repo.run_git_command(cmd)[0].splitlines()
 

	
 
        log_push_action(baseui, repo, _git_revs=git_revs)
0 comments (0 inline, 0 general)