【发布时间】:2019-04-15 13:47:01
【问题描述】:
我想为用 Python 编写的 Mercurial 写一个 pre- hook。我想检查传递给pull 命令的标志,并检查同步别名(“远程 URL”)。
我没有注意到类似的东西:
【问题讨论】:
我想为用 Python 编写的 Mercurial 写一个 pre- hook。我想检查传递给pull 命令的标志,并检查同步别名(“远程 URL”)。
我没有注意到类似的东西:
【问题讨论】:
kwargs['args'] 似乎包含命令(作为单个字符串)和所有命令参数(包括拉同步别名 URL,至少在通过 TortoiseHG 拉时)。
所以想要的钩子可能是这样的:
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
【讨论】: