##// END OF EJS Templates
py3: add Python 3 exception output to test-hook.t...
Denis Laxalde -
r43585:a973a75e default
parent child Browse files
Show More
@@ -1,1368 +1,1370 b''
1 1 commit hooks can see env vars
2 2 (and post-transaction one are run unlocked)
3 3
4 4
5 5 $ cat > $TESTTMP/txnabort.checkargs.py <<EOF
6 6 > from mercurial import pycompat
7 7 > def showargs(ui, repo, hooktype, **kwargs):
8 8 > kwargs = pycompat.byteskwargs(kwargs)
9 9 > ui.write(b'%s Python hook: %s\n' % (hooktype,
10 10 > b','.join(sorted(kwargs))))
11 11 > EOF
12 12
13 13 $ hg init a
14 14 $ cd a
15 15 $ cat > .hg/hgrc <<EOF
16 16 > [hooks]
17 17 > commit = sh -c "HG_LOCAL= HG_TAG= printenv.py --line commit"
18 18 > commit.b = sh -c "HG_LOCAL= HG_TAG= printenv.py --line commit.b"
19 19 > precommit = sh -c "HG_LOCAL= HG_NODE= HG_TAG= printenv.py --line precommit"
20 20 > pretxncommit = sh -c "HG_LOCAL= HG_TAG= printenv.py --line pretxncommit"
21 21 > pretxncommit.tip = hg -q tip
22 22 > pre-identify = sh -c "printenv.py --line pre-identify 1"
23 23 > pre-cat = sh -c "printenv.py --line pre-cat"
24 24 > post-cat = sh -c "printenv.py --line post-cat"
25 25 > pretxnopen = sh -c "HG_LOCAL= HG_TAG= printenv.py --line pretxnopen"
26 26 > pretxnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py --line pretxnclose"
27 27 > txnclose = sh -c "HG_LOCAL= HG_TAG= printenv.py --line txnclose"
28 28 > txnabort.0 = python:$TESTTMP/txnabort.checkargs.py:showargs
29 29 > txnabort.1 = sh -c "HG_LOCAL= HG_TAG= printenv.py --line txnabort"
30 30 > txnclose.checklock = sh -c "hg debuglock > /dev/null"
31 31 > EOF
32 32 $ echo a > a
33 33 $ hg add a
34 34 $ hg commit -m a
35 35 precommit hook: HG_HOOKNAME=precommit
36 36 HG_HOOKTYPE=precommit
37 37 HG_PARENT1=0000000000000000000000000000000000000000
38 38
39 39 pretxnopen hook: HG_HOOKNAME=pretxnopen
40 40 HG_HOOKTYPE=pretxnopen
41 41 HG_TXNID=TXN:$ID$
42 42 HG_TXNNAME=commit
43 43
44 44 pretxncommit hook: HG_HOOKNAME=pretxncommit
45 45 HG_HOOKTYPE=pretxncommit
46 46 HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
47 47 HG_PARENT1=0000000000000000000000000000000000000000
48 48 HG_PENDING=$TESTTMP/a
49 49
50 50 0:cb9a9f314b8b
51 51 pretxnclose hook: HG_HOOKNAME=pretxnclose
52 52 HG_HOOKTYPE=pretxnclose
53 53 HG_PENDING=$TESTTMP/a
54 54 HG_PHASES_MOVED=1
55 55 HG_TXNID=TXN:$ID$
56 56 HG_TXNNAME=commit
57 57
58 58 txnclose hook: HG_HOOKNAME=txnclose
59 59 HG_HOOKTYPE=txnclose
60 60 HG_PHASES_MOVED=1
61 61 HG_TXNID=TXN:$ID$
62 62 HG_TXNNAME=commit
63 63
64 64 commit hook: HG_HOOKNAME=commit
65 65 HG_HOOKTYPE=commit
66 66 HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
67 67 HG_PARENT1=0000000000000000000000000000000000000000
68 68
69 69 commit.b hook: HG_HOOKNAME=commit.b
70 70 HG_HOOKTYPE=commit
71 71 HG_NODE=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
72 72 HG_PARENT1=0000000000000000000000000000000000000000
73 73
74 74
75 75 $ hg clone . ../b
76 76 updating to branch default
77 77 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
78 78 $ cd ../b
79 79
80 80 changegroup hooks can see env vars
81 81
82 82 $ cat > .hg/hgrc <<EOF
83 83 > [hooks]
84 84 > prechangegroup = sh -c "printenv.py --line prechangegroup"
85 85 > changegroup = sh -c "printenv.py --line changegroup"
86 86 > incoming = sh -c "printenv.py --line incoming"
87 87 > EOF
88 88
89 89 pretxncommit and commit hooks can see both parents of merge
90 90
91 91 $ cd ../a
92 92 $ echo b >> a
93 93 $ hg commit -m a1 -d "1 0"
94 94 precommit hook: HG_HOOKNAME=precommit
95 95 HG_HOOKTYPE=precommit
96 96 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
97 97
98 98 pretxnopen hook: HG_HOOKNAME=pretxnopen
99 99 HG_HOOKTYPE=pretxnopen
100 100 HG_TXNID=TXN:$ID$
101 101 HG_TXNNAME=commit
102 102
103 103 pretxncommit hook: HG_HOOKNAME=pretxncommit
104 104 HG_HOOKTYPE=pretxncommit
105 105 HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd
106 106 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
107 107 HG_PENDING=$TESTTMP/a
108 108
109 109 1:ab228980c14d
110 110 pretxnclose hook: HG_HOOKNAME=pretxnclose
111 111 HG_HOOKTYPE=pretxnclose
112 112 HG_PENDING=$TESTTMP/a
113 113 HG_TXNID=TXN:$ID$
114 114 HG_TXNNAME=commit
115 115
116 116 txnclose hook: HG_HOOKNAME=txnclose
117 117 HG_HOOKTYPE=txnclose
118 118 HG_TXNID=TXN:$ID$
119 119 HG_TXNNAME=commit
120 120
121 121 commit hook: HG_HOOKNAME=commit
122 122 HG_HOOKTYPE=commit
123 123 HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd
124 124 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
125 125
126 126 commit.b hook: HG_HOOKNAME=commit.b
127 127 HG_HOOKTYPE=commit
128 128 HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd
129 129 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
130 130
131 131 $ hg update -C 0
132 132 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
133 133 $ echo b > b
134 134 $ hg add b
135 135 $ hg commit -m b -d '1 0'
136 136 precommit hook: HG_HOOKNAME=precommit
137 137 HG_HOOKTYPE=precommit
138 138 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
139 139
140 140 pretxnopen hook: HG_HOOKNAME=pretxnopen
141 141 HG_HOOKTYPE=pretxnopen
142 142 HG_TXNID=TXN:$ID$
143 143 HG_TXNNAME=commit
144 144
145 145 pretxncommit hook: HG_HOOKNAME=pretxncommit
146 146 HG_HOOKTYPE=pretxncommit
147 147 HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
148 148 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
149 149 HG_PENDING=$TESTTMP/a
150 150
151 151 2:ee9deb46ab31
152 152 pretxnclose hook: HG_HOOKNAME=pretxnclose
153 153 HG_HOOKTYPE=pretxnclose
154 154 HG_PENDING=$TESTTMP/a
155 155 HG_TXNID=TXN:$ID$
156 156 HG_TXNNAME=commit
157 157
158 158 created new head
159 159 txnclose hook: HG_HOOKNAME=txnclose
160 160 HG_HOOKTYPE=txnclose
161 161 HG_TXNID=TXN:$ID$
162 162 HG_TXNNAME=commit
163 163
164 164 commit hook: HG_HOOKNAME=commit
165 165 HG_HOOKTYPE=commit
166 166 HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
167 167 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
168 168
169 169 commit.b hook: HG_HOOKNAME=commit.b
170 170 HG_HOOKTYPE=commit
171 171 HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
172 172 HG_PARENT1=cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b
173 173
174 174 $ hg merge 1
175 175 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
176 176 (branch merge, don't forget to commit)
177 177 $ hg commit -m merge -d '2 0'
178 178 precommit hook: HG_HOOKNAME=precommit
179 179 HG_HOOKTYPE=precommit
180 180 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
181 181 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
182 182
183 183 pretxnopen hook: HG_HOOKNAME=pretxnopen
184 184 HG_HOOKTYPE=pretxnopen
185 185 HG_TXNID=TXN:$ID$
186 186 HG_TXNNAME=commit
187 187
188 188 pretxncommit hook: HG_HOOKNAME=pretxncommit
189 189 HG_HOOKTYPE=pretxncommit
190 190 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2
191 191 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
192 192 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
193 193 HG_PENDING=$TESTTMP/a
194 194
195 195 3:07f3376c1e65
196 196 pretxnclose hook: HG_HOOKNAME=pretxnclose
197 197 HG_HOOKTYPE=pretxnclose
198 198 HG_PENDING=$TESTTMP/a
199 199 HG_TXNID=TXN:$ID$
200 200 HG_TXNNAME=commit
201 201
202 202 txnclose hook: HG_HOOKNAME=txnclose
203 203 HG_HOOKTYPE=txnclose
204 204 HG_TXNID=TXN:$ID$
205 205 HG_TXNNAME=commit
206 206
207 207 commit hook: HG_HOOKNAME=commit
208 208 HG_HOOKTYPE=commit
209 209 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2
210 210 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
211 211 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
212 212
213 213 commit.b hook: HG_HOOKNAME=commit.b
214 214 HG_HOOKTYPE=commit
215 215 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2
216 216 HG_PARENT1=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
217 217 HG_PARENT2=ab228980c14deea8b9555d91c9581127383e40fd
218 218
219 219
220 220 test generic hooks
221 221
222 222 $ hg id
223 223 pre-identify hook: HG_ARGS=id
224 224 HG_HOOKNAME=pre-identify
225 225 HG_HOOKTYPE=pre-identify
226 226 HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None, 'template': ''}
227 227 HG_PATS=[]
228 228
229 229 abort: pre-identify hook exited with status 1
230 230 [255]
231 231 $ hg cat b
232 232 pre-cat hook: HG_ARGS=cat b
233 233 HG_HOOKNAME=pre-cat
234 234 HG_HOOKTYPE=pre-cat
235 235 HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': '', 'template': ''}
236 236 HG_PATS=['b']
237 237
238 238 b
239 239 post-cat hook: HG_ARGS=cat b
240 240 HG_HOOKNAME=post-cat
241 241 HG_HOOKTYPE=post-cat
242 242 HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': '', 'template': ''}
243 243 HG_PATS=['b']
244 244 HG_RESULT=0
245 245
246 246
247 247 $ cd ../b
248 248 $ hg pull ../a
249 249 pulling from ../a
250 250 searching for changes
251 251 prechangegroup hook: HG_HOOKNAME=prechangegroup
252 252 HG_HOOKTYPE=prechangegroup
253 253 HG_SOURCE=pull
254 254 HG_TXNID=TXN:$ID$
255 255 HG_TXNNAME=pull
256 256 file:/*/$TESTTMP/a (glob)
257 257 HG_URL=file:$TESTTMP/a
258 258
259 259 adding changesets
260 260 adding manifests
261 261 adding file changes
262 262 added 3 changesets with 2 changes to 2 files
263 263 new changesets ab228980c14d:07f3376c1e65
264 264 changegroup hook: HG_HOOKNAME=changegroup
265 265 HG_HOOKTYPE=changegroup
266 266 HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd
267 267 HG_NODE_LAST=07f3376c1e655977439df2a814e3cc14b27abac2
268 268 HG_SOURCE=pull
269 269 HG_TXNID=TXN:$ID$
270 270 HG_TXNNAME=pull
271 271 file:/*/$TESTTMP/a (glob)
272 272 HG_URL=file:$TESTTMP/a
273 273
274 274 incoming hook: HG_HOOKNAME=incoming
275 275 HG_HOOKTYPE=incoming
276 276 HG_NODE=ab228980c14deea8b9555d91c9581127383e40fd
277 277 HG_SOURCE=pull
278 278 HG_TXNID=TXN:$ID$
279 279 HG_TXNNAME=pull
280 280 file:/*/$TESTTMP/a (glob)
281 281 HG_URL=file:$TESTTMP/a
282 282
283 283 incoming hook: HG_HOOKNAME=incoming
284 284 HG_HOOKTYPE=incoming
285 285 HG_NODE=ee9deb46ab31e4cc3310f3cf0c3d668e4d8fffc2
286 286 HG_SOURCE=pull
287 287 HG_TXNID=TXN:$ID$
288 288 HG_TXNNAME=pull
289 289 file:/*/$TESTTMP/a (glob)
290 290 HG_URL=file:$TESTTMP/a
291 291
292 292 incoming hook: HG_HOOKNAME=incoming
293 293 HG_HOOKTYPE=incoming
294 294 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2
295 295 HG_SOURCE=pull
296 296 HG_TXNID=TXN:$ID$
297 297 HG_TXNNAME=pull
298 298 file:/*/$TESTTMP/a (glob)
299 299 HG_URL=file:$TESTTMP/a
300 300
301 301 (run 'hg update' to get a working copy)
302 302
303 303 tag hooks can see env vars
304 304
305 305 $ cd ../a
306 306 $ cat >> .hg/hgrc <<EOF
307 307 > pretag = sh -c "printenv.py --line pretag"
308 308 > tag = sh -c "HG_PARENT1= HG_PARENT2= printenv.py --line tag"
309 309 > EOF
310 310 $ hg tag -d '3 0' a
311 311 pretag hook: HG_HOOKNAME=pretag
312 312 HG_HOOKTYPE=pretag
313 313 HG_LOCAL=0
314 314 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2
315 315 HG_TAG=a
316 316
317 317 precommit hook: HG_HOOKNAME=precommit
318 318 HG_HOOKTYPE=precommit
319 319 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
320 320
321 321 pretxnopen hook: HG_HOOKNAME=pretxnopen
322 322 HG_HOOKTYPE=pretxnopen
323 323 HG_TXNID=TXN:$ID$
324 324 HG_TXNNAME=commit
325 325
326 326 pretxncommit hook: HG_HOOKNAME=pretxncommit
327 327 HG_HOOKTYPE=pretxncommit
328 328 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
329 329 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
330 330 HG_PENDING=$TESTTMP/a
331 331
332 332 4:539e4b31b6dc
333 333 pretxnclose hook: HG_HOOKNAME=pretxnclose
334 334 HG_HOOKTYPE=pretxnclose
335 335 HG_PENDING=$TESTTMP/a
336 336 HG_TXNID=TXN:$ID$
337 337 HG_TXNNAME=commit
338 338
339 339 tag hook: HG_HOOKNAME=tag
340 340 HG_HOOKTYPE=tag
341 341 HG_LOCAL=0
342 342 HG_NODE=07f3376c1e655977439df2a814e3cc14b27abac2
343 343 HG_TAG=a
344 344
345 345 txnclose hook: HG_HOOKNAME=txnclose
346 346 HG_HOOKTYPE=txnclose
347 347 HG_TXNID=TXN:$ID$
348 348 HG_TXNNAME=commit
349 349
350 350 commit hook: HG_HOOKNAME=commit
351 351 HG_HOOKTYPE=commit
352 352 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
353 353 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
354 354
355 355 commit.b hook: HG_HOOKNAME=commit.b
356 356 HG_HOOKTYPE=commit
357 357 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
358 358 HG_PARENT1=07f3376c1e655977439df2a814e3cc14b27abac2
359 359
360 360 $ hg tag -l la
361 361 pretag hook: HG_HOOKNAME=pretag
362 362 HG_HOOKTYPE=pretag
363 363 HG_LOCAL=1
364 364 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
365 365 HG_TAG=la
366 366
367 367 tag hook: HG_HOOKNAME=tag
368 368 HG_HOOKTYPE=tag
369 369 HG_LOCAL=1
370 370 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
371 371 HG_TAG=la
372 372
373 373
374 374 pretag hook can forbid tagging
375 375
376 376 $ cat >> .hg/hgrc <<EOF
377 377 > pretag.forbid = sh -c "printenv.py --line pretag.forbid 1"
378 378 > EOF
379 379 $ hg tag -d '4 0' fa
380 380 pretag hook: HG_HOOKNAME=pretag
381 381 HG_HOOKTYPE=pretag
382 382 HG_LOCAL=0
383 383 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
384 384 HG_TAG=fa
385 385
386 386 pretag.forbid hook: HG_HOOKNAME=pretag.forbid
387 387 HG_HOOKTYPE=pretag
388 388 HG_LOCAL=0
389 389 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
390 390 HG_TAG=fa
391 391
392 392 abort: pretag.forbid hook exited with status 1
393 393 [255]
394 394 $ hg tag -l fla
395 395 pretag hook: HG_HOOKNAME=pretag
396 396 HG_HOOKTYPE=pretag
397 397 HG_LOCAL=1
398 398 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
399 399 HG_TAG=fla
400 400
401 401 pretag.forbid hook: HG_HOOKNAME=pretag.forbid
402 402 HG_HOOKTYPE=pretag
403 403 HG_LOCAL=1
404 404 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
405 405 HG_TAG=fla
406 406
407 407 abort: pretag.forbid hook exited with status 1
408 408 [255]
409 409
410 410 pretxncommit hook can see changeset, can roll back txn, changeset no
411 411 more there after
412 412
413 413 $ cat >> .hg/hgrc <<EOF
414 414 > pretxncommit.forbid0 = sh -c "hg tip -q"
415 415 > pretxncommit.forbid1 = sh -c "printenv.py --line pretxncommit.forbid 1"
416 416 > EOF
417 417 $ echo z > z
418 418 $ hg add z
419 419 $ hg -q tip
420 420 4:539e4b31b6dc
421 421 $ hg commit -m 'fail' -d '4 0'
422 422 precommit hook: HG_HOOKNAME=precommit
423 423 HG_HOOKTYPE=precommit
424 424 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
425 425
426 426 pretxnopen hook: HG_HOOKNAME=pretxnopen
427 427 HG_HOOKTYPE=pretxnopen
428 428 HG_TXNID=TXN:$ID$
429 429 HG_TXNNAME=commit
430 430
431 431 pretxncommit hook: HG_HOOKNAME=pretxncommit
432 432 HG_HOOKTYPE=pretxncommit
433 433 HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567
434 434 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
435 435 HG_PENDING=$TESTTMP/a
436 436
437 437 5:6f611f8018c1
438 438 5:6f611f8018c1
439 439 pretxncommit.forbid hook: HG_HOOKNAME=pretxncommit.forbid1
440 440 HG_HOOKTYPE=pretxncommit
441 441 HG_NODE=6f611f8018c10e827fee6bd2bc807f937e761567
442 442 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
443 443 HG_PENDING=$TESTTMP/a
444 444
445 445 transaction abort!
446 446 txnabort Python hook: txnid,txnname
447 447 txnabort hook: HG_HOOKNAME=txnabort.1
448 448 HG_HOOKTYPE=txnabort
449 449 HG_TXNID=TXN:$ID$
450 450 HG_TXNNAME=commit
451 451
452 452 rollback completed
453 453 abort: pretxncommit.forbid1 hook exited with status 1
454 454 [255]
455 455 $ hg -q tip
456 456 4:539e4b31b6dc
457 457
458 458 (Check that no 'changelog.i.a' file were left behind)
459 459
460 460 $ ls -1 .hg/store/
461 461 00changelog.i
462 462 00manifest.i
463 463 data
464 464 fncache (repofncache !)
465 465 journal.phaseroots
466 466 phaseroots
467 467 undo
468 468 undo.backup.fncache (repofncache !)
469 469 undo.backupfiles
470 470 undo.phaseroots
471 471
472 472
473 473 precommit hook can prevent commit
474 474
475 475 $ cat >> .hg/hgrc <<EOF
476 476 > precommit.forbid = sh -c "printenv.py --line precommit.forbid 1"
477 477 > EOF
478 478 $ hg commit -m 'fail' -d '4 0'
479 479 precommit hook: HG_HOOKNAME=precommit
480 480 HG_HOOKTYPE=precommit
481 481 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
482 482
483 483 precommit.forbid hook: HG_HOOKNAME=precommit.forbid
484 484 HG_HOOKTYPE=precommit
485 485 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
486 486
487 487 abort: precommit.forbid hook exited with status 1
488 488 [255]
489 489 $ hg -q tip
490 490 4:539e4b31b6dc
491 491
492 492 preupdate hook can prevent update
493 493
494 494 $ cat >> .hg/hgrc <<EOF
495 495 > preupdate = sh -c "printenv.py --line preupdate"
496 496 > EOF
497 497 $ hg update 1
498 498 preupdate hook: HG_HOOKNAME=preupdate
499 499 HG_HOOKTYPE=preupdate
500 500 HG_PARENT1=ab228980c14d
501 501
502 502 0 files updated, 0 files merged, 2 files removed, 0 files unresolved
503 503
504 504 update hook
505 505
506 506 $ cat >> .hg/hgrc <<EOF
507 507 > update = sh -c "printenv.py --line update"
508 508 > EOF
509 509 $ hg update
510 510 preupdate hook: HG_HOOKNAME=preupdate
511 511 HG_HOOKTYPE=preupdate
512 512 HG_PARENT1=539e4b31b6dc
513 513
514 514 update hook: HG_ERROR=0
515 515 HG_HOOKNAME=update
516 516 HG_HOOKTYPE=update
517 517 HG_PARENT1=539e4b31b6dc
518 518
519 519 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
520 520
521 521 pushkey hook
522 522
523 523 $ cat >> .hg/hgrc <<EOF
524 524 > pushkey = sh -c "printenv.py --line pushkey"
525 525 > EOF
526 526 $ cd ../b
527 527 $ hg bookmark -r null foo
528 528 $ hg push -B foo ../a
529 529 pushing to ../a
530 530 searching for changes
531 531 no changes found
532 532 pretxnopen hook: HG_HOOKNAME=pretxnopen
533 533 HG_HOOKTYPE=pretxnopen
534 534 HG_TXNID=TXN:$ID$
535 535 HG_TXNNAME=push
536 536
537 537 pretxnclose hook: HG_BOOKMARK_MOVED=1
538 538 HG_BUNDLE2=1
539 539 HG_HOOKNAME=pretxnclose
540 540 HG_HOOKTYPE=pretxnclose
541 541 HG_PENDING=$TESTTMP/a
542 542 HG_SOURCE=push
543 543 HG_TXNID=TXN:$ID$
544 544 HG_TXNNAME=push
545 545 HG_URL=file:$TESTTMP/a
546 546
547 547 pushkey hook: HG_BUNDLE2=1
548 548 HG_HOOKNAME=pushkey
549 549 HG_HOOKTYPE=pushkey
550 550 HG_KEY=foo
551 551 HG_NAMESPACE=bookmarks
552 552 HG_NEW=0000000000000000000000000000000000000000
553 553 HG_PUSHKEYCOMPAT=1
554 554 HG_SOURCE=push
555 555 HG_TXNID=TXN:$ID$
556 556 HG_TXNNAME=push
557 557 HG_URL=file:$TESTTMP/a
558 558
559 559 txnclose hook: HG_BOOKMARK_MOVED=1
560 560 HG_BUNDLE2=1
561 561 HG_HOOKNAME=txnclose
562 562 HG_HOOKTYPE=txnclose
563 563 HG_SOURCE=push
564 564 HG_TXNID=TXN:$ID$
565 565 HG_TXNNAME=push
566 566 HG_URL=file:$TESTTMP/a
567 567
568 568 exporting bookmark foo
569 569 [1]
570 570 $ cd ../a
571 571
572 572 listkeys hook
573 573
574 574 $ cat >> .hg/hgrc <<EOF
575 575 > listkeys = sh -c "printenv.py --line listkeys"
576 576 > EOF
577 577 $ hg bookmark -r null bar
578 578 pretxnopen hook: HG_HOOKNAME=pretxnopen
579 579 HG_HOOKTYPE=pretxnopen
580 580 HG_TXNID=TXN:$ID$
581 581 HG_TXNNAME=bookmark
582 582
583 583 pretxnclose hook: HG_BOOKMARK_MOVED=1
584 584 HG_HOOKNAME=pretxnclose
585 585 HG_HOOKTYPE=pretxnclose
586 586 HG_PENDING=$TESTTMP/a
587 587 HG_TXNID=TXN:$ID$
588 588 HG_TXNNAME=bookmark
589 589
590 590 txnclose hook: HG_BOOKMARK_MOVED=1
591 591 HG_HOOKNAME=txnclose
592 592 HG_HOOKTYPE=txnclose
593 593 HG_TXNID=TXN:$ID$
594 594 HG_TXNNAME=bookmark
595 595
596 596 $ cd ../b
597 597 $ hg pull -B bar ../a
598 598 pulling from ../a
599 599 listkeys hook: HG_HOOKNAME=listkeys
600 600 HG_HOOKTYPE=listkeys
601 601 HG_NAMESPACE=bookmarks
602 602 HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
603 603
604 604 no changes found
605 605 adding remote bookmark bar
606 606 $ cd ../a
607 607
608 608 test that prepushkey can prevent incoming keys
609 609
610 610 $ cat >> .hg/hgrc <<EOF
611 611 > prepushkey = sh -c "printenv.py --line prepushkey.forbid 1"
612 612 > EOF
613 613 $ cd ../b
614 614 $ hg bookmark -r null baz
615 615 $ hg push -B baz ../a
616 616 pushing to ../a
617 617 searching for changes
618 618 listkeys hook: HG_HOOKNAME=listkeys
619 619 HG_HOOKTYPE=listkeys
620 620 HG_NAMESPACE=phases
621 621 HG_VALUES={'cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b': '1', 'publishing': 'True'}
622 622
623 623 listkeys hook: HG_HOOKNAME=listkeys
624 624 HG_HOOKTYPE=listkeys
625 625 HG_NAMESPACE=bookmarks
626 626 HG_VALUES={'bar': '0000000000000000000000000000000000000000', 'foo': '0000000000000000000000000000000000000000'}
627 627
628 628 no changes found
629 629 pretxnopen hook: HG_HOOKNAME=pretxnopen
630 630 HG_HOOKTYPE=pretxnopen
631 631 HG_TXNID=TXN:$ID$
632 632 HG_TXNNAME=push
633 633
634 634 prepushkey.forbid hook: HG_BUNDLE2=1
635 635 HG_HOOKNAME=prepushkey
636 636 HG_HOOKTYPE=prepushkey
637 637 HG_KEY=baz
638 638 HG_NAMESPACE=bookmarks
639 639 HG_NEW=0000000000000000000000000000000000000000
640 640 HG_PUSHKEYCOMPAT=1
641 641 HG_SOURCE=push
642 642 HG_TXNID=TXN:$ID$
643 643 HG_TXNNAME=push
644 644 HG_URL=file:$TESTTMP/a
645 645
646 646 abort: prepushkey hook exited with status 1
647 647 [255]
648 648 $ cd ../a
649 649
650 650 test that prelistkeys can prevent listing keys
651 651
652 652 $ cat >> .hg/hgrc <<EOF
653 653 > prelistkeys = sh -c "printenv.py --line prelistkeys.forbid 1"
654 654 > EOF
655 655 $ hg bookmark -r null quux
656 656 pretxnopen hook: HG_HOOKNAME=pretxnopen
657 657 HG_HOOKTYPE=pretxnopen
658 658 HG_TXNID=TXN:$ID$
659 659 HG_TXNNAME=bookmark
660 660
661 661 pretxnclose hook: HG_BOOKMARK_MOVED=1
662 662 HG_HOOKNAME=pretxnclose
663 663 HG_HOOKTYPE=pretxnclose
664 664 HG_PENDING=$TESTTMP/a
665 665 HG_TXNID=TXN:$ID$
666 666 HG_TXNNAME=bookmark
667 667
668 668 txnclose hook: HG_BOOKMARK_MOVED=1
669 669 HG_HOOKNAME=txnclose
670 670 HG_HOOKTYPE=txnclose
671 671 HG_TXNID=TXN:$ID$
672 672 HG_TXNNAME=bookmark
673 673
674 674 $ cd ../b
675 675 $ hg pull -B quux ../a
676 676 pulling from ../a
677 677 prelistkeys.forbid hook: HG_HOOKNAME=prelistkeys
678 678 HG_HOOKTYPE=prelistkeys
679 679 HG_NAMESPACE=bookmarks
680 680
681 681 abort: prelistkeys hook exited with status 1
682 682 [255]
683 683 $ cd ../a
684 684 $ rm .hg/hgrc
685 685
686 686 prechangegroup hook can prevent incoming changes
687 687
688 688 $ cd ../b
689 689 $ hg -q tip
690 690 3:07f3376c1e65
691 691 $ cat > .hg/hgrc <<EOF
692 692 > [hooks]
693 693 > prechangegroup.forbid = sh -c "printenv.py --line prechangegroup.forbid 1"
694 694 > EOF
695 695 $ hg pull ../a
696 696 pulling from ../a
697 697 searching for changes
698 698 prechangegroup.forbid hook: HG_HOOKNAME=prechangegroup.forbid
699 699 HG_HOOKTYPE=prechangegroup
700 700 HG_SOURCE=pull
701 701 HG_TXNID=TXN:$ID$
702 702 HG_TXNNAME=pull
703 703 file:/*/$TESTTMP/a (glob)
704 704 HG_URL=file:$TESTTMP/a
705 705
706 706 abort: prechangegroup.forbid hook exited with status 1
707 707 [255]
708 708
709 709 pretxnchangegroup hook can see incoming changes, can roll back txn,
710 710 incoming changes no longer there after
711 711
712 712 $ cat > .hg/hgrc <<EOF
713 713 > [hooks]
714 714 > pretxnchangegroup.forbid0 = hg tip -q
715 715 > pretxnchangegroup.forbid1 = sh -c "printenv.py --line pretxnchangegroup.forbid 1"
716 716 > EOF
717 717 $ hg pull ../a
718 718 pulling from ../a
719 719 searching for changes
720 720 adding changesets
721 721 adding manifests
722 722 adding file changes
723 723 4:539e4b31b6dc
724 724 pretxnchangegroup.forbid hook: HG_HOOKNAME=pretxnchangegroup.forbid1
725 725 HG_HOOKTYPE=pretxnchangegroup
726 726 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
727 727 HG_NODE_LAST=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
728 728 HG_PENDING=$TESTTMP/b
729 729 HG_SOURCE=pull
730 730 HG_TXNID=TXN:$ID$
731 731 HG_TXNNAME=pull
732 732 file:/*/$TESTTMP/a (glob)
733 733 HG_URL=file:$TESTTMP/a
734 734
735 735 transaction abort!
736 736 rollback completed
737 737 abort: pretxnchangegroup.forbid1 hook exited with status 1
738 738 [255]
739 739 $ hg -q tip
740 740 3:07f3376c1e65
741 741
742 742 outgoing hooks can see env vars
743 743
744 744 $ rm .hg/hgrc
745 745 $ cat > ../a/.hg/hgrc <<EOF
746 746 > [hooks]
747 747 > preoutgoing = sh -c "printenv.py --line preoutgoing"
748 748 > outgoing = sh -c "printenv.py --line outgoing"
749 749 > EOF
750 750 $ hg pull ../a
751 751 pulling from ../a
752 752 searching for changes
753 753 preoutgoing hook: HG_HOOKNAME=preoutgoing
754 754 HG_HOOKTYPE=preoutgoing
755 755 HG_SOURCE=pull
756 756
757 757 outgoing hook: HG_HOOKNAME=outgoing
758 758 HG_HOOKTYPE=outgoing
759 759 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10
760 760 HG_SOURCE=pull
761 761
762 762 adding changesets
763 763 adding manifests
764 764 adding file changes
765 765 adding remote bookmark quux
766 766 added 1 changesets with 1 changes to 1 files
767 767 new changesets 539e4b31b6dc
768 768 (run 'hg update' to get a working copy)
769 769 $ hg rollback
770 770 repository tip rolled back to revision 3 (undo pull)
771 771
772 772 preoutgoing hook can prevent outgoing changes
773 773
774 774 $ cat >> ../a/.hg/hgrc <<EOF
775 775 > preoutgoing.forbid = sh -c "printenv.py --line preoutgoing.forbid 1"
776 776 > EOF
777 777 $ hg pull ../a
778 778 pulling from ../a
779 779 searching for changes
780 780 preoutgoing hook: HG_HOOKNAME=preoutgoing
781 781 HG_HOOKTYPE=preoutgoing
782 782 HG_SOURCE=pull
783 783
784 784 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid
785 785 HG_HOOKTYPE=preoutgoing
786 786 HG_SOURCE=pull
787 787
788 788 abort: preoutgoing.forbid hook exited with status 1
789 789 [255]
790 790
791 791 outgoing hooks work for local clones
792 792
793 793 $ cd ..
794 794 $ cat > a/.hg/hgrc <<EOF
795 795 > [hooks]
796 796 > preoutgoing = sh -c "printenv.py --line preoutgoing"
797 797 > outgoing = sh -c "printenv.py --line outgoing"
798 798 > EOF
799 799 $ hg clone a c
800 800 preoutgoing hook: HG_HOOKNAME=preoutgoing
801 801 HG_HOOKTYPE=preoutgoing
802 802 HG_SOURCE=clone
803 803
804 804 outgoing hook: HG_HOOKNAME=outgoing
805 805 HG_HOOKTYPE=outgoing
806 806 HG_NODE=0000000000000000000000000000000000000000
807 807 HG_SOURCE=clone
808 808
809 809 updating to branch default
810 810 3 files updated, 0 files merged, 0 files removed, 0 files unresolved
811 811 $ rm -rf c
812 812
813 813 preoutgoing hook can prevent outgoing changes for local clones
814 814
815 815 $ cat >> a/.hg/hgrc <<EOF
816 816 > preoutgoing.forbid = sh -c "printenv.py --line preoutgoing.forbid 1"
817 817 > EOF
818 818 $ hg clone a zzz
819 819 preoutgoing hook: HG_HOOKNAME=preoutgoing
820 820 HG_HOOKTYPE=preoutgoing
821 821 HG_SOURCE=clone
822 822
823 823 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid
824 824 HG_HOOKTYPE=preoutgoing
825 825 HG_SOURCE=clone
826 826
827 827 abort: preoutgoing.forbid hook exited with status 1
828 828 [255]
829 829
830 830 $ cd "$TESTTMP/b"
831 831
832 832 $ cat > hooktests.py <<EOF
833 833 > from __future__ import print_function
834 834 > from mercurial import (
835 835 > error,
836 836 > pycompat,
837 837 > )
838 838 >
839 839 > uncallable = 0
840 840 >
841 841 > def printargs(ui, args):
842 842 > a = list(pycompat.byteskwargs(args).items())
843 843 > a.sort()
844 844 > ui.write(b'hook args:\n')
845 845 > for k, v in a:
846 846 > ui.write(b' %s %s\n' % (k, v))
847 847 >
848 848 > def passhook(ui, repo, **args):
849 849 > printargs(ui, args)
850 850 >
851 851 > def failhook(ui, repo, **args):
852 852 > printargs(ui, args)
853 853 > return True
854 854 >
855 855 > class LocalException(Exception):
856 856 > pass
857 857 >
858 858 > def raisehook(**args):
859 859 > raise LocalException('exception from hook')
860 860 >
861 861 > def aborthook(**args):
862 862 > raise error.Abort(b'raise abort from hook')
863 863 >
864 864 > def brokenhook(**args):
865 865 > return 1 + {}
866 866 >
867 867 > def verbosehook(ui, **args):
868 868 > ui.note(b'verbose output from hook\n')
869 869 >
870 870 > def printtags(ui, repo, **args):
871 871 > ui.write(b'[%s]\n' % b', '.join(sorted(repo.tags())))
872 872 >
873 873 > class container(object):
874 874 > unreachable = 1
875 875 > EOF
876 876
877 877 $ cat > syntaxerror.py << NO_CHECK_EOF
878 878 > (foo
879 879 > NO_CHECK_EOF
880 880
881 881 test python hooks
882 882
883 883 #if windows
884 884 $ PYTHONPATH="$TESTTMP/b;$PYTHONPATH"
885 885 #else
886 886 $ PYTHONPATH="$TESTTMP/b:$PYTHONPATH"
887 887 #endif
888 888 $ export PYTHONPATH
889 889
890 890 $ echo '[hooks]' > ../a/.hg/hgrc
891 891 $ echo 'preoutgoing.broken = python:hooktests.brokenhook' >> ../a/.hg/hgrc
892 892 $ hg pull ../a 2>&1 | grep 'raised an exception'
893 893 error: preoutgoing.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
894 894
895 895 $ echo '[hooks]' > ../a/.hg/hgrc
896 896 $ echo 'preoutgoing.raise = python:hooktests.raisehook' >> ../a/.hg/hgrc
897 897 $ hg pull ../a 2>&1 | grep 'raised an exception'
898 898 error: preoutgoing.raise hook raised an exception: exception from hook
899 899
900 900 $ echo '[hooks]' > ../a/.hg/hgrc
901 901 $ echo 'preoutgoing.abort = python:hooktests.aborthook' >> ../a/.hg/hgrc
902 902 $ hg pull ../a
903 903 pulling from ../a
904 904 searching for changes
905 905 error: preoutgoing.abort hook failed: raise abort from hook
906 906 abort: raise abort from hook
907 907 [255]
908 908
909 909 $ echo '[hooks]' > ../a/.hg/hgrc
910 910 $ echo 'preoutgoing.fail = python:hooktests.failhook' >> ../a/.hg/hgrc
911 911 $ hg pull ../a
912 912 pulling from ../a
913 913 searching for changes
914 914 hook args:
915 915 hooktype preoutgoing
916 916 source pull
917 917 abort: preoutgoing.fail hook failed
918 918 [255]
919 919
920 920 $ echo '[hooks]' > ../a/.hg/hgrc
921 921 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc
922 922 $ hg pull ../a
923 923 pulling from ../a
924 924 searching for changes
925 925 abort: preoutgoing.uncallable hook is invalid: "hooktests.uncallable" is not callable
926 926 [255]
927 927
928 928 $ echo '[hooks]' > ../a/.hg/hgrc
929 929 $ echo 'preoutgoing.nohook = python:hooktests.nohook' >> ../a/.hg/hgrc
930 930 $ hg pull ../a
931 931 pulling from ../a
932 932 searching for changes
933 933 abort: preoutgoing.nohook hook is invalid: "hooktests.nohook" is not defined
934 934 [255]
935 935
936 936 $ echo '[hooks]' > ../a/.hg/hgrc
937 937 $ echo 'preoutgoing.nomodule = python:nomodule' >> ../a/.hg/hgrc
938 938 $ hg pull ../a
939 939 pulling from ../a
940 940 searching for changes
941 941 abort: preoutgoing.nomodule hook is invalid: "nomodule" not in a module
942 942 [255]
943 943
944 944 $ echo '[hooks]' > ../a/.hg/hgrc
945 945 $ echo 'preoutgoing.badmodule = python:nomodule.nowhere' >> ../a/.hg/hgrc
946 946 $ hg pull ../a
947 947 pulling from ../a
948 948 searching for changes
949 949 abort: preoutgoing.badmodule hook is invalid: import of "nomodule" failed
950 950 (run with --traceback for stack trace)
951 951 [255]
952 952
953 953 $ echo '[hooks]' > ../a/.hg/hgrc
954 954 $ echo 'preoutgoing.unreachable = python:hooktests.container.unreachable' >> ../a/.hg/hgrc
955 955 $ hg pull ../a
956 956 pulling from ../a
957 957 searching for changes
958 958 abort: preoutgoing.unreachable hook is invalid: import of "hooktests.container" failed
959 959 (run with --traceback for stack trace)
960 960 [255]
961 961
962 962 $ echo '[hooks]' > ../a/.hg/hgrc
963 963 $ echo 'preoutgoing.syntaxerror = python:syntaxerror.syntaxerror' >> ../a/.hg/hgrc
964 964 $ hg pull ../a
965 965 pulling from ../a
966 966 searching for changes
967 967 abort: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
968 968 (run with --traceback for stack trace)
969 969 [255]
970 970
971 971 The second egrep is to filter out lines like ' ^', which are slightly
972 972 different between Python 2.6 and Python 2.7.
973 973 $ hg pull ../a --traceback 2>&1 | egrep -v '^( +File| [_a-zA-Z*(])' | egrep -v '^( )+(\^)?$'
974 974 pulling from ../a
975 975 searching for changes
976 976 exception from first failed import attempt:
977 977 Traceback (most recent call last):
978 978 SyntaxError: * (glob)
979 979 exception from second failed import attempt:
980 980 Traceback (most recent call last):
981 981 ImportError: No module named hgext_syntaxerror
982 982 Traceback (most recent call last):
983 HookLoadError: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
983 HookLoadError: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed (no-py3 !)
984 mercurial.error.HookLoadError: b'preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed' (py3 !)
984 985 abort: preoutgoing.syntaxerror hook is invalid: import of "syntaxerror" failed
985 986
986 987 $ echo '[hooks]' > ../a/.hg/hgrc
987 988 $ echo 'preoutgoing.pass = python:hooktests.passhook' >> ../a/.hg/hgrc
988 989 $ hg pull ../a
989 990 pulling from ../a
990 991 searching for changes
991 992 hook args:
992 993 hooktype preoutgoing
993 994 source pull
994 995 adding changesets
995 996 adding manifests
996 997 adding file changes
997 998 adding remote bookmark quux
998 999 added 1 changesets with 1 changes to 1 files
999 1000 new changesets 539e4b31b6dc
1000 1001 (run 'hg update' to get a working copy)
1001 1002
1002 1003 post- python hooks that fail to *run* don't cause an abort
1003 1004 $ rm ../a/.hg/hgrc
1004 1005 $ echo '[hooks]' > .hg/hgrc
1005 1006 $ echo 'post-pull.broken = python:hooktests.brokenhook' >> .hg/hgrc
1006 1007 $ hg pull ../a
1007 1008 pulling from ../a
1008 1009 searching for changes
1009 1010 no changes found
1010 1011 error: post-pull.broken hook raised an exception: unsupported operand type(s) for +: 'int' and 'dict'
1011 1012 (run with --traceback for stack trace)
1012 1013
1013 1014 but post- python hooks that fail to *load* do
1014 1015 $ echo '[hooks]' > .hg/hgrc
1015 1016 $ echo 'post-pull.nomodule = python:nomodule' >> .hg/hgrc
1016 1017 $ hg pull ../a
1017 1018 pulling from ../a
1018 1019 searching for changes
1019 1020 no changes found
1020 1021 abort: post-pull.nomodule hook is invalid: "nomodule" not in a module
1021 1022 [255]
1022 1023
1023 1024 $ echo '[hooks]' > .hg/hgrc
1024 1025 $ echo 'post-pull.badmodule = python:nomodule.nowhere' >> .hg/hgrc
1025 1026 $ hg pull ../a
1026 1027 pulling from ../a
1027 1028 searching for changes
1028 1029 no changes found
1029 1030 abort: post-pull.badmodule hook is invalid: import of "nomodule" failed
1030 1031 (run with --traceback for stack trace)
1031 1032 [255]
1032 1033
1033 1034 $ echo '[hooks]' > .hg/hgrc
1034 1035 $ echo 'post-pull.nohook = python:hooktests.nohook' >> .hg/hgrc
1035 1036 $ hg pull ../a
1036 1037 pulling from ../a
1037 1038 searching for changes
1038 1039 no changes found
1039 1040 abort: post-pull.nohook hook is invalid: "hooktests.nohook" is not defined
1040 1041 [255]
1041 1042
1042 1043 make sure --traceback works
1043 1044
1044 1045 $ echo '[hooks]' > .hg/hgrc
1045 1046 $ echo 'commit.abort = python:hooktests.aborthook' >> .hg/hgrc
1046 1047
1047 1048 $ echo aa > a
1048 1049 $ hg --traceback commit -d '0 0' -ma 2>&1 | grep '^Traceback'
1049 1050 Traceback (most recent call last):
1050 1051
1051 1052 $ cd ..
1052 1053 $ hg init c
1053 1054 $ cd c
1054 1055
1055 1056 $ cat > hookext.py <<EOF
1056 1057 > def autohook(ui, **args):
1057 1058 > ui.write(b'Automatically installed hook\n')
1058 1059 >
1059 1060 > def reposetup(ui, repo):
1060 1061 > repo.ui.setconfig(b"hooks", b"commit.auto", autohook)
1061 1062 > EOF
1062 1063 $ echo '[extensions]' >> .hg/hgrc
1063 1064 $ echo 'hookext = hookext.py' >> .hg/hgrc
1064 1065
1065 1066 $ touch foo
1066 1067 $ hg add foo
1067 1068 $ hg ci -d '0 0' -m 'add foo'
1068 1069 Automatically installed hook
1069 1070 $ echo >> foo
1070 1071 $ hg ci --debug -d '0 0' -m 'change foo'
1071 1072 committing files:
1072 1073 foo
1073 1074 committing manifest
1074 1075 committing changelog
1075 1076 updating the branch cache
1076 1077 committed changeset 1:52998019f6252a2b893452765fcb0a47351a5708
1077 1078 calling hook commit.auto: hgext_hookext.autohook
1078 1079 Automatically installed hook
1079 1080
1080 1081 $ hg showconfig hooks
1081 1082 hooks.commit.auto=<function autohook at *> (glob)
1082 1083
1083 1084 test python hook configured with python:[file]:[hook] syntax
1084 1085
1085 1086 $ cd ..
1086 1087 $ mkdir d
1087 1088 $ cd d
1088 1089 $ hg init repo
1089 1090 $ mkdir hooks
1090 1091
1091 1092 $ cd hooks
1092 1093 $ cat > testhooks.py <<EOF
1093 1094 > def testhook(ui, **args):
1094 1095 > ui.write(b'hook works\n')
1095 1096 > EOF
1096 1097 $ echo '[hooks]' > ../repo/.hg/hgrc
1097 1098 $ echo "pre-commit.test = python:`pwd`/testhooks.py:testhook" >> ../repo/.hg/hgrc
1098 1099
1099 1100 $ cd ../repo
1100 1101 $ hg commit -d '0 0'
1101 1102 hook works
1102 1103 nothing changed
1103 1104 [1]
1104 1105
1105 1106 $ echo '[hooks]' > .hg/hgrc
1106 1107 $ echo "update.ne = python:`pwd`/nonexistent.py:testhook" >> .hg/hgrc
1107 1108 $ echo "pre-identify.npmd = python:`pwd`/:no_python_module_dir" >> .hg/hgrc
1108 1109
1109 1110 $ hg up null
1110 1111 loading update.ne hook failed:
1111 1112 abort: $ENOENT$: '$TESTTMP/d/repo/nonexistent.py'
1112 1113 [255]
1113 1114
1114 1115 $ hg id
1115 1116 loading pre-identify.npmd hook failed:
1116 1117 abort: No module named repo! (no-py3 !)
1117 1118 abort: No module named 'repo'! (py3 !)
1118 1119 [255]
1119 1120
1120 1121 $ cd ../../b
1121 1122
1122 1123 make sure --traceback works on hook import failure
1123 1124
1124 1125 $ cat > importfail.py <<EOF
1125 1126 > import somebogusmodule
1126 1127 > # dereference something in the module to force demandimport to load it
1127 1128 > somebogusmodule.whatever
1128 1129 > EOF
1129 1130
1130 1131 $ echo '[hooks]' > .hg/hgrc
1131 1132 $ echo 'precommit.importfail = python:importfail.whatever' >> .hg/hgrc
1132 1133
1133 1134 $ echo a >> a
1134 1135 $ hg --traceback commit -ma 2>&1 | egrep -v '^( +File| [a-zA-Z(])'
1135 1136 exception from first failed import attempt:
1136 1137 Traceback (most recent call last):
1137 1138 ImportError: No module named somebogusmodule
1138 1139 exception from second failed import attempt:
1139 1140 Traceback (most recent call last):
1140 1141 ImportError: No module named hgext_importfail
1141 1142 Traceback (most recent call last):
1142 HookLoadError: precommit.importfail hook is invalid: import of "importfail" failed
1143 HookLoadError: precommit.importfail hook is invalid: import of "importfail" failed (no-py3 !)
1144 mercurial.error.HookLoadError: b'precommit.importfail hook is invalid: import of "importfail" failed' (py3 !)
1143 1145 abort: precommit.importfail hook is invalid: import of "importfail" failed
1144 1146
1145 1147 Issue1827: Hooks Update & Commit not completely post operation
1146 1148
1147 1149 commit and update hooks should run after command completion. The largefiles
1148 1150 use demonstrates a recursive wlock, showing the hook doesn't run until the
1149 1151 final release (and dirstate flush).
1150 1152
1151 1153 $ echo '[hooks]' > .hg/hgrc
1152 1154 $ echo 'commit = hg id' >> .hg/hgrc
1153 1155 $ echo 'update = hg id' >> .hg/hgrc
1154 1156 $ echo bb > a
1155 1157 $ hg ci -ma
1156 1158 223eafe2750c tip
1157 1159 $ hg up 0 --config extensions.largefiles=
1158 1160 The fsmonitor extension is incompatible with the largefiles extension and has been disabled. (fsmonitor !)
1159 1161 cb9a9f314b8b
1160 1162 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1161 1163
1162 1164 make sure --verbose (and --quiet/--debug etc.) are propagated to the local ui
1163 1165 that is passed to pre/post hooks
1164 1166
1165 1167 $ echo '[hooks]' > .hg/hgrc
1166 1168 $ echo 'pre-identify = python:hooktests.verbosehook' >> .hg/hgrc
1167 1169 $ hg id
1168 1170 cb9a9f314b8b
1169 1171 $ hg id --verbose
1170 1172 calling hook pre-identify: hooktests.verbosehook
1171 1173 verbose output from hook
1172 1174 cb9a9f314b8b
1173 1175
1174 1176 Ensure hooks can be prioritized
1175 1177
1176 1178 $ echo '[hooks]' > .hg/hgrc
1177 1179 $ echo 'pre-identify.a = python:hooktests.verbosehook' >> .hg/hgrc
1178 1180 $ echo 'pre-identify.b = python:hooktests.verbosehook' >> .hg/hgrc
1179 1181 $ echo 'priority.pre-identify.b = 1' >> .hg/hgrc
1180 1182 $ echo 'pre-identify.c = python:hooktests.verbosehook' >> .hg/hgrc
1181 1183 $ hg id --verbose
1182 1184 calling hook pre-identify.b: hooktests.verbosehook
1183 1185 verbose output from hook
1184 1186 calling hook pre-identify.a: hooktests.verbosehook
1185 1187 verbose output from hook
1186 1188 calling hook pre-identify.c: hooktests.verbosehook
1187 1189 verbose output from hook
1188 1190 cb9a9f314b8b
1189 1191
1190 1192 new tags must be visible in pretxncommit (issue3210)
1191 1193
1192 1194 $ echo 'pretxncommit.printtags = python:hooktests.printtags' >> .hg/hgrc
1193 1195 $ hg tag -f foo
1194 1196 [a, foo, tip]
1195 1197
1196 1198 post-init hooks must not crash (issue4983)
1197 1199 This also creates the `to` repo for the next test block.
1198 1200
1199 1201 $ cd ..
1200 1202 $ cat << EOF >> hgrc-with-post-init-hook
1201 1203 > [hooks]
1202 1204 > post-init = sh -c "printenv.py --line post-init"
1203 1205 > EOF
1204 1206 $ HGRCPATH=hgrc-with-post-init-hook hg init to
1205 1207 post-init hook: HG_ARGS=init to
1206 1208 HG_HOOKNAME=post-init
1207 1209 HG_HOOKTYPE=post-init
1208 1210 HG_OPTS={'insecure': None, 'remotecmd': '', 'ssh': ''}
1209 1211 HG_PATS=['to']
1210 1212 HG_RESULT=0
1211 1213
1212 1214
1213 1215 new commits must be visible in pretxnchangegroup (issue3428)
1214 1216
1215 1217 $ echo '[hooks]' >> to/.hg/hgrc
1216 1218 $ echo 'prechangegroup = hg --traceback tip' >> to/.hg/hgrc
1217 1219 $ echo 'pretxnchangegroup = hg --traceback tip' >> to/.hg/hgrc
1218 1220 $ echo a >> to/a
1219 1221 $ hg --cwd to ci -Ama
1220 1222 adding a
1221 1223 $ hg clone to from
1222 1224 updating to branch default
1223 1225 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
1224 1226 $ echo aa >> from/a
1225 1227 $ hg --cwd from ci -mb
1226 1228 $ hg --cwd from push
1227 1229 pushing to $TESTTMP/to
1228 1230 searching for changes
1229 1231 changeset: 0:cb9a9f314b8b
1230 1232 tag: tip
1231 1233 user: test
1232 1234 date: Thu Jan 01 00:00:00 1970 +0000
1233 1235 summary: a
1234 1236
1235 1237 adding changesets
1236 1238 adding manifests
1237 1239 adding file changes
1238 1240 changeset: 1:9836a07b9b9d
1239 1241 tag: tip
1240 1242 user: test
1241 1243 date: Thu Jan 01 00:00:00 1970 +0000
1242 1244 summary: b
1243 1245
1244 1246 added 1 changesets with 1 changes to 1 files
1245 1247
1246 1248 pretxnclose hook failure should abort the transaction
1247 1249
1248 1250 $ hg init txnfailure
1249 1251 $ cd txnfailure
1250 1252 $ touch a && hg commit -Aqm a
1251 1253 $ cat >> .hg/hgrc <<EOF
1252 1254 > [hooks]
1253 1255 > pretxnclose.error = exit 1
1254 1256 > EOF
1255 1257 $ hg strip -r 0 --config extensions.strip=
1256 1258 0 files updated, 0 files merged, 1 files removed, 0 files unresolved
1257 1259 saved backup bundle to * (glob)
1258 1260 transaction abort!
1259 1261 rollback completed
1260 1262 strip failed, backup bundle stored in * (glob)
1261 1263 abort: pretxnclose.error hook exited with status 1
1262 1264 [255]
1263 1265 $ hg recover
1264 1266 no interrupted transaction available
1265 1267 [1]
1266 1268 $ cd ..
1267 1269
1268 1270 check whether HG_PENDING makes pending changes only in related
1269 1271 repositories visible to an external hook.
1270 1272
1271 1273 (emulate a transaction running concurrently by copied
1272 1274 .hg/store/00changelog.i.a in subsequent test)
1273 1275
1274 1276 $ cat > $TESTTMP/savepending.sh <<EOF
1275 1277 > cp .hg/store/00changelog.i.a .hg/store/00changelog.i.a.saved
1276 1278 > exit 1 # to avoid adding new revision for subsequent tests
1277 1279 > EOF
1278 1280 $ cd a
1279 1281 $ hg tip -q
1280 1282 4:539e4b31b6dc
1281 1283 $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" commit -m "invisible"
1282 1284 transaction abort!
1283 1285 rollback completed
1284 1286 abort: pretxnclose hook exited with status 1
1285 1287 [255]
1286 1288 $ cp .hg/store/00changelog.i.a.saved .hg/store/00changelog.i.a
1287 1289
1288 1290 (check (in)visibility of new changeset while transaction running in
1289 1291 repo)
1290 1292
1291 1293 $ cat > $TESTTMP/checkpending.sh <<EOF
1292 1294 > echo '@a'
1293 1295 > hg -R "$TESTTMP/a" tip -q
1294 1296 > echo '@a/nested'
1295 1297 > hg -R "$TESTTMP/a/nested" tip -q
1296 1298 > exit 1 # to avoid adding new revision for subsequent tests
1297 1299 > EOF
1298 1300 $ hg init nested
1299 1301 $ cd nested
1300 1302 $ echo a > a
1301 1303 $ hg add a
1302 1304 $ hg --config hooks.pretxnclose="sh $TESTTMP/checkpending.sh" commit -m '#0'
1303 1305 @a
1304 1306 4:539e4b31b6dc
1305 1307 @a/nested
1306 1308 0:bf5e395ced2c
1307 1309 transaction abort!
1308 1310 rollback completed
1309 1311 abort: pretxnclose hook exited with status 1
1310 1312 [255]
1311 1313
1312 1314 Hook from untrusted hgrc are reported as failure
1313 1315 ================================================
1314 1316
1315 1317 $ cat << EOF > $TESTTMP/untrusted.py
1316 1318 > from mercurial import scmutil, util
1317 1319 > def uisetup(ui):
1318 1320 > class untrustedui(ui.__class__):
1319 1321 > def _trusted(self, fp, f):
1320 1322 > if util.normpath(fp.name).endswith(b'untrusted/.hg/hgrc'):
1321 1323 > return False
1322 1324 > return super(untrustedui, self)._trusted(fp, f)
1323 1325 > ui.__class__ = untrustedui
1324 1326 > EOF
1325 1327 $ cat << EOF >> $HGRCPATH
1326 1328 > [extensions]
1327 1329 > untrusted=$TESTTMP/untrusted.py
1328 1330 > EOF
1329 1331 $ hg init untrusted
1330 1332 $ cd untrusted
1331 1333
1332 1334 Non-blocking hook
1333 1335 -----------------
1334 1336
1335 1337 $ cat << EOF >> .hg/hgrc
1336 1338 > [hooks]
1337 1339 > txnclose.testing=echo txnclose hook called
1338 1340 > EOF
1339 1341 $ touch a && hg commit -Aqm a
1340 1342 warning: untrusted hook txnclose.testing not executed
1341 1343 $ hg log
1342 1344 changeset: 0:3903775176ed
1343 1345 tag: tip
1344 1346 user: test
1345 1347 date: Thu Jan 01 00:00:00 1970 +0000
1346 1348 summary: a
1347 1349
1348 1350
1349 1351 Non-blocking hook
1350 1352 -----------------
1351 1353
1352 1354 $ cat << EOF >> .hg/hgrc
1353 1355 > [hooks]
1354 1356 > pretxnclose.testing=echo pre-txnclose hook called
1355 1357 > EOF
1356 1358 $ touch b && hg commit -Aqm a
1357 1359 transaction abort!
1358 1360 rollback completed
1359 1361 abort: untrusted hook pretxnclose.testing not executed
1360 1362 (see 'hg help config.trusted')
1361 1363 [255]
1362 1364 $ hg log
1363 1365 changeset: 0:3903775176ed
1364 1366 tag: tip
1365 1367 user: test
1366 1368 date: Thu Jan 01 00:00:00 1970 +0000
1367 1369 summary: a
1368 1370
General Comments 0
You need to be logged in to leave comments. Login now