[PATCH 1 of 8] update: add pre-applyupdate hook

Durham Goode durham at fb.com
Mon May 6 14:36:51 CDT 2013


# HG changeset patch
# User Durham Goode <durham at fb.com>
# Date 1367429725 25200
#      Wed May 01 10:35:25 2013 -0700
# Node ID 4ddd3b2b3407fe3344fd800ea11ab377a34b8ae6
# Parent  bfd128c3fbb830b332fec89eddc82b0b9aa31b64
update: add pre-applyupdate hook

This adds a hook after update actions are calculated but before they are
applied. This allows an extension to download any data necessary for the
update if necessary.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -477,6 +477,11 @@
     removed = len(removeactions)
     actions = [a for a in actions if a[1] not in 'gr']
 
+    repo.hook('pre-applyupdate',
+              manifest=mctx.manifest(),
+              actions=workeractions,
+              throw=True)
+
     hgsub = [a[1] for a in workeractions if a[0] == '.hgsubstate']
     if hgsub and hgsub[0] == 'r':
         subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
diff --git a/tests/test-hook.t b/tests/test-hook.t
--- a/tests/test-hook.t
+++ b/tests/test-hook.t
@@ -469,6 +469,26 @@
   adding remote bookmark quux
   (run 'hg update' to get a working copy)
 
+pre-applyupdate hook
+
+  $ echo '[hooks]' > .hg/hgrc
+  $ echo 'pre-applyupdate.success = python:hooktests.passhook' >> .hg/hgrc
+  $ hg up .
+  hook args:
+    actions []
+    hooktype pre-applyupdate
+    manifest {'a': '*'} (glob)
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+pre-applyupdate hook can fail update
+
+  $ echo '[hooks]' > .hg/hgrc
+  $ echo 'pre-applyupdate.fail = python:hooktests.aborthook' >> .hg/hgrc
+  $ hg up 0
+  error: pre-applyupdate.fail hook failed: raise abort from hook
+  abort: raise abort from hook
+  [255]
+
 make sure --traceback works
 
   $ echo '[hooks]' > .hg/hgrc


More information about the Mercurial-devel mailing list