Mercurial - 我想添加一些在提交后运行的自定义代码

发布于 2024-08-19 16:10:47 字数 769 浏览 8 评论 0原文

我可以在哪里放置每次使用 Mercurial 提交后运行的代码?具体来说,我想在项目根目录的 .hg 文件夹中维护一个名为 latest 的文件 - 该文件将保存最近提交的修订号和哈希码。关于同一主题,我如何在 python 中获得这些?

# get mercurial version hash
ver = ?

# get mercurial revision number
rev = ?

# is there a shortcut to this folder through mercurial?
f = open('/path/to/.hg/latest', 'w')
f.write('ver=%s\nrev=%d' % ( str(ver), int(rev) ) )
f.close

编辑: 我能够使用钩子(在 .hg/hgrc 中)完成上述操作:

[hooks]
precommit= echo node=`hg tip --template {node}` > tip && echo rev=`hg tip --template {rev}` >> tip && hg add tip

包含提示信息的文件已成功创建,但我还想使用 hg addtip 将其添加到当前提交,这就是 Mercurial 进程陷入等待显然由挂起的提交持有的锁的地方。有没有办法解决这个问题,以便将提交期间/预提交创建的文件添加到其中?谢谢。

where could I place code to be run after every commit I make with mercurial? Specifically, I would like to maintain a file called latest inside the .hg folder in the root of my project - that file will hold the revision number and hash code for the most recent commit. On that same topic, how can I get those in python?

# get mercurial version hash
ver = ?

# get mercurial revision number
rev = ?

# is there a shortcut to this folder through mercurial?
f = open('/path/to/.hg/latest', 'w')
f.write('ver=%s\nrev=%d' % ( str(ver), int(rev) ) )
f.close

EDIT:
I was able to accomplish the above with hooks (in .hg/hgrc):

[hooks]
precommit= echo node=`hg tip --template {node}` > tip && echo rev=`hg tip --template {rev}` >> tip && hg add tip

The file with the tip info is created successfully, but I would also like to add it to the current commit with hg add tip, which is where the mercurial process gets stuck waiting for the lock apparently held by the pending commit. Is there a way to work around it such that the file created during/pre commit is added to it? thanks.

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

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

发布评论

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

评论(1

呢古 2024-08-26 16:10:47

http://hgbook.red-bean.com/ read/handling-repository-events-with-hooks.html

具体来说,您似乎想要提交钩子,其中有一个教程,当然

听起来您真正想要的是 hg 提示

http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html

specifically you seem to want the commit hook which there is a tutorial for

of course it sounds like what you really want is hg tip

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