Show More
@@ -1,179 +1,179 | |||
|
1 | 1 | #!/bin/sh |
|
2 | 2 | |
|
3 | 3 | # commit hooks can see env vars |
|
4 | 4 | hg init a |
|
5 | 5 | cd a |
|
6 | 6 | echo "[hooks]" > .hg/hgrc |
|
7 | 7 | echo 'commit = echo commit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc |
|
8 | 8 | echo 'commit.b = echo commit hook b' >> .hg/hgrc |
|
9 | 9 | echo 'precommit = echo precommit hook: p1=$HG_PARENT1 p2=$HG_PARENT2' >> .hg/hgrc |
|
10 | 10 | echo 'pretxncommit = echo pretxncommit hook: n=$HG_NODE p1=$HG_PARENT1 p2=$HG_PARENT2; hg -q tip' >> .hg/hgrc |
|
11 | 11 | echo a > a |
|
12 | 12 | hg add a |
|
13 | 13 | hg commit -m a -d "1000000 0" |
|
14 | 14 | |
|
15 | 15 | hg clone . ../b |
|
16 | 16 | cd ../b |
|
17 | 17 | |
|
18 | 18 | # changegroup hooks can see env vars |
|
19 | 19 | echo '[hooks]' > .hg/hgrc |
|
20 | 20 | echo 'prechangegroup = echo prechangegroup hook' >> .hg/hgrc |
|
21 | 21 | echo 'changegroup = echo changegroup hook: n=$HG_NODE' >> .hg/hgrc |
|
22 | 22 | echo 'incoming = echo incoming hook: n=$HG_NODE' >> .hg/hgrc |
|
23 | 23 | |
|
24 | 24 | # pretxncommit and commit hooks can see both parents of merge |
|
25 | 25 | cd ../a |
|
26 | 26 | echo b >> a |
|
27 | 27 | hg commit -m a1 -d "1 0" |
|
28 | 28 | hg update -C 0 |
|
29 | 29 | echo b > b |
|
30 | 30 | hg add b |
|
31 | 31 | hg commit -m b -d '1 0' |
|
32 | 32 | hg update -m 1 |
|
33 | 33 | hg commit -m merge -d '2 0' |
|
34 | 34 | |
|
35 | 35 | cd ../b |
|
36 | 36 | hg pull ../a |
|
37 | 37 | |
|
38 | 38 | # tag hooks can see env vars |
|
39 | 39 | cd ../a |
|
40 | 40 | echo 'pretag = echo pretag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc |
|
41 | 41 | echo 'tag = echo tag hook: t=$HG_TAG n=$HG_NODE l=$HG_LOCAL' >> .hg/hgrc |
|
42 | 42 | hg tag -d '3 0' a |
|
43 | 43 | hg tag -l la |
|
44 | 44 | |
|
45 | 45 | # pretag hook can forbid tagging |
|
46 | 46 | echo 'pretag.forbid = echo pretag.forbid hook; exit 1' >> .hg/hgrc |
|
47 | 47 | hg tag -d '4 0' fa |
|
48 | 48 | hg tag -l fla |
|
49 | 49 | |
|
50 | 50 | # pretxncommit hook can see changeset, can roll back txn, changeset |
|
51 | 51 | # no more there after |
|
52 | 52 | echo 'pretxncommit.forbid = echo pretxncommit.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc |
|
53 | 53 | echo z > z |
|
54 | 54 | hg add z |
|
55 | 55 | hg -q tip |
|
56 | 56 | hg commit -m 'fail' -d '4 0' |
|
57 | 57 | hg -q tip |
|
58 | 58 | |
|
59 | 59 | # precommit hook can prevent commit |
|
60 | 60 | echo 'precommit.forbid = echo precommit.forbid hook; exit 1' >> .hg/hgrc |
|
61 | 61 | hg commit -m 'fail' -d '4 0' |
|
62 | 62 | hg -q tip |
|
63 | 63 | |
|
64 | 64 | # prechangegroup hook can prevent incoming changes |
|
65 | 65 | cd ../b |
|
66 | 66 | hg -q tip |
|
67 | 67 | echo '[hooks]' > .hg/hgrc |
|
68 | 68 | echo 'prechangegroup.forbid = echo prechangegroup.forbid hook; exit 1' >> .hg/hgrc |
|
69 | 69 | hg pull ../a |
|
70 | 70 | |
|
71 | 71 | # pretxnchangegroup hook can see incoming changes, can roll back txn, |
|
72 | 72 | # incoming changes no longer there after |
|
73 | 73 | echo '[hooks]' > .hg/hgrc |
|
74 | 74 | echo 'pretxnchangegroup.forbid = echo pretxnchangegroup.forbid hook: tip=`hg -q tip`; exit 1' >> .hg/hgrc |
|
75 | 75 | hg pull ../a |
|
76 | 76 | hg -q tip |
|
77 | 77 | |
|
78 | 78 | # outgoing hooks can see env vars |
|
79 | 79 | rm .hg/hgrc |
|
80 | 80 | echo '[hooks]' > ../a/.hg/hgrc |
|
81 | 81 | echo 'preoutgoing = echo preoutgoing hook: s=$HG_SOURCE' >> ../a/.hg/hgrc |
|
82 | 82 | echo 'outgoing = echo outgoing hook: n=$HG_NODE s=$HG_SOURCE' >> ../a/.hg/hgrc |
|
83 | 83 | hg pull ../a |
|
84 | 84 | hg undo |
|
85 | 85 | |
|
86 | 86 | # preoutgoing hook can prevent outgoing changes |
|
87 | 87 | echo 'preoutgoing.forbid = echo preoutgoing.forbid hook; exit 1' >> ../a/.hg/hgrc |
|
88 | 88 | hg pull ../a |
|
89 | 89 | |
|
90 | 90 | cat > hooktests.py <<EOF |
|
91 | 91 | from mercurial import util |
|
92 | 92 | |
|
93 | 93 | uncallable = 0 |
|
94 | 94 | |
|
95 | 95 | def printargs(args): |
|
96 | 96 | args.pop('ui', None) |
|
97 | 97 | args.pop('repo', None) |
|
98 | 98 | a = list(args.items()) |
|
99 | 99 | a.sort() |
|
100 | 100 | print 'hook args:' |
|
101 | 101 | for k, v in a: |
|
102 | 102 | print ' ', k, v |
|
103 | 103 | return True |
|
104 | 104 | |
|
105 | 105 | def passhook(**args): |
|
106 | 106 | printargs(args) |
|
107 | 107 | return True |
|
108 | 108 | |
|
109 | 109 | def failhook(**args): |
|
110 | 110 | printargs(args) |
|
111 | 111 | |
|
112 | 112 | class LocalException(Exception): |
|
113 | 113 | pass |
|
114 | 114 | |
|
115 | 115 | def raisehook(**args): |
|
116 | 116 | raise LocalException('exception from hook') |
|
117 | 117 | |
|
118 | 118 | def aborthook(**args): |
|
119 | 119 | raise util.Abort('raise abort from hook') |
|
120 | 120 | |
|
121 | 121 | def brokenhook(**args): |
|
122 | 122 | return 1 + {} |
|
123 | 123 | |
|
124 | 124 | class container: |
|
125 | 125 | unreachable = 1 |
|
126 | 126 | EOF |
|
127 | 127 | |
|
128 | 128 | echo '# test python hooks' |
|
129 |
PYTHONPATH=" |
|
|
129 | PYTHONPATH="`pwd`:$PYTHONPATH" | |
|
130 | 130 | export PYTHONPATH |
|
131 | 131 | |
|
132 | 132 | echo '[hooks]' > ../a/.hg/hgrc |
|
133 | 133 | echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc |
|
134 | 134 | hg pull ../a 2>&1 | grep 'raised an exception' |
|
135 | 135 | |
|
136 | 136 | echo '[hooks]' > ../a/.hg/hgrc |
|
137 | 137 | echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc |
|
138 | 138 | hg pull ../a 2>&1 | grep 'raised an exception' |
|
139 | 139 | |
|
140 | 140 | echo '[hooks]' > ../a/.hg/hgrc |
|
141 | 141 | echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc |
|
142 | 142 | hg pull ../a |
|
143 | 143 | |
|
144 | 144 | echo '[hooks]' > ../a/.hg/hgrc |
|
145 | 145 | echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc |
|
146 | 146 | hg pull ../a |
|
147 | 147 | |
|
148 | 148 | echo '[hooks]' > ../a/.hg/hgrc |
|
149 | 149 | echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc |
|
150 | 150 | hg pull ../a |
|
151 | 151 | |
|
152 | 152 | echo '[hooks]' > ../a/.hg/hgrc |
|
153 | 153 | echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc |
|
154 | 154 | hg pull ../a |
|
155 | 155 | |
|
156 | 156 | echo '[hooks]' > ../a/.hg/hgrc |
|
157 | 157 | echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc |
|
158 | 158 | hg pull ../a |
|
159 | 159 | |
|
160 | 160 | echo '[hooks]' > ../a/.hg/hgrc |
|
161 | 161 | echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc |
|
162 | 162 | hg pull ../a |
|
163 | 163 | |
|
164 | 164 | echo '[hooks]' > ../a/.hg/hgrc |
|
165 | 165 | echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc |
|
166 | 166 | hg pull ../a |
|
167 | 167 | |
|
168 | 168 | echo '[hooks]' > ../a/.hg/hgrc |
|
169 | 169 | echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc |
|
170 | 170 | hg pull ../a |
|
171 | 171 | |
|
172 | 172 | echo '# make sure --traceback works' |
|
173 | 173 | echo '[hooks]' > .hg/hgrc |
|
174 | 174 | echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc |
|
175 | 175 | |
|
176 | 176 | echo a >> a |
|
177 | 177 | hg --traceback commit -A -m a 2>&1 | grep '^Traceback' |
|
178 | 178 | |
|
179 | 179 | exit 0 |
General Comments 0
You need to be logged in to leave comments.
Login now