~bzr-pqm/bzr/bzr.dev

1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
1
# Copyright (C) 2005 Robey Pointer <robey@lag.net>, Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
7
#
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
17
"""Tests for branches bound to an sftp branch."""
18
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
19
20
import os
21
1607.1.13 by Robert Collins
Add a clear_connection_cache to the SFTP transport and use it in fixing the bound branch test speed performance problem which was cause by the server thread timing out - it was blocked on a read and closing the client side causes the server to unblock and exit.
22
import bzrlib
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
23
from bzrlib.branch import Branch
24
from bzrlib.bzrdir import (BzrDir,
25
                           BzrDirFormat,
26
                           BzrDirFormat6,
27
                           BzrDirMetaFormat1,
28
                           )
29
import bzrlib.errors as errors
1505.1.30 by John Arbash Meinel
[merge] jam-integration 1495
30
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer, paramiko_loaded
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
31
32
33
class BoundSFTPBranch(TestCaseWithSFTPServer):
34
35
    def create_branches(self):
36
        self.build_tree(['base/', 'base/a', 'base/b'])
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
37
        old_format = BzrDirFormat.get_default_format()
38
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
39
        try:
40
            wt_base = BzrDir.create_standalone_workingtree('base')
41
        finally:
42
            BzrDirFormat.set_default_format(old_format)
43
    
44
        b_base = wt_base.branch
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
45
46
        wt_base.add('a')
47
        wt_base.add('b')
48
        wt_base.commit('first', rev_id='r@b-1')
49
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
50
        wt_child = b_base.bzrdir.sprout('child').open_workingtree()
51
        self.sftp_base = Branch.open(self.get_url('base'))
52
        wt_child.branch.bind(self.sftp_base)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
