Show More
@@ -0,0 +1,117 b'' | |||
|
1 | Verify that pending changesets are seen by pretxn* hooks but not by other | |
|
2 | processes that access the destination repo while the hooks are running. | |
|
3 | ||
|
4 | The hooks (python and external) both reject changesets after some think time, | |
|
5 | during which another process runs pull. Each hook creates a file ('notify') to | |
|
6 | indicate to the controlling process that it is running; the process removes the | |
|
7 | file to indicate the hook can terminate. | |
|
8 | ||
|
9 | init env vars | |
|
10 | ||
|
11 | $ d=`pwd` | |
|
12 | $ maxwait=20 | |
|
13 | ||
|
14 | utility to run the test - start a push in the background and run pull | |
|
15 | ||
|
16 | $ dotest() { | |
|
17 | > rm -f notify | |
|
18 | > printf 'push '; hg -R child-push tip --template '{node}\n' | |
|
19 | > hg -R child-push -q push > push.out 2>&1 & | |
|
20 | > | |
|
21 | > # wait for hook to create the notify file | |
|
22 | > i=$maxwait | |
|
23 | > while [ ! -f notify -a $i != 0 ]; do | |
|
24 | > sleep 1 | |
|
25 | > i=`expr $i - 1` | |
|
26 | > done | |
|
27 | > | |
|
28 | > # run pull | |
|
29 | > hg -R child-pull -q pull | |
|
30 | > rc=$? | |
|
31 | > | |
|
32 | > # tell hook to finish; notify should exist. | |
|
33 | > rm notify | |
|
34 | > wait | |
|
35 | > | |
|
36 | > cat push.out | |
|
37 | > printf 'pull '; hg -R child-pull tip --template '{node}\n' | |
|
38 | > return $rc | |
|
39 | > } | |
|
40 | ||
|
41 | python hook | |
|
42 | ||
|
43 | $ cat <<EOF > reject.py | |
|
44 | > import os, time | |
|
45 | > from mercurial import ui, localrepo | |
|
46 | > def rejecthook(ui, repo, hooktype, node, **opts): | |
|
47 | > ui.write('hook %s\\n' % repo['tip'].hex()) | |
|
48 | > # create the notify file so caller knows we're running | |
|
49 | > fpath = os.path.join('$d', 'notify') | |
|
50 | > f = open(fpath, 'w') | |
|
51 | > f.close() | |
|
52 | > # wait for ack - caller should delete the notify file | |
|
53 | > i = $maxwait | |
|
54 | > while os.path.exists(fpath) and i > 0: | |
|
55 | > time.sleep(1) | |
|
56 | > i -= 1 | |
|
57 | > return True # reject the changesets | |
|
58 | > EOF | |
|
59 | ||
|
60 | external hook | |
|
61 | ||
|
62 | $ cat <<EOF > reject.sh | |
|
63 | > #! /bin/sh | |
|
64 | > printf 'hook '; hg tip --template '{node}\\n' | |
|
65 | > # create the notify file so caller knows we're running | |
|
66 | > fpath=$d/notify | |
|
67 | > touch \$fpath | |
|
68 | > # wait for ack - caller should delete the notify file | |
|
69 | > i=$maxwait | |
|
70 | > while [ -f \$fpath -a \$i != 0 ]; do | |
|
71 | > sleep 1 | |
|
72 | > i=\`expr \$i - 1\` | |
|
73 | > done | |
|
74 | > exit 1 # reject the changesets | |
|
75 | > EOF | |
|
76 | $ chmod +x reject.sh | |
|
77 | ||
|
78 | create repos | |
|
79 | ||
|
80 | $ hg init parent | |
|
81 | $ hg clone -q parent child-push | |
|
82 | $ hg clone -q parent child-pull | |
|
83 | $ echo a > child-push/a | |
|
84 | $ hg -R child-push add child-push/a | |
|
85 | $ hg -R child-push commit -m a -d '1000000 0' | |
|
86 | ||
|
87 | test python hook | |
|
88 | ||
|
89 | $ cat <<EOF > parent/.hg/hgrc | |
|
90 | > [extensions] | |
|
91 | > reject = $d/reject.py | |
|
92 | > [hooks] | |
|
93 | > pretxnchangegroup = python:reject.rejecthook | |
|
94 | > EOF | |
|
95 | ||
|
96 | $ dotest | |
|
97 | push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
98 | hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
99 | transaction abort! | |
|
100 | rollback completed | |
|
101 | abort: pretxnchangegroup hook failed | |
|
102 | pull 0000000000000000000000000000000000000000 | |
|
103 | ||
|
104 | test external hook | |
|
105 | ||
|
106 | $ cat <<EOF > parent/.hg/hgrc | |
|
107 | > [hooks] | |
|
108 | > pretxnchangegroup = $d/reject.sh | |
|
109 | > EOF | |
|
110 | ||
|
111 | $ dotest | |
|
112 | push 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
113 | hook 29b62aeb769fdf78d8d9c5f28b017f76d7ef824b | |
|
114 | transaction abort! | |
|
115 | rollback completed | |
|
116 | abort: pretxnchangegroup hook exited with status 1 | |
|
117 | pull 0000000000000000000000000000000000000000 |
General Comments 0
You need to be logged in to leave comments.
Login now