【问题标题】:mercurial - I want to add some custom code to be run after commitmercurial - 我想添加一些自定义代码以在提交后运行
【发布时间】: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


    【解决方案1】:

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

    具体来说,您似乎想要有教程的提交钩子

    当然听起来你真正想要的是hg tip

    【讨论】:

    • hg 提示并不是最新的提交(如果你拉),但它应该足以满足操作
    • 是的,不清楚他们是否想要小费,但它可能是一个选项,所以我提到了它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-02
    • 2017-06-05
    • 2017-06-11
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-02
    相关资源
    最近更新 更多