如何使用 Mercurial 队列或 histedit 禁用 pretxncommit 挂钩?

发布于 2024-12-08 05:49:58 字数 284 浏览 2 评论 0原文

我的本地 Mercurial 存储库中有一些 pretxncommit 挂钩,这些挂钩用于检查提交消息是否包含对票证的引用和其他一些健全性检查。

我的问题是,当我尝试使用 Mercurial 队列时,像 qnew 这样的命令尝试运行这些挂钩,并且其中一个票证检查失败,我在 histedit 中也看到了同样的问题> 和类似的扩展。

为什么要使用这些命令执行 pretxncommit 挂钩?他们是否运行某种内部提交?

如何使这些挂钩仅在提交时运行?

I have some pretxncommit hooks in my local mercurial repository, those hooks are used to check that the commit message includes a reference to a ticket and some other sanity checks.

My problem is that when I try to use mercurial queues, commands like qnew try to run these hooks and the one of the ticket checking fails, I have seen the same problem with histedit and similar extensions.

Why are pretxncommit hooks executed with these commands? Do they run some kind of internal commit?

How can I make these hooks to be run only on commits?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

奶茶白久 2024-12-15 05:49:58

是的,qnew 创建一个真正的提交,从而调用所有相关的提交挂钩。您可以通过在应用 MQ 补丁时暂时禁用 MQ 并查看日志来亲自确认这一点。

没有办法让 pretxncommit 钩子只适用于某些命令,除非用其他钩子临时操纵某些东西:

$ cat .hg/hgrc
[hooks]
pre-qnew = touch .hg/skiphook
post-qnew = rm .hg/skiphook
pretxncommit = test -e .hg/skiphook || echo not skipping
$ hg rm README  # make some change
$ hg qnew asdf  # no hook
$ hg qpop
$ hg rm README
$ hg ci -m asdf
not skipping

这里我们的 pretxncommit 钩子确保在运行其(简单的)钩子之前特定文件不存在,并且 pre-/ post-qnew 挂钩创建文件并清理它。

Yes, a qnew creates a real commit and thus invokes all the relevant commit hooks. You can confirm this for yourself by temporarily disabling MQ while you have an MQ patch applied and looking at the log.

There is no way to make the pretxncommit hook apply to only some commands except by jury-rigging something with other hooks:

$ cat .hg/hgrc
[hooks]
pre-qnew = touch .hg/skiphook
post-qnew = rm .hg/skiphook
pretxncommit = test -e .hg/skiphook || echo not skipping
$ hg rm README  # make some change
$ hg qnew asdf  # no hook
$ hg qpop
$ hg rm README
$ hg ci -m asdf
not skipping

Here our pretxncommit hook makes sure a specific file doesn't exist before running its (trivial) hook, and the pre-/post-qnew hooks create the file and clean it up.

电影里的梦 2024-12-15 05:49:58

https://stackoverflow.com/a/19349636/350713 中的函数 abort_commit_to_wrong_branch
显示了一种仅在“真实”提交而不是 MQ 提交上运行挂钩的方法。
这个想法是检查 repo 中的属性 _committingpatch

如果 repo 具有“_committingpatch”属性,则它是正在进行的 MQ 提交。
相关行是

if hasattr(repo, "_committingpatch"):

在函数newcommit中提到的
http://hg.intevation.org/mercurial/船员/文件/7032dcff290c/hgext/mq.py#l293

The function abort_commit_to_wrong_branch in https://stackoverflow.com/a/19349636/350713
shows an approach to run a hook only on a "real" commit, not an MQ commit.
The idea is to check for the attribute _committingpatch in repo.

If repo has '_committingpatch' attribute, then it is an MQ commit in progress.
The relevant line is

if hasattr(repo, "_committingpatch"):

This is mentioned in the function newcommit in
http://hg.intevation.org/mercurial/crew/file/7032dcff290c/hgext/mq.py#l293

往昔成烟 2024-12-15 05:49:58
  • pretxncommit 适用于存储库内的所有更改(可记录),
  • 如果您想忽略 mq 操作,您可以查找变更集父级并查看它是否是后代
    qparent/qbase 标签的或参见 WC。史密斯。就像(来自头部的脏东西,而不是来自测试的脏东西) hg id -tr 。

或者(也许是精神错乱)- 当您使用 MQ 时,您总是使用 qtip,不是吗?

>hg parents
...
tag:         qtip
tag:         tip
..
  • pretxncommit works with all changes (recordable) inside repo
  • if you want ignore mq-operation, you could look for the changeset parents and see if that's a descendant
    of the qparent/qbase tag or see at WC. Smth. like (dirty from head, not from test) hg id -tr .

Or (maybe delirium) - when you work with MQ, you work with qtip always, sn't it?

>hg parents
...
tag:         qtip
tag:         tip
..
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文