Mercurial - I want to add some custom code to run after commit

where can I put the code that will be run after every commit that I make with the mercury? In particular, I would like to save the file with the last name inside the .hg folder in the root of my project - this file will contain the version number and hash code for the last commit. On the same topic, how can I get them 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

, hg add tip, , , . , , /pre commit, ? .

+3

Source: https://habr.com/ru/post/1730837/


All Articles