Mercurial钩子-在钩子之间传递信息? [英] Mercurial hooks -- pass information between hooks?

查看:80
本文介绍了Mercurial钩子-在钩子之间传递信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前在我的软件项目中有一个pre-commit钩子,如果需要,用户可以选择更新项目的版本号(例如,将1.0更改为1.0.11.12.0) .他们选择这些选项之一,然后在提交之前,挂钩会更新项目文件之一中的版本号.

当我运行hg commit时,此挂钩将运行并使用新的版本号更新相关文件,然后执行提交.

我想添加到钩子中,使其也调用hg tag <new_verson_number>.

但是,我不能将其添加到pre-commit钩子中,因为这样会在调用提交之前 添加该标签,从而使该标签成为一个过时的修订版本. /p>

我想将hg tag命令添加到commit钩子(在提交后运行),以便事件的顺序如下:

  • hg commit -m "my commit message"
  • 用户说是的,我想更改版本号
  • 版本号已在相关文件中更新
  • 提交发生[到这里的一切都很好]
  • 如果用户更改了版本号,请运行一个提交挂钩:hg tag <new_version_number>.

现在,我可以添加一个提交挂钩,以从存储在其中的文件中读取新版本号并运行hg tag <new_version_number>但是,如果用户决定不更改版本号怎么办?在那种情况下,我不要想要添加标签,并且如果我盲目运行hg tag <new_version_number>,我最终会得到我不想要的标签.

所以-有什么方法可以告诉pre-commit挂钩为commit挂钩保留一些信息(是否添加标签的是/否),并且commit挂钩可以使用此信息来确定是否添加标签?

欢呼.

解决方案

一个commit钩子如何检查上一次提交是否修改了存储版本的文件?像这样:

[hooks]
commit.tagversion = if hg log -r $HG_NODE --template '{files}' | grep -q VERSION_FILE ; then hg tag $(hg cat -r $HG_NODE VERSION_FILE) ; fi

我还没有测试过,但是它应该可以工作.

I currently have a pre-commit hook in my mercurial project that gives the user the option to update the version number of the project if they wish (e.g. 1.0 to 1.0.1 or 1.1 or 2.0). They select one of these options, and the hook updates the version number in one of the project's files prior to the commit taking place.

When I run hg commit, this hook runs and updates the relevant file with the new version number, and then performs the commit.

I'd like to add to the hook such that it calls hg tag <new_verson_number> as well.

However, I can't add this to the pre-commit hook, because then the tag will be added before the commit is called, causing the tag to be one revision out of date.

I'd like to add the hg tag command to a commit hook (run after the commit), so that the sequence of events is like so:

  • hg commit -m "my commit message"
  • user says yes, I'd like to change the version number
  • version number is updated in the relevant file
  • commit occurs [everything up to here is fine]
  • if the user changed the version number, run a commit hook: hg tag <new_version_number>.

Now, I could add a commit hook that read off the new version number from the file it's stored in and run hg tag <new_version_number>, but what if the user decided not to change the version number? In that case, I don't want a tag added, and if I blindly run hg tag <new_version_number> I'll end up with tags I don't want.

So - is there some way I can tell the pre-commit hook to leave some information for the commit hook (a yes/no of whether to add the tag), and the commit hook can use this to determine whether to add the tag or not?

cheers.

解决方案

How about a commit hook that checks if the last commit modified the file in which you store the version? Something like:

[hooks]
commit.tagversion = if hg log -r $HG_NODE --template '{files}' | grep -q VERSION_FILE ; then hg tag $(hg cat -r $HG_NODE VERSION_FILE) ; fi

I haven't tested it, but that or something like it should work.

这篇关于Mercurial钩子-在钩子之间传递信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