comparison tests/test-bundle2-pushback.t @ 23439:743736fc7c41

bundle2-push: provide transaction to reply unbundler This patch series is intended to allow bundle2 push reply part handlers to make changes to the local repository; it has been developed in parallel with an extension that allows the server to rebase incoming changesets while applying them. This diff adds an experimental config option "bundle2.pushback" which provides a transaction to the reply unbundler during a push operation. This behavior is opt-in because of potential security issues: the response can contain any part type that has a handler defined, allowing the server to make arbitrary changes to the local repository.
author Eric Sumner <ericsumner@fb.com>
date Fri, 21 Nov 2014 15:50:38 -0800
parents
children e0e28e910fa3
comparison
equal deleted inserted replaced
23438:6e0ecb9a2e19 23439:743736fc7c41
1 $ cat > bundle2.py << EOF
2 > """A small extension to test bundle2 pushback parts.
3 > Current bundle2 implementation doesn't provide a way to generate those
4 > parts, so they must be created by extensions.
5 > """
6 > from mercurial import bundle2, pushkey, exchange, util
7 > def _newhandlechangegroup(op, inpart):
8 > """This function wraps the changegroup part handler for getbundle.
9 > It issues an additional b2x:pushkey part to send a new
10 > bookmark back to the client"""
11 > result = bundle2.handlechangegroup(op, inpart)
12 > if 'b2x:pushback' in op.reply.capabilities:
13 > params = {'namespace': 'bookmarks',
14 > 'key': 'new-server-mark',
15 > 'old': '',
16 > 'new': 'tip'}
17 > encodedparams = [(k, pushkey.encode(v)) for (k,v) in params.items()]
18 > op.reply.newpart('b2x:pushkey', mandatoryparams=encodedparams)
19 > else:
20 > op.reply.newpart('b2x:output', data='pushback not enabled')
21 > return result
22 > _newhandlechangegroup.params = bundle2.handlechangegroup.params
23 > bundle2.parthandlermapping['b2x:changegroup'] = _newhandlechangegroup
24 > EOF
25
26 $ cat >> $HGRCPATH <<EOF
27 > [ui]
28 > ssh = python "$TESTDIR/dummyssh"
29 > username = nobody <no.reply@example.com>
30 >
31 > [alias]
32 > tglog = log -G -T "{desc} [{phase}:{node|short}]"
33 > EOF
34
35 Set up server repository
36
37 $ hg init server
38 $ cd server
39 $ echo c0 > f0
40 $ hg commit -Am 0
41 adding f0
42
43 Set up client repository
44
45 $ cd ..
46 $ hg clone ssh://user@dummy/server client -q
47 $ cd client
48
49 Enable extension
50 $ cat >> $HGRCPATH <<EOF
51 > [extensions]
52 > bundle2=$TESTTMP/bundle2.py
53 > [experimental]
54 > bundle2-exp = True
55 > EOF
56
57 Without config
58
59 $ cd ../client
60 $ echo c1 > f1
61 $ hg commit -Am 1
62 adding f1
63 $ hg push
64 pushing to ssh://user@dummy/server
65 searching for changes
66 remote: pushback not enabled
67 remote: adding changesets
68 remote: adding manifests
69 remote: adding file changes
70 remote: added 1 changesets with 1 changes to 1 files
71 $ hg bookmark
72 no bookmarks set
73
74 $ cd ../server
75 $ hg tglog
76 o 1 [public:2b9c7234e035]
77 |
78 @ 0 [public:6cee5c8f3e5b]
79
80
81
82
83 With config
84
85 $ cd ../client
86 $ echo '[experimental]' >> .hg/hgrc
87 $ echo 'bundle2.pushback = True' >> .hg/hgrc
88 $ echo c2 > f2
89 $ hg commit -Am 2
90 adding f2
91 $ hg push
92 pushing to ssh://user@dummy/server
93 searching for changes
94 remote: adding changesets
95 remote: adding manifests
96 remote: adding file changes
97 remote: added 1 changesets with 1 changes to 1 files
98 $ hg bookmark
99 new-server-mark 2:0a76dfb2e179
100
101 $ cd ../server
102 $ hg tglog
103 o 2 [public:0a76dfb2e179]
104 |
105 o 1 [public:2b9c7234e035]
106 |
107 @ 0 [public:6cee5c8f3e5b]
108
109
110
111