Debian Codegraph @

tests/test-hook.t

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