[PATCH] [issue1602] Make local clone activate preoutgoing and outgoing hooks

Fred Wulff frew at cs.stanford.edu
Fri Apr 17 18:45:39 CDT 2009


# HG changeset patch
# User Fred Wulff <frew at cs.stanford.edu>
# Date 1240011283 25200
# Node ID 1f5c062a7ab40a02b852f2cc5787384efd4eccaf
# Parent  fc78313cba53d982b34a1516b81348a8b89bd867
Add (pre)outgoing hooks for local clones.

diff -r fc78313cba53 -r 1f5c062a7ab4 mercurial/hg.py
--- a/mercurial/hg.py	Sat Apr 04 20:19:51 2009 -0500
+++ b/mercurial/hg.py	Fri Apr 17 16:34:43 2009 -0700
@@ -168,6 +168,7 @@
                 copy = False
 
         if copy:
+            src_repo.hook('preoutgoing', throw=True, source='clone')
             hgdir = os.path.realpath(os.path.join(dest, ".hg"))
             if not os.path.exists(dest):
                 os.mkdir(dest)
@@ -199,7 +200,7 @@
             # we need to re-init the repo after manually copying the data
             # into it
             dest_repo = repository(ui, dest)
-
+            src_repo.hook('outgoing', source='clone', node='0'*40)
         else:
             try:
                 dest_repo = repository(ui, dest, create=True)
diff -r fc78313cba53 -r 1f5c062a7ab4 tests/test-hook
--- a/tests/test-hook	Sat Apr 04 20:19:51 2009 -0500
+++ b/tests/test-hook	Fri Apr 17 16:34:43 2009 -0700
@@ -107,6 +107,19 @@
 echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> ../a/.hg/hgrc
 hg pull ../a
 
+# outgoing hooks work for local clones
+cd ..
+echo '[hooks]' > a/.hg/hgrc
+echo 'preoutgoing = python ../printenv.py preoutgoing' >> a/.hg/hgrc
+echo 'outgoing = python ../printenv.py outgoing' >> a/.hg/hgrc
+hg clone a c
+rm -rf c
+
+# preoutgoing hook can prevent outgoing changes for local clones
+echo 'preoutgoing.forbid = python ../printenv.py preoutgoing.forbid 1' >> a/.hg/hgrc
+hg clone a zzz
+cd b
+
 cat > hooktests.py <<EOF
 from mercurial import util
 
diff -r fc78313cba53 -r 1f5c062a7ab4 tests/test-hook.out
--- a/tests/test-hook.out	Sat Apr 04 20:19:51 2009 -0500
+++ b/tests/test-hook.out	Fri Apr 17 16:34:43 2009 -0700
@@ -106,6 +106,13 @@
 pulling from ../a
 searching for changes
 abort: preoutgoing.forbid hook exited with status 1
+preoutgoing hook: HG_SOURCE=clone 
+outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone 
+updating working directory
+3 files updated, 0 files merged, 0 files removed, 0 files unresolved
+preoutgoing hook: HG_SOURCE=clone 
+preoutgoing.forbid hook: HG_SOURCE=clone 
+abort: preoutgoing.forbid hook exited with status 1
 # test python hooks
 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
 error: preoutgoing.raise hook raised an exception: exception from hook


More information about the Mercurial-devel mailing list