Mercurial - 我想添加一些在提交后运行的自定义代码
我可以在哪里放置每次使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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