Changeset - a3efdd61a21f
[Not reviewed]
beta
1 2 1
Marcin Kuzminski - 13 years ago 2012-06-06 21:32:19
marcin@python-works.com
Git Hooks are automatically installed in new repos
- fixed issue with initial push
- changed git pre-receive hook template to py file
3 files changed with 29 insertions and 4 deletions:
0 comments (0 inline, 0 general)
rhodecode/config/pre_receive_tmpl.py
Show inline comments
 
file renamed from rhodecode/config/pre-receive.tmpl to rhodecode/config/pre_receive_tmpl.py
rhodecode/lib/hooks.py
Show inline comments
 
@@ -33,6 +33,7 @@ from mercurial.node import nullrev
 
from rhodecode import EXTENSIONS
 
from rhodecode.lib import helpers as h
 
from rhodecode.lib.utils import action_logger
 
from rhodecode.lib.vcs.backends.base import EmptyChangeset
 

	
 

	
 
def _get_scm_size(alias, root_path):
 
@@ -242,9 +243,14 @@ def handle_git_post_receive(repo_path, r
 
            baseui.setconfig('rhodecode_extras', k, v)
 
        repo = repo.scm_instance
 
        repo.ui = baseui
 
        old_rev, new_rev = revs[0:-1]
 

	
 
        cmd = 'log ' + old_rev + '..' + new_rev + ' --reverse --pretty=format:"%H"'
 
        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
 
        else:
 
            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)
rhodecode/model/repo.py
Show inline comments
 
@@ -22,10 +22,13 @@
 
#
 
# You should have received a copy of the GNU General Public License
 
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
from __future__ import with_statement
 
import os
 
import shutil
 
import logging
 
import traceback
 
import pkg_resources
 
from os.path import dirname as dn, join as jn
 
from datetime import datetime
 

	
 
from rhodecode.lib.vcs.backends import get_backend
 
@@ -461,7 +464,23 @@ class RepoModel(BaseModel):
 
        if alias == 'hg':
 
            backend(repo_path, create=True, src_url=clone_uri)
 
        elif alias == 'git':
 
            backend(repo_path, create=True, src_url=clone_uri, bare=True)
 
            r = backend(repo_path, create=True, src_url=clone_uri, bare=True)
 
            # add rhodecode hook into this repo
 

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

	
 
            tmpl = pkg_resources.resource_string(
 
                'rhodecode', jn('config', 'pre_receive_tmpl.py')
 
            )
 
            _hook_file = jn(loc, 'pre-receive')
 
            with open(_hook_file, 'wb') as f:
 
                f.write(tmpl)
 
            os.chmod(_hook_file, 0555)
 

	
 
        else:
 
            raise Exception('Undefined alias %s' % alias)
 

	
0 comments (0 inline, 0 general)