【发布时间】:2011-01-11 15:48:47
【问题描述】:
每次使用 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 add tip 的当前提交中,这是 mercurial 进程卡住等待显然由未决提交持有的锁的地方。有没有办法解决它,以便将在提交期间/提交前创建的文件添加到其中?谢谢。
【问题讨论】:
标签: python mercurial automation customization