using external commit hooks to kick off build

Christian Ebert blacktrash at gmx.net
Wed Mar 28 06:12:53 CDT 2007


Hi Sean,

* Sean on Wednesday, March 28, 2007 at 18:16:12 +1000:
> I am trying to do a little post commit automation using commit hooks.
> 
> I can pick up the %HG_NODE% from the environment (windows) all right,
> but, how do I then retrieve a list of pathname\file.ext that were
> committed so that I can do stuff ?
> 
> The following works in my external .cmd file:
> 
> hg log --template {files} -r %HG_NODE%

Might break on filenames with spaces.

> but I am sure there must be a way to pass the file directly to the
> external script rather than have to invoke hg again like this ?

I'd use a python hook, something along those lines (see
man 5 hgrc), should be safer and faster:

hgrc (adapt "hghooks", "buildhook(.py)"):

#v+
[hooks]
commit =
commit.build = python:hghooks.buildhook.mybuild
#v-

buildhook.py:

#v+
from mercurial.node import *

def mybuild(ui=None, repo=None, hooktype='', **args):
    if hooktype != 'commit':
        return True
    files = repo.changelog.read(bin(args['node']))[3]

    # perhaps do a check for removed files and symlinks here
    if files:
        # do stuff with files
#v-
        

c
-- 
_B A U S T E L L E N_ lesen! --->> <http://www.blacktrash.org/baustellen.html>


More information about the Mercurial mailing list