Mercurial > hg
comparison tests/test-hook.t @ 46417:768056549737
errors: use exit code 40 for when a hook fails
A hook can be used for checking inputs, state, configuration,
security, etc., so it's unclear which of the existing exit codes to
use. Let's instead add one specifically for failed hooks. I picked 40.
Differential Revision: https://phab.mercurial-scm.org/D9910
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 29 Jan 2021 12:16:55 -0800 |
parents | 95c4cca641f6 |
children | d67732a4b58a |
comparison
equal
deleted
inserted
replaced
46416:bc3f3b59d0a4 | 46417:768056549737 |
---|---|
225 HG_HOOKTYPE=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': ''} | 226 HG_OPTS={'bookmarks': None, 'branch': None, 'id': None, 'insecure': None, 'num': None, 'remotecmd': '', 'rev': '', 'ssh': '', 'tags': None, 'template': ''} |
227 HG_PATS=[] | 227 HG_PATS=[] |
228 | 228 |
229 abort: pre-identify hook exited with status 1 | 229 abort: pre-identify hook exited with status 1 |
230 [255] | 230 [40] |
231 $ hg cat b | 231 $ hg cat b |
232 pre-cat hook: HG_ARGS=cat b | 232 pre-cat hook: HG_ARGS=cat b |
233 HG_HOOKNAME=pre-cat | 233 HG_HOOKNAME=pre-cat |
234 HG_HOOKTYPE=pre-cat | 234 HG_HOOKTYPE=pre-cat |
235 HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': '', 'template': ''} | 235 HG_OPTS={'decode': None, 'exclude': [], 'include': [], 'output': '', 'rev': '', 'template': ''} |
388 HG_LOCAL=0 | 388 HG_LOCAL=0 |
389 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 | 389 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
390 HG_TAG=fa | 390 HG_TAG=fa |
391 | 391 |
392 abort: pretag.forbid hook exited with status 1 | 392 abort: pretag.forbid hook exited with status 1 |
393 [255] | 393 [40] |
394 $ hg tag -l fla | 394 $ hg tag -l fla |
395 pretag hook: HG_HOOKNAME=pretag | 395 pretag hook: HG_HOOKNAME=pretag |
396 HG_HOOKTYPE=pretag | 396 HG_HOOKTYPE=pretag |
397 HG_LOCAL=1 | 397 HG_LOCAL=1 |
398 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 | 398 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
403 HG_LOCAL=1 | 403 HG_LOCAL=1 |
404 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 | 404 HG_NODE=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
405 HG_TAG=fla | 405 HG_TAG=fla |
406 | 406 |
407 abort: pretag.forbid hook exited with status 1 | 407 abort: pretag.forbid hook exited with status 1 |
408 [255] | 408 [40] |
409 | 409 |
410 pretxncommit hook can see changeset, can roll back txn, changeset no | 410 pretxncommit hook can see changeset, can roll back txn, changeset no |
411 more there after | 411 more there after |
412 | 412 |
413 $ cat >> .hg/hgrc <<EOF | 413 $ cat >> .hg/hgrc <<EOF |
449 HG_TXNID=TXN:$ID$ | 449 HG_TXNID=TXN:$ID$ |
450 HG_TXNNAME=commit | 450 HG_TXNNAME=commit |
451 | 451 |
452 rollback completed | 452 rollback completed |
453 abort: pretxncommit.forbid1 hook exited with status 1 | 453 abort: pretxncommit.forbid1 hook exited with status 1 |
454 [255] | 454 [40] |
455 $ hg -q tip | 455 $ hg -q tip |
456 4:539e4b31b6dc | 456 4:539e4b31b6dc |
457 | 457 |
458 (Check that no 'changelog.i.a' file were left behind) | 458 (Check that no 'changelog.i.a' file were left behind) |
459 | 459 |
483 precommit.forbid hook: HG_HOOKNAME=precommit.forbid | 483 precommit.forbid hook: HG_HOOKNAME=precommit.forbid |
484 HG_HOOKTYPE=precommit | 484 HG_HOOKTYPE=precommit |
485 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 | 485 HG_PARENT1=539e4b31b6dc99b3cfbaa6b53cbc1c1f9a1e3a10 |
486 | 486 |
487 abort: precommit.forbid hook exited with status 1 | 487 abort: precommit.forbid hook exited with status 1 |
488 [255] | 488 [40] |
489 $ hg -q tip | 489 $ hg -q tip |
490 4:539e4b31b6dc | 490 4:539e4b31b6dc |
491 | 491 |
492 preupdate hook can prevent update | 492 preupdate hook can prevent update |
493 | 493 |
642 HG_TXNID=TXN:$ID$ | 642 HG_TXNID=TXN:$ID$ |
643 HG_TXNNAME=push | 643 HG_TXNNAME=push |
644 HG_URL=file:$TESTTMP/a | 644 HG_URL=file:$TESTTMP/a |
645 | 645 |
646 abort: prepushkey hook exited with status 1 | 646 abort: prepushkey hook exited with status 1 |
647 [255] | 647 [40] |
648 $ cd ../a | 648 $ cd ../a |
649 | 649 |
650 test that prelistkeys can prevent listing keys | 650 test that prelistkeys can prevent listing keys |
651 | 651 |
652 $ cat >> .hg/hgrc <<EOF | 652 $ cat >> .hg/hgrc <<EOF |
677 prelistkeys.forbid hook: HG_HOOKNAME=prelistkeys | 677 prelistkeys.forbid hook: HG_HOOKNAME=prelistkeys |
678 HG_HOOKTYPE=prelistkeys | 678 HG_HOOKTYPE=prelistkeys |
679 HG_NAMESPACE=bookmarks | 679 HG_NAMESPACE=bookmarks |
680 | 680 |
681 abort: prelistkeys hook exited with status 1 | 681 abort: prelistkeys hook exited with status 1 |
682 [255] | 682 [40] |
683 $ cd ../a | 683 $ cd ../a |
684 $ rm .hg/hgrc | 684 $ rm .hg/hgrc |
685 | 685 |
686 prechangegroup hook can prevent incoming changes | 686 prechangegroup hook can prevent incoming changes |
687 | 687 |
702 HG_TXNNAME=pull | 702 HG_TXNNAME=pull |
703 file:/*/$TESTTMP/a (glob) | 703 file:/*/$TESTTMP/a (glob) |
704 HG_URL=file:$TESTTMP/a | 704 HG_URL=file:$TESTTMP/a |
705 | 705 |
706 abort: prechangegroup.forbid hook exited with status 1 | 706 abort: prechangegroup.forbid hook exited with status 1 |
707 [255] | 707 [40] |
708 | 708 |
709 pretxnchangegroup hook can see incoming changes, can roll back txn, | 709 pretxnchangegroup hook can see incoming changes, can roll back txn, |
710 incoming changes no longer there after | 710 incoming changes no longer there after |
711 | 711 |
712 $ cat > .hg/hgrc <<EOF | 712 $ cat > .hg/hgrc <<EOF |
733 HG_URL=file:$TESTTMP/a | 733 HG_URL=file:$TESTTMP/a |
734 | 734 |
735 transaction abort! | 735 transaction abort! |
736 rollback completed | 736 rollback completed |
737 abort: pretxnchangegroup.forbid1 hook exited with status 1 | 737 abort: pretxnchangegroup.forbid1 hook exited with status 1 |
738 [255] | 738 [40] |
739 $ hg -q tip | 739 $ hg -q tip |
740 3:07f3376c1e65 | 740 3:07f3376c1e65 |
741 | 741 |
742 outgoing hooks can see env vars | 742 outgoing hooks can see env vars |
743 | 743 |
784 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid | 784 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid |
785 HG_HOOKTYPE=preoutgoing | 785 HG_HOOKTYPE=preoutgoing |
786 HG_SOURCE=pull | 786 HG_SOURCE=pull |
787 | 787 |
788 abort: preoutgoing.forbid hook exited with status 1 | 788 abort: preoutgoing.forbid hook exited with status 1 |
789 [255] | 789 [40] |
790 | 790 |
791 outgoing hooks work for local clones | 791 outgoing hooks work for local clones |
792 | 792 |
793 $ cd .. | 793 $ cd .. |
794 $ cat > a/.hg/hgrc <<EOF | 794 $ cat > a/.hg/hgrc <<EOF |
823 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid | 823 preoutgoing.forbid hook: HG_HOOKNAME=preoutgoing.forbid |
824 HG_HOOKTYPE=preoutgoing | 824 HG_HOOKTYPE=preoutgoing |
825 HG_SOURCE=clone | 825 HG_SOURCE=clone |
826 | 826 |
827 abort: preoutgoing.forbid hook exited with status 1 | 827 abort: preoutgoing.forbid hook exited with status 1 |
828 [255] | 828 [40] |
829 | 829 |
830 $ cd "$TESTTMP/b" | 830 $ cd "$TESTTMP/b" |
831 | 831 |
832 $ cat > hooktests.py <<EOF | 832 $ cat > hooktests.py <<EOF |
833 > from __future__ import print_function | 833 > from __future__ import print_function |
913 searching for changes | 913 searching for changes |
914 hook args: | 914 hook args: |
915 hooktype preoutgoing | 915 hooktype preoutgoing |
916 source pull | 916 source pull |
917 abort: preoutgoing.fail hook failed | 917 abort: preoutgoing.fail hook failed |
918 [255] | 918 [40] |
919 | 919 |
920 $ echo '[hooks]' > ../a/.hg/hgrc | 920 $ echo '[hooks]' > ../a/.hg/hgrc |
921 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc | 921 $ echo 'preoutgoing.uncallable = python:hooktests.uncallable' >> ../a/.hg/hgrc |
922 $ hg pull ../a | 922 $ hg pull ../a |
923 pulling from ../a | 923 pulling from ../a |
1281 saved backup bundle to * (glob) | 1281 saved backup bundle to * (glob) |
1282 transaction abort! | 1282 transaction abort! |
1283 rollback completed | 1283 rollback completed |
1284 strip failed, backup bundle stored in * (glob) | 1284 strip failed, backup bundle stored in * (glob) |
1285 abort: pretxnclose.error hook exited with status 1 | 1285 abort: pretxnclose.error hook exited with status 1 |
1286 [255] | 1286 [40] |
1287 $ hg recover | 1287 $ hg recover |
1288 no interrupted transaction available | 1288 no interrupted transaction available |
1289 [1] | 1289 [1] |
1290 $ cd .. | 1290 $ cd .. |
1291 | 1291 |
1304 4:539e4b31b6dc | 1304 4:539e4b31b6dc |
1305 $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" commit -m "invisible" | 1305 $ hg --config hooks.pretxnclose="sh $TESTTMP/savepending.sh" commit -m "invisible" |
1306 transaction abort! | 1306 transaction abort! |
1307 rollback completed | 1307 rollback completed |
1308 abort: pretxnclose hook exited with status 1 | 1308 abort: pretxnclose hook exited with status 1 |
1309 [255] | 1309 [40] |
1310 $ cp .hg/store/00changelog.i.a.saved .hg/store/00changelog.i.a | 1310 $ cp .hg/store/00changelog.i.a.saved .hg/store/00changelog.i.a |
1311 | 1311 |
1312 (check (in)visibility of new changeset while transaction running in | 1312 (check (in)visibility of new changeset while transaction running in |
1313 repo) | 1313 repo) |
1314 | 1314 |
1329 @a/nested | 1329 @a/nested |
1330 0:bf5e395ced2c | 1330 0:bf5e395ced2c |
1331 transaction abort! | 1331 transaction abort! |
1332 rollback completed | 1332 rollback completed |
1333 abort: pretxnclose hook exited with status 1 | 1333 abort: pretxnclose hook exited with status 1 |
1334 [255] | 1334 [40] |
1335 | 1335 |
1336 Hook from untrusted hgrc are reported as failure | 1336 Hook from untrusted hgrc are reported as failure |
1337 ================================================ | 1337 ================================================ |
1338 | 1338 |
1339 $ cat << EOF > $TESTTMP/untrusted.py | 1339 $ cat << EOF > $TESTTMP/untrusted.py |
1380 $ touch b && hg commit -Aqm a | 1380 $ touch b && hg commit -Aqm a |
1381 transaction abort! | 1381 transaction abort! |
1382 rollback completed | 1382 rollback completed |
1383 abort: untrusted hook pretxnclose.testing not executed | 1383 abort: untrusted hook pretxnclose.testing not executed |
1384 (see 'hg help config.trusted') | 1384 (see 'hg help config.trusted') |
1385 [255] | 1385 [40] |
1386 $ hg log | 1386 $ hg log |
1387 changeset: 0:3903775176ed | 1387 changeset: 0:3903775176ed |
1388 tag: tip | 1388 tag: tip |
1389 user: test | 1389 user: test |
1390 date: Thu Jan 01 00:00:00 1970 +0000 | 1390 date: Thu Jan 01 00:00:00 1970 +0000 |