【问题标题】:How can a Mercurial Hook validate the used flags and sync alias?Mercurial Hook 如何验证使用的标志和同步别名?
【发布时间】:2019-04-15 13:47:01
【问题描述】:

我想为用 Python 编写的 Mercurial 写一个 pre- hook。我想检查传递给pull 命令的标志,并检查同步别名(“远程 URL”)。

我没有注意到类似的东西:

【问题讨论】:

    标签: mercurial mercurial-hook


    【解决方案1】:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-12
      • 1970-01-01
      • 1970-01-01
      • 2017-07-08
      • 1970-01-01
      • 1970-01-01
      • 2018-09-02
      相关资源
      最近更新 更多