Question about pretxnchangegroup
Doug Simon
Doug.Simon at sun.com
Fri Nov 7 16:02:11 CST 2008
On Nov 7, 2008, at 11:47 AM, Maxim Vuets wrote:
> On 11/6/08, Doug Simon <Doug.Simon at sun.com> wrote:
>
>> I want to use the pretxnchangegroup hook to verify that pushes to a
>> shared repo do not break the build.
>
> As for me, it looks like you have chosen a wrong way to verify a
> commit,
> because every push will take some time.
> I think it is better to have two repos: first one for development
> purposes,
> second one for stable and tested versions of a product.
This is exactly what I have: a 'gate' repo that is push-only and a
'shared' repo that is pull-only. When developers push to 'gate', the
push tests run and if they succeed, then a automatic push is done from
'gate' to 'shared'. I'm using various hooks to enforce the push-only
and pull-only restrictions.
>> The problem is that the test requires accessing the state
>> that would be pushed.
>> As far as I understand it, the working directory in the destination
>> repo is not updated
>> before my pretxnchangegroup hook executes which means I have
>> incorporate an explicit
>> 'hg update' in my hook. Assuming that this is correct, should I run
>> another 'hg update'
>> at the end of my hook in the case that the test fails? Otherwise, the
>> working directory
>> would now reflects changeset(s) that no longer exist, right?
>
> Just try it (:
>
> tmp$ hg init hgtest
> tmp$ cd hgtest
> hgtest$ touch file
> hgtest$ hg ci -qAm init
> hgtest$ echo -e "[hooks]\\npretxnchangegroup=sh -c 'hg -R $(pwd) log
> --style=compact; exit 1'\\n" >>.hg/hgrc
> hgtest$ cd ..
> tmp$ hg clone hgtest hgtest-slave
> tmp$ cd hgtest-slave
> hgtest-slave$ echo something >>file
> hgtest-slave$ hg ci -m 'my change'
> hgtest-slave$ hg push -q
> 1[tip] 7d3d801f7ace 2008-11-07 21:32 +0200 maxim
> my change
>
> 0 47cf95ae6ec5 2008-11-07 21:26 +0200 maxim
> init
>
> transaction abort!
> rollback completed
> abort: pretxnchangegroup hook exited with status 1
>
> ---you see that the state of a repo during pretxnchangegroup hook
> reflectes commits that are commiting now.
> So just call some script which will do "hg up -C", make test build,
> perform tests and as a result return 0 or non-0 for success and
> failure respectively. I think there are no reasons to worry about
> state of working dir after not successful commit (assuming that
> this repo is just used like a common storage).
Actually, this contradicts the following statement from the HG book (http://hgbook.red-bean.com/hgbookch10.html#x14-24600010.9.9
):
"It [the hook script] must also not modify the working directory."
I learnt this one the hard way. If you do indeed do a 'hg update' on
the working directory of 'gate' during a push that fails, 'gate' is
pretty much corrupted. Any subsequent hg commands performed in 'gate'
fail with error messages about unknown node identifiers.
So now, I have my hook script create another clone of 'gate' with the
pushed changes and do the testing there.
-Doug
More information about the Mercurial
mailing list