mercurial - 我想添加一些自定义代码,以便在提交后运行

sa1*_*125 3 python mercurial customization automation

在我用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
Run Code Online (Sandbox Code Playgroud)

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

[hooks]
precommit= echo node=`hg tip --template {node}` > tip && echo rev=`hg tip --template {rev}` >> tip && hg add tip
Run Code Online (Sandbox Code Playgroud)

带有提示信息的文件已成功创建,但我还想将其添加到当前提交中hg add tip,这是mercurial进程卡在等待挂起提交显然持有的锁的位置.有没有办法解决它,以便在/ pre commit期间创建的文件被添加到它?谢谢.

jk.*_*jk. 5

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

特别是你似乎想要有一个教程的提交钩子

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