2

I would like to write a pre- hook for Mercurial written in Python. I would like to check the flags passed to the pull command, and also check the sync alias (the "remote URL").

I didn't notice anything like that on:

Peter
  • 3,322
  • 3
  • 27
  • 41

1 Answers1

1

kwargs['args'] seems to contain the command (as a single string) and all command arguments (including the pull sync alias URL, at least when pulling via TortoiseHG).

So the desired hook could be something like this:

from mercurial import ui

def check_pull(ui, repo, **kwargs):
    """
    [hooks]
    pre-pull.check_pull = python:.hg/hooks/my_hooks.py:check_pull
    """
    args = kwargs['args']
    is_pull_all = not '--bookmark' in args
    is_pull_clowncopter = 'http://hg.example.com/clowncopter/' in args
    if is_pull_all and is_pull_clowncopter:
        ui.warn('Detected pull all from clowncoper. Did you forget to switch to the main repository or target a specific bookmark?\n')
        return True
Peter
  • 3,322
  • 3
  • 27
  • 41