Mercurial > hg
comparison tests/test-bundle2-exchange.t @ 25485:8182163ae983
push: catch and process PushkeyFailed error
We add a way to register "pushkey failure callback" that will be used if the
push is aborted by a pushkey failure. A part generator adding mandatory pushkey
parts should register a failure callback for all of them. The callback will be
in charge of generating a meaningful abort if this part fails.
If no callback is registered, the error is propagated.
Catch PushkeyFailed error in exchange.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Fri, 05 Jun 2015 16:30:11 -0700 |
parents | 6de96cb31176 |
children | d8e7b0781ad7 |
comparison
equal
deleted
inserted
replaced
25484:a5192774e925 | 25485:8182163ae983 |
---|---|
722 | 722 |
723 $ cat > mandatorypart.py << EOF | 723 $ cat > mandatorypart.py << EOF |
724 > from mercurial import exchange | 724 > from mercurial import exchange |
725 > from mercurial import pushkey | 725 > from mercurial import pushkey |
726 > from mercurial import node | 726 > from mercurial import node |
727 > from mercurial import error | |
727 > @exchange.b2partsgenerator('failingpuskey') | 728 > @exchange.b2partsgenerator('failingpuskey') |
728 > def addfailingpushey(pushop, bundler): | 729 > def addfailingpushey(pushop, bundler): |
729 > enc = pushkey.encode | 730 > enc = pushkey.encode |
730 > part = bundler.newpart('pushkey') | 731 > part = bundler.newpart('pushkey') |
731 > part.addparam('namespace', enc('phases')) | 732 > part.addparam('namespace', enc('phases')) |
732 > part.addparam('key', enc(pushop.repo['cd010b8cd998'].hex())) | 733 > part.addparam('key', enc(pushop.repo['cd010b8cd998'].hex())) |
733 > part.addparam('old', enc(str(0))) # successful update | 734 > part.addparam('old', enc(str(0))) # successful update |
734 > part.addparam('new', enc(str(0))) | 735 > part.addparam('new', enc(str(0))) |
736 > def fail(pushop, exc): | |
737 > raise error.Abort('Correct phase push failed (because hooks)') | |
738 > pushop.pkfailcb[part.id] = fail | |
735 > EOF | 739 > EOF |
736 $ cat >> $HGRCPATH << EOF | 740 $ cat >> $HGRCPATH << EOF |
737 > [hooks] | 741 > [hooks] |
738 > pretxnchangegroup= | 742 > pretxnchangegroup= |
739 > pretxnclose.failpush= | 743 > pretxnclose.failpush= |
757 do not push the key ! | 761 do not push the key ! |
758 pushkey-abort: prepushkey.failpush hook exited with status 1 | 762 pushkey-abort: prepushkey.failpush hook exited with status 1 |
759 transaction abort! | 763 transaction abort! |
760 Cleaning up the mess... | 764 Cleaning up the mess... |
761 rollback completed | 765 rollback completed |
762 abort: failed to update value for "phases/cd010b8cd998f3981a5a8115f94f8da4ab506089" | 766 abort: Correct phase push failed (because hooks) |
763 [255] | 767 [255] |
764 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6 | 768 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6 |
765 pushing to ssh://user@dummy/other | 769 pushing to ssh://user@dummy/other |
766 searching for changes | 770 searching for changes |
767 remote: adding changesets | 771 remote: adding changesets |
794 | 798 |
795 $ cat > mandatorypart.py << EOF | 799 $ cat > mandatorypart.py << EOF |
796 > from mercurial import exchange | 800 > from mercurial import exchange |
797 > from mercurial import pushkey | 801 > from mercurial import pushkey |
798 > from mercurial import node | 802 > from mercurial import node |
803 > from mercurial import error | |
799 > @exchange.b2partsgenerator('failingpuskey') | 804 > @exchange.b2partsgenerator('failingpuskey') |
800 > def addfailingpushey(pushop, bundler): | 805 > def addfailingpushey(pushop, bundler): |
801 > enc = pushkey.encode | 806 > enc = pushkey.encode |
802 > part = bundler.newpart('pushkey') | 807 > part = bundler.newpart('pushkey') |
803 > part.addparam('namespace', enc('phases')) | 808 > part.addparam('namespace', enc('phases')) |
804 > part.addparam('key', enc(pushop.repo['cd010b8cd998'].hex())) | 809 > part.addparam('key', enc(pushop.repo['cd010b8cd998'].hex())) |
805 > part.addparam('old', enc(str(4))) # will fail | 810 > part.addparam('old', enc(str(4))) # will fail |
806 > part.addparam('new', enc(str(3))) | 811 > part.addparam('new', enc(str(3))) |
812 > def fail(pushop, exc): | |
813 > raise error.Abort('Clown phase push failed') | |
814 > pushop.pkfailcb[part.id] = fail | |
807 > EOF | 815 > EOF |
808 $ cat >> $HGRCPATH << EOF | 816 $ cat >> $HGRCPATH << EOF |
809 > [hooks] | 817 > [hooks] |
810 > prepushkey.failpush = | 818 > prepushkey.failpush = |
811 > EOF | 819 > EOF |
824 Cleaning up the mess... | 832 Cleaning up the mess... |
825 rollback completed | 833 rollback completed |
826 pushkey: lock state after "phases" | 834 pushkey: lock state after "phases" |
827 lock: free | 835 lock: free |
828 wlock: free | 836 wlock: free |
829 abort: failed to update value for "phases/cd010b8cd998f3981a5a8115f94f8da4ab506089" | 837 abort: Clown phase push failed |
830 [255] | 838 [255] |
831 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6 | 839 $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6 |
832 pushing to ssh://user@dummy/other | 840 pushing to ssh://user@dummy/other |
833 searching for changes | 841 searching for changes |
834 remote: adding changesets | 842 remote: adding changesets |