53
        # check the branch histories are ready for using in tests.
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
54
        self.assertEqual(['r@b-1'], b_base.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
55
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
56
        return b_base, wt_child
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
57
1607.1.13 by Robert Collins
Add a clear_connection_cache to the SFTP transport and use it in fixing the bound branch test speed performance problem which was cause by the server thread timing out - it was blocked on a read and closing the client side causes the server to unblock and exit.
58
    def tearDown(self):
59
        self.sftp_base = None
60
        bzrlib.transport.sftp.clear_connection_cache()
61
        super(BoundSFTPBranch, self).tearDown()
62
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
63
    def test_simple_binding(self):
64
        self.build_tree(['base/', 'base/a', 'base/b', 'child/'])
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
65
        wt_base = BzrDir.create_standalone_workingtree('base')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
66
67
        wt_base.add('a')
68
        wt_base.add('b')
69
        wt_base.commit('first', rev_id='r@b-1')
70
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
71
        b_base = wt_base.branch
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
72
        # manually make a branch we can bind, because the default format
73
        # may not be bindable-from, and we want to test the side effects etc
74
        # of bondage.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
75
        old_format = BzrDirFormat.get_default_format()
76
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
77
        try:
78
            b_child = BzrDir.create_branch_convenience('child')
79
        finally:
80
            BzrDirFormat.set_default_format(old_format)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
81
        self.assertEqual(None, b_child.get_bound_location())
82
        self.assertEqual(None, b_child.get_master_branch())
83
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
84
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
85
        b_child.bind(sftp_b_base)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
86
        self.assertEqual(sftp_b_base.base, b_child.get_bound_location())
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
87
        # the bind must not have given b_child history:
88
        self.assertEqual([], b_child.revision_history())
89
        # we should be able to update the branch at this point:
90
        self.assertEqual(None, b_child.update())
91
        # and now there must be history.
92
        self.assertEqual(['r@b-1'], b_child.revision_history())
93
        # this line is more of a working tree test line, but - what the hey,
94
        # it has work to do.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
95
        b_child.bzrdir.open_workingtree().update()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
96
        self.failUnlessExists('child/a')
97
        self.failUnlessExists('child/b')
98
99
        b_child.unbind()
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
100
        self.assertEqual(None, b_child.get_bound_location())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
101
102
    def test_bound_commit(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
103
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
104
105
        open('child/a', 'wb').write('new contents\n')
106
        wt_child.commit('modified a', rev_id='r@c-2')
107
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
108
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
109
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
110
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
111
    def test_bound_commit_fails_when_out_of_date(self):
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
112
        # Make sure commit fails if out of date.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
113
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
114
115
        open('base/a', 'wb').write('new base contents\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
116
        b_base.bzrdir.open_workingtree().commit('base', rev_id='r@b-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
117
118
        open('child/b', 'wb').write('new b child contents\n')
119
        self.assertRaises(errors.BoundBranchOutOfDate,
120
                wt_child.commit, 'child', rev_id='r@c-2')
121
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
122
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
123
124
        # This is all that cmd_update does
125
        wt_child.pull(sftp_b_base, overwrite=False)
126
127
        wt_child.commit('child', rev_id='r@c-3')
128
129
        self.assertEqual(['r@b-1', 'r@b-2', 'r@c-3'],
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
130
                wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
131
        self.assertEqual(['r@b-1', 'r@b-2', 'r@c-3'],
132
                b_base.revision_history())
133
        self.assertEqual(['r@b-1', 'r@b-2', 'r@c-3'],
134
                sftp_b_base.revision_history())
135
136
    def test_double_binding(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
137
        b_base, wt_child = self.create_branches()
138
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
139
        wt_child2 = wt_child.branch.create_checkout('child2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
140
141
        open('child2/a', 'wb').write('new contents\n')
142
        self.assertRaises(errors.CommitToDoubleBoundBranch,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
143
                wt_child2.commit, 'child2', rev_id='r@d-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
144
145
    def test_unbinding(self):
146
        from bzrlib.transport import get_transport
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
147
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
148
149
        # TestCaseWithSFTPServer only allows you to connect one time
150
        # to the SFTP server. So we have to create a connection and
151
        # keep it around, so that it can be reused
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
152
        __unused_t = get_transport(self.get_url('.'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
153
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
154
        wt_base = b_base.bzrdir.open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
155
        open('base/a', 'wb').write('new base contents\n')
156
        wt_base.commit('base', rev_id='r@b-2')
157
158
        open('child/b', 'wb').write('new b child contents\n')
159
        self.assertRaises(errors.BoundBranchOutOfDate,
160
                wt_child.commit, 'child', rev_id='r@c-2')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
161
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
162
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
163
        wt_child.commit('child', rev_id='r@c-2')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
164
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
165
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
166
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
167
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
168
        self.assertRaises(errors.DivergedBranches,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
169
                wt_child.branch.bind, sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
170
171
    def test_commit_remote_bound(self):
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
172
        # Make sure it is detected if the current base is bound during the
173
        # objects lifetime, when the child goes to commit.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
174
        b_base, wt_child = self.create_branches()
175
176
        b_base.bzrdir.sprout('newbase')
177
178
        sftp_b_base = Branch.open(self.get_url('base'))
179
        sftp_b_newbase = Branch.open(self.get_url('newbase'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
180
181
        sftp_b_base.bind(sftp_b_newbase)
182
183
        open('child/a', 'wb').write('new contents\n')
184
        self.assertRaises(errors.CommitToDoubleBoundBranch,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
185
                wt_child.commit, 'failure', rev_id='r@c-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
186
187
        self.assertEqual(['r@b-1'], b_base.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
188
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
189
        self.assertEqual(['r@b-1'], sftp_b_newbase.revision_history())
190
191
    def test_pull_updates_both(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
192
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
193
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
194
        wt_newchild = b_base.bzrdir.sprout('newchild').open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
195
        open('newchild/b', 'wb').write('newchild b contents\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
196
        wt_newchild.commit('newchild', rev_id='r@d-2')
197
        self.assertEqual(['r@b-1', 'r@d-2'], wt_newchild.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
198
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
199
        wt_child.pull(wt_newchild.branch)
200
        self.assertEqual(['r@b-1', 'r@d-2'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
201
        self.assertEqual(['r@b-1', 'r@d-2'], b_base.revision_history())
202
203
    def test_bind_diverged(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
204
        from bzrlib.builtins import merge
205
206
        b_base, wt_child = self.create_branches()
207
208
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
209
        open('child/a', 'ab').write('child contents\n')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
210
        wt_child_rev = wt_child.commit('child', rev_id='r@c-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
211
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
212
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
213
        self.assertEqual(['r@b-1'], b_base.revision_history())
214
215
        open('base/b', 'ab').write('base contents\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
216
        b_base.bzrdir.open_workingtree().commit('base', rev_id='r@b-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
217
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
218
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
219
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
220
221
        self.assertRaises(errors.DivergedBranches,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
222
                wt_child.branch.bind, sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
223
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
224
        wt_child.merge_from_branch(sftp_b_base)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
225
        self.assertEqual([wt_child_rev, 'r@b-2'], wt_child.get_parent_ids())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
226
        wt_child.commit('merged', rev_id='r@c-3')
227
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
228
        # After a merge, trying to bind again should succeed but not push the
229
        # new change.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
230
        wt_child.branch.bind(sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
231
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
232
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
233
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3'],
234
            wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
235
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
236
    def test_bind_parent_ahead_preserves_parent(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
237
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
238
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
239
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
240
241
        open('a', 'ab').write('base changes\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
242
        wt_base = b_base.bzrdir.open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
243
        wt_base.commit('base', rev_id='r@b-2')
244
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
245
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
246
247
        sftp_b_base = Branch.open(self.get_url('base'))
248
        wt_child.branch.bind(sftp_b_base)
249
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
250
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
251
252
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
253
254
        # Check and make sure it also works if parent is ahead multiple
255
        wt_base.commit('base 3', rev_id='r@b-3', allow_pointless=True)
256
        wt_base.commit('base 4', rev_id='r@b-4', allow_pointless=True)
257
        wt_base.commit('base 5', rev_id='r@b-5', allow_pointless=True)
258
259
        self.assertEqual(['r@b-1', 'r@b-2', 'r@b-3', 'r@b-4', 'r@b-5'],
260
                b_base.revision_history())
261
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
262
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
263
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
264
        wt_child.branch.bind(sftp_b_base)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
265
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
266
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
267
    def test_bind_child_ahead_preserves_child(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
268
        b_base, wt_child = self.create_branches()
269
270
        wt_child.branch.unbind()
271
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
272
        wt_child.commit('child', rev_id='r@c-2', allow_pointless=True)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
273
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
274
        self.assertEqual(['r@b-1'], b_base.revision_history())
275
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
276
        sftp_b_base = Branch.open(self.get_url('base'))
277
        wt_child.branch.bind(sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
278
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
279
        self.assertEqual(['r@b-1'], b_base.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
280
281
        # Check and make sure it also works if child is ahead multiple
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
282
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
283
        wt_child.commit('child 3', rev_id='r@c-3', allow_pointless=True)
284
        wt_child.commit('child 4', rev_id='r@c-4', allow_pointless=True)
285
        wt_child.commit('child 5', rev_id='r@c-5', allow_pointless=True)
286
287
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3', 'r@c-4', 'r@c-5'],
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
288
                wt_child.branch.revision_history())
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
289
        self.assertEqual(['r@b-1'], b_base.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
290
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
291
        wt_child.branch.bind(sftp_b_base)
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
292
        self.assertEqual(['r@b-1'], b_base.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
293
294
    def test_commit_after_merge(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
295
        from bzrlib.builtins import merge
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
296
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
297
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
298
299
        # We want merge to be able to be a local only
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
300
        # operation, because it does not alter the branch data.
301
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
302
        # But we can't fail afterwards
303
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
304
        wt_other = wt_child.bzrdir.sprout('other').open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
305
306
        open('other/c', 'wb').write('file c\n')
307
        wt_other.add('c')
308
        wt_other.commit('adding c', rev_id='r@d-2')
309
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
310
        self.failIf(wt_child.branch.repository.has_revision('r@d-2'))
311
        self.failIf(b_base.repository.has_revision('r@d-2'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
312
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
313
        wt_child.merge_from_branch(wt_other.branch)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
314
315
        self.failUnlessExists('child/c')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
316
        self.assertEqual(['r@d-2'], wt_child.get_parent_ids()[1:])
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
317
        self.failUnless(wt_child.branch.repository.has_revision('r@d-2'))
318
        self.failIf(b_base.repository.has_revision('r@d-2'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
319
320
        # Commit should succeed, and cause merged revisions to
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
321
        # be pushed into base
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
322
        wt_child.commit('merge other', rev_id='r@c-2')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
323
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
324
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
325
        self.failUnless(b_base.repository.has_revision('r@d-2'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
326
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
327
    def test_commit_fails(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
328
        b_base, wt_child = self.create_branches()
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
329
330
        open('a', 'ab').write('child adds some text\n')
331
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
332
        # this deletes the branch from memory
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
333
        del b_base
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
334
        # and this moves it out of the way on disk
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
335
        os.rename('base', 'hidden_base')
336
337
        self.assertRaises(errors.BoundBranchConnectionFailure,
338
                wt_child.commit, 'added text', rev_id='r@c-2')
339
340
    def test_pull_fails(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
341
        b_base, wt_child = self.create_branches()
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
342
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
343
        wt_other = wt_child.bzrdir.sprout('other').open_workingtree()
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
344
        open('other/a', 'wb').write('new contents\n')
345
        wt_other.commit('changed a', rev_id='r@d-2')
346
347
        self.assertEqual(['r@b-1'], b_base.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
348
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
349
        self.assertEqual(['r@b-1', 'r@d-2'], wt_other.branch.revision_history())
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
350
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
351
        # this deletes the branch from memory
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
352
        del b_base
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
353
        # and this moves it out of the way on disk
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
354
        os.rename('base', 'hidden_base')
355
356
        self.assertRaises(errors.BoundBranchConnectionFailure,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
357
                wt_child.pull, wt_other.branch)
1505.1.29 by John Arbash Meinel
Added special exceptions when unable to contact parent branch. Added tests for failure. bind() no longer updates the remote working tree
358
359
    # TODO: jam 20051231 We need invasive failure tests, so that we can show
360
    #       performance even when something fails.
1505.1.28 by John Arbash Meinel
todo
361
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
362
363
if not paramiko_loaded:
364
    del BoundSFTPBranch
365