Mercurial > hg-stable
changeset 1734:9488d53233b5
tests for new hooks. fix things i found when writing tests.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 16 Feb 2006 09:56:31 -0800 |
parents | 6d288d8c3ca6 |
children | 791405fe9991 |
files | doc/hgrc.5.txt mercurial/commands.py tests/test-hook |
diffstat | 3 files changed, 72 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/hgrc.5.txt Thu Feb 16 09:09:45 2006 -0800 +++ b/doc/hgrc.5.txt Thu Feb 16 09:56:31 2006 -0800 @@ -178,7 +178,7 @@ but before the transaction has been committed. Changegroup is visible to hook program. This lets you validate incoming changes before accepting them. Passed the ID of the first new changeset - in $NODE. Exit status 0 allows the transaction to commit. + in $HG_NODE. Exit status 0 allows the transaction to commit. Non-zero status will cause the transaction to be rolled back and the push, pull or unbundle will fail. pretxncommit;;
--- a/mercurial/commands.py Thu Feb 16 09:09:45 2006 -0800 +++ b/mercurial/commands.py Thu Feb 16 09:56:31 2006 -0800 @@ -2117,7 +2117,7 @@ raise util.Abort(_("%s cannot be used in a tag name") % repr(c)) repo.hook('pretag', throw=True, node=r, tag=name, - local=not not opts['local']) + local=int(not not opts['local'])) if opts['local']: repo.opener("localtags", "a").write("%s %s\n" % (r, name))
--- a/tests/test-hook Thu Feb 16 09:09:45 2006 -0800 +++ b/tests/test-hook Thu Feb 16 09:56:31 2006 -0800 @@ -1,10 +1,76 @@ #!/bin/sh -hg init +# commit hooks can see env vars +hg init a +cd a echo "[hooks]" > .hg/hgrc -echo 'precommit = echo precommit hook' >> .hg/hgrc -echo 'commit = echo commit hook: $NODE' >> .hg/hgrc +echo 'commit = echo commit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc echo 'commit.b = echo commit hook b' >> .hg/hgrc +echo 'precommit = echo precommit hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc +echo 'pretxncommit = echo pretxncommit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2; hg -q tip' >> .hg/hgrc echo a > a hg add a -hg commit -m "test" -d "0 0" +hg commit -m a -d "0 0" + +hg clone . ../b +cd ../b + +# changegroup hooks can see env vars +echo '[hooks]' > .hg/hgrc +echo 'prechangegroup = echo prechangegroup hook' >> .hg/hgrc +echo 'changegroup = echo changegroup hook: n=$HG_NODE' >> .hg/hgrc +echo 'incoming = echo incoming hook: n=$HG_NODE' >> .hg/hgrc + +# pretxncommit and commit hooks can see both parents of merge +cd ../a +echo b >> a +hg commit -m a1 -d "1 0" +hg update -C 0 +echo b > b +hg add b +hg commit -m b -d '1 0' +hg update -m 1 +hg commit -m merge -d '2 0' + +cd ../b +hg pull ../a + +# tag hooks can see env vars +cd ../a +echo 'pretag = echo pretag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc +echo 'tag = echo tag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc +hg tag -d '3 0' a +hg tag -l la + +# pretag hook can forbid tagging +echo 'pretag.forbid = echo pretag.forbid hook; exit 1' >> .hg/hgrc +hg tag -d '4 0' fa +hg tag -l fla + +# pretxncommit hook can see changeset, can roll back txn, changeset +# no more there after +echo 'pretxncommit.forbid = echo pretxncommit.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc +echo z > z +hg add z +hg -q tip +hg commit -m 'fail' -d '4 0' +hg -q tip + +# precommit hook can prevent commit +echo 'precommit.forbid = echo precommit.forbid hook; exit 1' >> .hg/hgrc +hg commit -m 'fail' -d '4 0' +hg -q tip + +# prechangegroup hook can prevent incoming changes +cd ../b +hg -q tip +echo '[hooks]' > .hg/hgrc +echo 'prechangegroup.forbid = echo prechangegroup.forbid hook; exit 1' >> .hg/hgrc +hg pull ../a + +# pretxnchangegroup hook can see incoming changes, can roll back txn, +# incoming changes no longer there after +echo '[hooks]' > .hg/hgrc +echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc +hg pull ../a +hg -q tip