##// END OF EJS Templates
tests: make test-hook.t output more stable
Mads Kiilerich -
r18377:56b80530 default
parent child Browse files
Show More
@@ -1,644 +1,644 b''
1 1 commit hooks can see env vars
2 2
3 3 $ hg init a
4 4 $ cd a
5 5 $ cat > .hg/hgrc <<EOF
6 6 > [hooks]
7 7 > commit = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" commit"
8 8 > commit.b = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" commit.b"
9 9 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= python \"$TESTDIR/printenv.py\" precommit"
10 10 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= python \"$TESTDIR/printenv.py\" pretxncommit"
11 11 > pretxncommit.tip = hg -q tip
12 12 > pre-identify = python "$TESTDIR/printenv.py" pre-identify 1
13 13 > pre-cat = python "$TESTDIR/printenv.py" pre-cat
14 14 > post-cat = python "$TESTDIR/printenv.py" post-cat
15 15 > EOF
16 16 $ echo a > a
17 17 $ hg add a
18 18 $ hg commit -m a
19 19 precommit hook: HG_PARENT1=0000000000000000000000000000000000000000
20 20 pretxncommit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000 HG_PENDING=$TESTTMP/a
21 21 0:cb9a9f314b8b
22 22 commit hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
23 23 commit.b hook: HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PARENT1=0000000000000000000000000000000000000000
24 24
25 25 $ hg clone . ../b
26 26 updating to branch default
27 27 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
28 28 $ cd ../b
29 29
30 30 changegroup hooks can see env vars
31 31
32 32 $ cat > .hg/hgrc <<EOF
33 33 > [hooks]
34 34 > prechangegroup = python "$TESTDIR/printenv.py" prechangegroup
35 35 > changegroup = python "$TESTDIR/printenv.py" changegroup
36 36 > incoming = python "$TESTDIR/printenv.py" incoming
37 37 > EOF
38 38
39 39 pretxncommit and commit hooks can see both parents of merge
40 40
41 41 $ cd ../a
42 42 $ echo b >> a
43 43 $ hg commit -m a1 -d "1 0"
44 44 precommit hook: HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
45 45 pretxncommit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
46 46 1:ab228980c14d
47 47 commit hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
48 48 commit.b hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
49 49 $ hg update -C 0
50 50 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
51 51 $ echo b > b
52 52 $ hg add b
53 53 $ hg commit -m b -d '1 0'
54 54 precommit hook: HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
55 55 pretxncommit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b HG_PENDING=$TESTTMP/a
56 56 2:ee9deb46ab31
57 57 commit hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
58 58 commit.b hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
59 59 created new head
60 60 $ hg merge 1
61 61 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
62 62 (branch merge, don't forget to commit)
63 63 $ hg commit -m merge -d '2 0'
64 64 precommit hook: HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
65 65 pretxncommit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd HG_PENDING=$TESTTMP/a
66 66 3:07f3376c1e65
67 67 commit hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
68 68 commit.b hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
69 69
70 70 test generic hooks
71 71
72 72 $ hg id
73 73 pre-identify hook: HG_ARGS=id HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None} HG_PATS=[]
74 74 warning: pre-identify hook exited with status 1
75 75 [1]
76 76 $ hg cat b
77 77 pre-cat hook: HG_ARGS=cat b HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': ''} HG_PATS=['b']
78 78 b
79 79 post-cat hook: HG_ARGS=cat b HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': ''} HG_PATS=['b'] HG_RESULT=0
80 80
81 81 $ cd ../b
82 82 $ hg pull ../a
83 83 pulling from ../a
84 84 searching for changes
85 85 prechangegroup hook: HG_SOURCE=pull HG_URL=file:$TESTTMP/a
86 86 adding changesets
87 87 adding manifests
88 88 adding file changes
89 89 added 3 changesets with 2 changes to 2 files
90 90 changegroup hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_SOURCE=pull HG_URL=file:$TESTTMP/a
91 91 incoming hook: HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd HG_SOURCE=pull HG_URL=file:$TESTTMP/a
92 92 incoming hook: HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2 HG_SOURCE=pull HG_URL=file:$TESTTMP/a
93 93 incoming hook: HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_SOURCE=pull HG_URL=file:$TESTTMP/a
94 94 (run 'hg update' to get a working copy)
95 95
96 96 tag hooks can see env vars
97 97
98 98 $ cd ../a
99 99 $ cat >> .hg/hgrc <<EOF
100 100 > pretag = python "$TESTDIR/printenv.py" pretag
101 101 > tag = sh -c "HG_PARENT1= HG_PARENT2= python \"$TESTDIR/printenv.py\" tag"
102 102 > EOF
103 103 $ hg tag -d '3 0' a
104 104 pretag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
105 105 precommit hook: HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
106 106 pretxncommit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2 HG_PENDING=$TESTTMP/a
107 107 4:539e4b31b6dc
108 108 tag hook: HG_LOCAL=0 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2 HG_TAG=a
109 109 commit hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
110 110 commit.b hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
111 111 $ hg tag -l la
112 112 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
113 113 tag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=la
114 114
115 115 pretag hook can forbid tagging
116 116
117 117 $ echo "pretag.forbid = python \"$TESTDIR/printenv.py\" pretag.forbid 1" >> .hg/hgrc
118 118 $ hg tag -d '4 0' fa
119 119 pretag hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
120 120 pretag.forbid hook: HG_LOCAL=0 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fa
121 121 abort: pretag.forbid hook exited with status 1
122 122 [255]
123 123 $ hg tag -l fla
124 124 pretag hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla
125 125 pretag.forbid hook: HG_LOCAL=1 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_TAG=fla
126 126 abort: pretag.forbid hook exited with status 1
127 127 [255]
128 128
129 129 pretxncommit hook can see changeset, can roll back txn, changeset no
130 130 more there after
131 131
132 132 $ echo "pretxncommit.forbid0 = hg tip -q" >> .hg/hgrc
133 133 $ echo "pretxncommit.forbid1 = python \"$TESTDIR/printenv.py\" pretxncommit.forbid 1" >> .hg/hgrc
134 134 $ echo z > z
135 135 $ hg add z
136 136 $ hg -q tip
137 137 4:539e4b31b6dc
138 138 $ hg commit -m 'fail' -d '4 0'
139 139 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
140 140 pretxncommit hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a
141 141 5:6f611f8018c1
142 142 5:6f611f8018c1
143 143 pretxncommit.forbid hook: HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/a
144 144 transaction abort!
145 145 rollback completed
146 146 abort: pretxncommit.forbid1 hook exited with status 1
147 147 [255]
148 148 $ hg -q tip
149 149 4:539e4b31b6dc
150 150
151 151 precommit hook can prevent commit
152 152
153 153 $ echo "precommit.forbid = python \"$TESTDIR/printenv.py\" precommit.forbid 1" >> .hg/hgrc
154 154 $ hg commit -m 'fail' -d '4 0'
155 155 precommit hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
156 156 precommit.forbid hook: HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
157 157 abort: precommit.forbid hook exited with status 1
158 158 [255]
159 159 $ hg -q tip
160 160 4:539e4b31b6dc
161 161
162 162 preupdate hook can prevent update
163 163
164 164 $ echo "preupdate = python \"$TESTDIR/printenv.py\" preupdate" >> .hg/hgrc
165 165 $ hg update 1
166 166 preupdate hook: HG_PARENT1=ab228980c14d
167 167 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
168 168
169 169 update hook
170 170
171 171 $ echo "update = python \"$TESTDIR/printenv.py\" update" >> .hg/hgrc
172 172 $ hg update
173 173 preupdate hook: HG_PARENT1=539e4b31b6dc
174 174 update hook: HG_ERROR=0 HG_PARENT1=539e4b31b6dc
175 175 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
176 176
177 177 pushkey hook
178 178
179 179 $ echo "pushkey = python \"$TESTDIR/printenv.py\" pushkey" >> .hg/hgrc
180 180 $ cd ../b
181 181 $ hg bookmark -r null foo
182 182 $ hg push -B foo ../a
183 183 pushing to ../a
184 184 searching for changes
185 185 no changes found
186 186 exporting bookmark foo
187 187 pushkey hook: HG_KEY=foo HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000 HG_RET=1
188 188 [1]
189 189 $ cd ../a
190 190
191 191 listkeys hook
192 192
193 193 $ echo "listkeys = python \"$TESTDIR/printenv.py\" listkeys" >> .hg/hgrc
194 194 $ hg bookmark -r null bar
195 195 $ cd ../b
196 196 $ hg pull -B bar ../a
197 197 pulling from ../a
198 198 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
199 199 no changes found
200 200 listkeys hook: HG_NAMESPACE=phases HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
201 201 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
202 202 adding remote bookmark bar
203 203 importing bookmark bar
204 204 $ cd ../a
205 205
206 206 test that prepushkey can prevent incoming keys
207 207
208 208 $ echo "prepushkey = python \"$TESTDIR/printenv.py\" prepushkey.forbid 1" >> .hg/hgrc
209 209 $ cd ../b
210 210 $ hg bookmark -r null baz
211 211 $ hg push -B baz ../a
212 212 pushing to ../a
213 213 searching for changes
214 214 no changes found
215 215 listkeys hook: HG_NAMESPACE=phases HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
216 216 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
217 217 listkeys hook: HG_NAMESPACE=bookmarks HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
218 218 exporting bookmark baz
219 219 prepushkey.forbid hook: HG_KEY=baz HG_NAMESPACE=bookmarks HG_NEW=0000000000000000000000000000000000000000
220 220 abort: prepushkey hook exited with status 1
221 221 [255]
222 222 $ cd ../a
223 223
224 224 test that prelistkeys can prevent listing keys
225 225
226 226 $ echo "prelistkeys = python \"$TESTDIR/printenv.py\" prelistkeys.forbid 1" >> .hg/hgrc
227 227 $ hg bookmark -r null quux
228 228 $ cd ../b
229 229 $ hg pull -B quux ../a
230 230 pulling from ../a
231 231 prelistkeys.forbid hook: HG_NAMESPACE=bookmarks
232 232 abort: prelistkeys hook exited with status 1
233 233 [255]
234 234 $ cd ../a
235 235
236 236 prechangegroup hook can prevent incoming changes
237 237
238 238 $ cd ../b
239 239 $ hg -q tip
240 240 3:07f3376c1e65
241 241 $ cat > .hg/hgrc <<EOF
242 242 > [hooks]
243 243 > prechangegroup.forbid = python "$TESTDIR/printenv.py" prechangegroup.forbid 1
244 244 > EOF
245 245 $ hg pull ../a
246 246 pulling from ../a
247 247 searching for changes
248 248 prechangegroup.forbid hook: HG_SOURCE=pull HG_URL=file:$TESTTMP/a
249 249 abort: prechangegroup.forbid hook exited with status 1
250 250 [255]
251 251
252 252 pretxnchangegroup hook can see incoming changes, can roll back txn,
253 253 incoming changes no longer there after
254 254
255 255 $ cat > .hg/hgrc <<EOF
256 256 > [hooks]
257 257 > pretxnchangegroup.forbid0 = hg tip -q
258 258 > pretxnchangegroup.forbid1 = python "$TESTDIR/printenv.py" pretxnchangegroup.forbid 1
259 259 > EOF
260 260 $ hg pull ../a
261 261 pulling from ../a
262 262 searching for changes
263 263 adding changesets
264 264 adding manifests
265 265 adding file changes
266 266 added 1 changesets with 1 changes to 1 files
267 267 4:539e4b31b6dc
268 268 pretxnchangegroup.forbid hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_PENDING=$TESTTMP/b HG_SOURCE=pull HG_URL=file:$TESTTMP/a
269 269 transaction abort!
270 270 rollback completed
271 271 abort: pretxnchangegroup.forbid1 hook exited with status 1
272 272 [255]
273 273 $ hg -q tip
274 274 3:07f3376c1e65
275 275
276 276 outgoing hooks can see env vars
277 277
278 278 $ rm .hg/hgrc
279 279 $ cat > ../a/.hg/hgrc <<EOF
280 280 > [hooks]
281 281 > preoutgoing = python "$TESTDIR/printenv.py" preoutgoing
282 282 > outgoing = python "$TESTDIR/printenv.py" outgoing
283 283 > EOF
284 284 $ hg pull ../a
285 285 pulling from ../a
286 286 searching for changes
287 287 preoutgoing hook: HG_SOURCE=pull
288 288 adding changesets
289 289 outgoing hook: HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 HG_SOURCE=pull
290 290 adding manifests
291 291 adding file changes
292 292 added 1 changesets with 1 changes to 1 files
293 293 adding remote bookmark quux
294 294 (run 'hg update' to get a working copy)
295 295 $ hg rollback
296 296 repository tip rolled back to revision 3 (undo pull)
297 297
298 298 preoutgoing hook can prevent outgoing changes
299 299
300 300 $ echo "preoutgoing.forbid = python \"$TESTDIR/printenv.py\" preoutgoing.forbid 1" >> ../a/.hg/hgrc
301 301 $ hg pull ../a
302 302 pulling from ../a
303 303 searching for changes
304 304 preoutgoing hook: HG_SOURCE=pull
305 305 preoutgoing.forbid hook: HG_SOURCE=pull
306 306 abort: preoutgoing.forbid hook exited with status 1
307 307 [255]
308 308
309 309 outgoing hooks work for local clones
310 310
311 311 $ cd ..
312 312 $ cat > a/.hg/hgrc <<EOF
313 313 > [hooks]
314 314 > preoutgoing = python "$TESTDIR/printenv.py" preoutgoing
315 315 > outgoing = python "$TESTDIR/printenv.py" outgoing
316 316 > EOF
317 317 $ hg clone a c
318 318 preoutgoing hook: HG_SOURCE=clone
319 319 outgoing hook: HG_NODE=0000000000000000000000000000000000000000 HG_SOURCE=clone
320 320 updating to branch default
321 321 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
322 322 $ rm -rf c
323 323
324 324 preoutgoing hook can prevent outgoing changes for local clones
325 325
326 326 $ echo "preoutgoing.forbid = python \"$TESTDIR/printenv.py\" preoutgoing.forbid 1" >> a/.hg/hgrc
327 327 $ hg clone a zzz
328 328 preoutgoing hook: HG_SOURCE=clone
329 329 preoutgoing.forbid hook: HG_SOURCE=clone
330 330 abort: preoutgoing.forbid hook exited with status 1
331 331 [255]
332 332
333 333 $ cd "$TESTTMP/b"
334 334
335 335 $ cat > hooktests.py <<EOF
336 336 > from mercurial import util
337 337 >
338 338 > uncallable = 0
339 339 >
340 340 > def printargs(args):
341 341 > args.pop('ui', None)
342 342 > args.pop('repo', None)
343 343 > a = list(args.items())
344 344 > a.sort()
345 345 > print 'hook args:'
346 346 > for k, v in a:
347 347 > print ' ', k, v
348 348 >
349 349 > def passhook(**args):
350 350 > printargs(args)
351 351 >
352 352 > def failhook(**args):
353 353 > printargs(args)
354 354 > return True
355 355 >
356 356 > class LocalException(Exception):
357 357 > pass
358 358 >
359 359 > def raisehook(**args):
360 360 > raise LocalException('exception from hook')
361 361 >
362 362 > def aborthook(**args):
363 363 > raise util.Abort('raise abort from hook')
364 364 >
365 365 > def brokenhook(**args):
366 366 > return 1 + {}
367 367 >
368 368 > def verbosehook(ui, **args):
369 369 > ui.note('verbose output from hook\n')
370 370 >
371 371 > def printtags(ui, repo, **args):
372 > print repo.tags().keys()
372 > print sorted(repo.tags())
373 373 >
374 374 > class container:
375 375 > unreachable = 1
376 376 > EOF
377 377
378 378 test python hooks
379 379
380 380 #if windows
381 381 $ PYTHONPATH="$TESTTMP/b;$PYTHONPATH"
382 382 #else
383 383 $ PYTHONPATH="$TESTTMP/b:$PYTHONPATH"
384 384 #endif
385 385 $ export PYTHONPATH
386 386
387 387 $ echo '[hooks]' > ../a/.hg/hgrc
388 388 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
389 389 $ hg pull ../a 2>&1 | grep 'raised an exception'
390 390 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
391 391
392 392 $ echo '[hooks]' > ../a/.hg/hgrc
393 393 $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
394 394 $ hg pull ../a 2>&1 | grep 'raised an exception'
395 395 error: preoutgoing.raise hook raised an exception: exception from hook
396 396
397 397 $ echo '[hooks]' > ../a/.hg/hgrc
398 398 $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
399 399 $ hg pull ../a
400 400 pulling from ../a
401 401 searching for changes
402 402 error: preoutgoing.abort hook failed: raise abort from hook
403 403 abort: raise abort from hook
404 404 [255]
405 405
406 406 $ echo '[hooks]' > ../a/.hg/hgrc
407 407 $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
408 408 $ hg pull ../a
409 409 pulling from ../a
410 410 searching for changes
411 411 hook args:
412 412 hooktype preoutgoing
413 413 source pull
414 414 abort: preoutgoing.fail hook failed
415 415 [255]
416 416
417 417 $ echo '[hooks]' > ../a/.hg/hgrc
418 418 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
419 419 $ hg pull ../a
420 420 pulling from ../a
421 421 searching for changes
422 422 abort: preoutgoing.uncallable hook is invalid ("hooktests.uncallable" is not callable)
423 423 [255]
424 424
425 425 $ echo '[hooks]' > ../a/.hg/hgrc
426 426 $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
427 427 $ hg pull ../a
428 428 pulling from ../a
429 429 searching for changes
430 430 abort: preoutgoing.nohook hook is invalid ("hooktests.nohook" is not defined)
431 431 [255]
432 432
433 433 $ echo '[hooks]' > ../a/.hg/hgrc
434 434 $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
435 435 $ hg pull ../a
436 436 pulling from ../a
437 437 searching for changes
438 438 abort: preoutgoing.nomodule hook is invalid ("nomodule" not in a module)
439 439 [255]
440 440
441 441 $ echo '[hooks]' > ../a/.hg/hgrc
442 442 $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
443 443 $ hg pull ../a
444 444 pulling from ../a
445 445 searching for changes
446 446 abort: preoutgoing.badmodule hook is invalid (import of "nomodule" failed)
447 447 [255]
448 448
449 449 $ echo '[hooks]' > ../a/.hg/hgrc
450 450 $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
451 451 $ hg pull ../a
452 452 pulling from ../a
453 453 searching for changes
454 454 abort: preoutgoing.unreachable hook is invalid (import of "hooktests.container" failed)
455 455 [255]
456 456
457 457 $ echo '[hooks]' > ../a/.hg/hgrc
458 458 $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
459 459 $ hg pull ../a
460 460 pulling from ../a
461 461 searching for changes
462 462 hook args:
463 463 hooktype preoutgoing
464 464 source pull
465 465 adding changesets
466 466 adding manifests
467 467 adding file changes
468 468 added 1 changesets with 1 changes to 1 files
469 469 adding remote bookmark quux
470 470 (run 'hg update' to get a working copy)
471 471
472 472 make sure --traceback works
473 473
474 474 $ echo '[hooks]' > .hg/hgrc
475 475 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
476 476
477 477 $ echo aa > a
478 478 $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback'
479 479 Traceback (most recent call last):
480 480
481 481 $ cd ..
482 482 $ hg init c
483 483 $ cd c
484 484
485 485 $ cat > hookext.py <<EOF
486 486 > def autohook(**args):
487 487 > print "Automatically installed hook"
488 488 >
489 489 > def reposetup(ui, repo):
490 490 > repo.ui.setconfig("hooks", "commit.auto", autohook)
491 491 > EOF
492 492 $ echo '[extensions]' >> .hg/hgrc
493 493 $ echo 'hookext = hookext.py' >> .hg/hgrc
494 494
495 495 $ touch foo
496 496 $ hg add foo
497 497 $ hg ci -d '0 0' -m 'add foo'
498 498 Automatically installed hook
499 499 $ echo >> foo
500 500 $ hg ci --debug -d '0 0' -m 'change foo'
501 501 foo
502 502 calling hook commit.auto: <function autohook at *> (glob)
503 503 Automatically installed hook
504 504 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
505 505
506 506 $ hg showconfig hooks
507 507 hooks.commit.auto=<function autohook at *> (glob)
508 508
509 509 test python hook configured with python:[file]:[hook] syntax
510 510
511 511 $ cd ..
512 512 $ mkdir d
513 513 $ cd d
514 514 $ hg init repo
515 515 $ mkdir hooks
516 516
517 517 $ cd hooks
518 518 $ cat > testhooks.py <<EOF
519 519 > def testhook(**args):
520 520 > print 'hook works'
521 521 > EOF
522 522 $ echo '[hooks]' > ../repo/.hg/hgrc
523 523 $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
524 524
525 525 $ cd ../repo
526 526 $ hg commit -d '0 0'
527 527 hook works
528 528 nothing changed
529 529 [1]
530 530
531 531 $ echo '[hooks]' > .hg/hgrc
532 532 $ echo "update.ne = python:`pwd`/nonexistent.py:testhook" >> .hg/hgrc
533 533 $ echo "pre-identify.npmd = python:`pwd`/:no_python_module_dir" >> .hg/hgrc
534 534
535 535 $ hg up null
536 536 loading update.ne hook failed:
537 537 abort: No such file or directory: $TESTTMP/d/repo/nonexistent.py
538 538 [255]
539 539
540 540 $ hg id
541 541 loading pre-identify.npmd hook failed:
542 542 abort: No module named repo!
543 543 [255]
544 544
545 545 $ cd ../../b
546 546
547 547 make sure --traceback works on hook import failure
548 548
549 549 $ cat > importfail.py <<EOF
550 550 > import somebogusmodule
551 551 > # dereference something in the module to force demandimport to load it
552 552 > somebogusmodule.whatever
553 553 > EOF
554 554
555 555 $ echo '[hooks]' > .hg/hgrc
556 556 $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
557 557
558 558 $ echo a >> a
559 559 $ hg --traceback commit -ma 2>&1 | egrep -v '^( +File| [a-zA-Z(])'
560 560 exception from first failed import attempt:
561 561 Traceback (most recent call last):
562 562 ImportError: No module named somebogusmodule
563 563 exception from second failed import attempt:
564 564 Traceback (most recent call last):
565 565 ImportError: No module named hgext_importfail
566 566 Traceback (most recent call last):
567 567 Abort: precommit.importfail hook is invalid (import of "importfail" failed)
568 568 abort: precommit.importfail hook is invalid (import of "importfail" failed)
569 569
570 570 Issue1827: Hooks Update & Commit not completely post operation
571 571
572 572 commit and update hooks should run after command completion
573 573
574 574 $ echo '[hooks]' > .hg/hgrc
575 575 $ echo 'commit = hg id' >> .hg/hgrc
576 576 $ echo 'update = hg id' >> .hg/hgrc
577 577 $ echo bb > a
578 578 $ hg ci -ma
579 579 223eafe2750c tip
580 580 $ hg up 0
581 581 cb9a9f314b8b
582 582 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
583 583
584 584 make sure --verbose (and --quiet/--debug etc.) are propagated to the local ui
585 585 that is passed to pre/post hooks
586 586
587 587 $ echo '[hooks]' > .hg/hgrc
588 588 $ echo 'pre-identify = python:hooktests.verbosehook' >> .hg/hgrc
589 589 $ hg id
590 590 cb9a9f314b8b
591 591 $ hg id --verbose
592 592 calling hook pre-identify: hooktests.verbosehook
593 593 verbose output from hook
594 594 cb9a9f314b8b
595 595
596 596 Ensure hooks can be prioritized
597 597
598 598 $ echo '[hooks]' > .hg/hgrc
599 599 $ echo 'pre-identify.a = python:hooktests.verbosehook' >> .hg/hgrc
600 600 $ echo 'pre-identify.b = python:hooktests.verbosehook' >> .hg/hgrc
601 601 $ echo 'priority.pre-identify.b = 1' >> .hg/hgrc
602 602 $ echo 'pre-identify.c = python:hooktests.verbosehook' >> .hg/hgrc
603 603 $ hg id --verbose
604 604 calling hook pre-identify.b: hooktests.verbosehook
605 605 verbose output from hook
606 606 calling hook pre-identify.a: hooktests.verbosehook
607 607 verbose output from hook
608 608 calling hook pre-identify.c: hooktests.verbosehook
609 609 verbose output from hook
610 610 cb9a9f314b8b
611 611
612 612 new tags must be visible in pretxncommit (issue3210)
613 613
614 614 $ echo 'pretxncommit.printtags = python:hooktests.printtags' >> .hg/hgrc
615 615 $ hg tag -f foo
616 616 ['a', 'foo', 'tip']
617 617
618 618 new commits must be visible in pretxnchangegroup (issue3428)
619 619
620 620 $ cd ..
621 621 $ hg init to
622 622 $ echo '[hooks]' >> to/.hg/hgrc
623 623 $ echo 'pretxnchangegroup = hg --traceback tip' >> to/.hg/hgrc
624 624 $ echo a >> to/a
625 625 $ hg --cwd to ci -Ama
626 626 adding a
627 627 $ hg clone to from
628 628 updating to branch default
629 629 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
630 630 $ echo aa >> from/a
631 631 $ hg --cwd from ci -mb
632 632 $ hg --cwd from push
633 633 pushing to $TESTTMP/to (glob)
634 634 searching for changes
635 635 adding changesets
636 636 adding manifests
637 637 adding file changes
638 638 added 1 changesets with 1 changes to 1 files
639 639 changeset: 1:9836a07b9b9d
640 640 tag: tip
641 641 user: test
642 642 date: Thu Jan 01 00:00:00 1970 +0000
643 643 summary: b
644 644
General Comments 0
You need to be logged in to leave comments. Login now