diff --git a/kallithea/bin/vcs_hooks.py b/kallithea/bin/vcs_hooks.py --- a/kallithea/bin/vcs_hooks.py +++ b/kallithea/bin/vcs_hooks.py @@ -25,9 +25,11 @@ Original author and date, and relevant c :license: GPLv3, see LICENSE.md for more details. """ +import logging import os import sys +import mercurial.hg import mercurial.scmutil import paste.deploy @@ -40,6 +42,9 @@ from kallithea.lib.vcs.utils.helpers imp from kallithea.model import db +log = logging.getLogger(__name__) + + def repo_size(ui, repo, hooktype=None, **kwargs): """Show size of Mercurial repository. @@ -60,6 +65,21 @@ def repo_size(ui, repo, hooktype=None, * ui.status(safe_bytes(msg)) +def update(ui, repo, hooktype=None, **kwargs): + """Update repo after push. The equivalent to 'hg update' but using the same + Mercurial as everything else. + + Called as Mercurial hook changegroup.update after push. + """ + try: + ui.pushbuffer(error=True, subproc=True) + rev = brev = None + mercurial.hg.updatetotally(ui, repo, rev, brev) + finally: + s = ui.popbuffer() # usually just "x files updated, x files merged, x files removed, x files unresolved" + log.info('%s update hook output: %s', safe_str(repo.root), safe_str(s).rstrip()) + + def pull_action(ui, repo, **kwargs): """Logs user pull action diff --git a/kallithea/lib/db_manage.py b/kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py +++ b/kallithea/lib/db_manage.py @@ -244,8 +244,8 @@ class DbManage(object): ui_config = [ ('paths', '/', repo_root_path, True), #('phases', 'publish', 'false', False) - ('hooks', db.Ui.HOOK_UPDATE, 'hg update >&2', False), - ('hooks', db.Ui.HOOK_REPO_SIZE, 'python:', True), # the actual value doesn't matter + ('hooks', db.Ui.HOOK_UPDATE, 'python:', False), # the actual value in db doesn't matter + ('hooks', db.Ui.HOOK_REPO_SIZE, 'python:', True), # the actual value in db doesn't matter ('extensions', 'largefiles', '', True), ('largefiles', 'usercache', os.path.join(repo_root_path, '.cache', 'largefiles'), True), ('extensions', 'hggit', '', False), diff --git a/kallithea/lib/utils.py b/kallithea/lib/utils.py --- a/kallithea/lib/utils.py +++ b/kallithea/lib/utils.py @@ -283,6 +283,8 @@ def make_ui(repo_path=None): baseui.setconfig(b'hooks', b'outgoing.kallithea_pull_action', b'python:kallithea.bin.vcs_hooks.pull_action') if baseui.config(b'hooks', ascii_bytes(db.Ui.HOOK_REPO_SIZE)): # ignore actual value baseui.setconfig(b'hooks', ascii_bytes(db.Ui.HOOK_REPO_SIZE), b'python:kallithea.bin.vcs_hooks.repo_size') + if baseui.config(b'hooks', ascii_bytes(db.Ui.HOOK_UPDATE)): # ignore actual value + baseui.setconfig(b'hooks', ascii_bytes(db.Ui.HOOK_UPDATE), b'python:kallithea.bin.vcs_hooks.update') if repo_path is not None: # Note: MercurialRepository / mercurial.localrepo.instance will do this too, so it will always be possible to override db settings or what is hardcoded above diff --git a/kallithea/tests/functional/test_admin_settings.py b/kallithea/tests/functional/test_admin_settings.py --- a/kallithea/tests/functional/test_admin_settings.py +++ b/kallithea/tests/functional/test_admin_settings.py @@ -98,7 +98,6 @@ class TestAdminSettingsController(base.T self.checkSessionFlash(response, 'Builtin hooks are read-only') response = response.follow() response.mustcontain('changegroup.update') - response.mustcontain('hg update >&2') def test_index_search(self): self.log_user()