Mercurial > hg-stable
changeset 2266:3f7692b0ff13
hooks: add preupdate and update hooks.
preupdate run before working dir updated. can prevent update.
update run after working dir updated.
author | Vadim Gelfer <vadim.gelfer@gmail.com> |
---|---|
date | Thu, 11 May 2006 10:14:48 -0700 |
parents | 3e4a1a0739c2 |
children | 8cb77698f5fd |
files | doc/hgrc.5.txt mercurial/localrepo.py tests/test-hook tests/test-hook.out |
diffstat | 4 files changed, 32 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/hgrc.5.txt Thu May 11 09:44:11 2006 -0700 +++ b/doc/hgrc.5.txt Thu May 11 10:14:48 2006 -0700 @@ -219,10 +219,20 @@ commit to proceed. Non-zero status will cause the transaction to be rolled back. ID of changeset is in $HG_NODE. Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2. + preupdate;; + Run before updating the working directory. Exit status 0 allows + the update to proceed. Non-zero status will prevent the update. + Changeset ID of first new parent is in $HG_PARENT1. If merge, ID + of second new parent is in $HG_PARENT2. tag;; Run after a tag is created. ID of tagged changeset is in $HG_NODE. Name of tag is in $HG_TAG. Tag is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0. + update;; + Run after updating the working directory. Changeset ID of first + new parent is in $HG_PARENT1. If merge, ID of second new parent + is in $HG_PARENT2. If update succeeded, $HG_ERROR=0. If update + failed (e.g. because conflicts not resolved), $HG_ERROR=1. In earlier releases, the names of hook environment variables did not have a "HG_" prefix. These unprefixed names are still provided in
--- a/mercurial/localrepo.py Thu May 11 09:44:11 2006 -0700 +++ b/mercurial/localrepo.py Thu May 11 10:14:48 2006 -0700 @@ -1592,6 +1592,7 @@ if allow and not forcemerge: if modified or added or removed: raise util.Abort(_("outstanding uncommitted changes")) + if not forcemerge and not force: for f in unknown: if f in m2: @@ -1765,6 +1766,13 @@ return 1 branch_merge = True + xp1 = hex(p1) + xp2 = hex(p2) + if p2 == nullid: xxp2 = '' + else: xxp2 = xp2 + + self.hook('preupdate', throw=True, parent1=xp1, parent2=xxp2) + # get the files we don't need to change files = get.keys() files.sort() @@ -1785,8 +1793,6 @@ failedmerge = [] files = merge.keys() files.sort() - xp1 = hex(p1) - xp2 = hex(p2) for f in files: self.ui.status(_("merging %s\n") % f) my, other, flag = merge[f] @@ -1850,6 +1856,7 @@ self.ui.status(_("There are unresolved merges with" " locally modified files.\n")) + self.hook('update', parent1=xp1, parent2=xxp2, error=int(err)) return err def merge3(self, fn, my, other, p1, p2):
--- a/tests/test-hook Thu May 11 09:44:11 2006 -0700 +++ b/tests/test-hook Thu May 11 10:14:48 2006 -0700 @@ -61,6 +61,14 @@ hg commit -m 'fail' -d '4 0' hg -q tip +# preupdate hook can prevent update +echo 'preupdate = echo preupdate hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc +hg update 1 + +# update hook +echo 'update = echo update hook: p1=$HG_PARENT1 p2=$HG_PARENT2 err=$HG_ERROR' >> .hg/hgrc +hg update + # prechangegroup hook can prevent incoming changes cd ../b hg -q tip
--- a/tests/test-hook.out Thu May 11 09:44:11 2006 -0700 +++ b/tests/test-hook.out Thu May 11 10:14:48 2006 -0700 @@ -62,6 +62,11 @@ precommit.forbid hook abort: precommit.forbid hook exited with status 1 4:4f92e785b90a +preupdate hook: p1=b702efe9688826e3a91283852b328b84dbf37bc2 p2= +0 files updated, 0 files merged, 2 files removed, 0 files unresolved +preupdate hook: p1=4f92e785b90ae8995dfe156e39dd4fbc3b346a24 p2= +update hook: p1=4f92e785b90ae8995dfe156e39dd4fbc3b346a24 p2= err=0 +2 files updated, 0 files merged, 0 files removed, 0 files unresolved 3:4c52fb2e4022 prechangegroup.forbid hook pulling from ../a