~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
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
23
from bzrlib import (
24
    bzrdir,
25
    )
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
26
from bzrlib.branch import Branch
27
from bzrlib.bzrdir import (BzrDir,
28
                           BzrDirFormat,
29
                           BzrDirFormat6,
30
                           BzrDirMetaFormat1,
31
                           )
32
import bzrlib.errors as errors
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
33
from bzrlib.tests import TestSkipped
1505.1.30 by John Arbash Meinel
[merge] jam-integration 1495
34
from bzrlib.tests.test_sftp_transport import TestCaseWithSFTPServer, paramiko_loaded
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
35
36
37
class BoundSFTPBranch(TestCaseWithSFTPServer):
38
39
    def create_branches(self):
40
        self.build_tree(['base/', 'base/a', 'base/b'])
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
41
        format = bzrdir.format_registry.make_bzrdir('knit')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
42
        try:
43
            wt_base = BzrDir.create_standalone_workingtree(
44
                self.get_url('base'), format=format)
45
        except errors.NotLocalUrl:
46
            raise TestSkipped('Not a local URL')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
47
    
48
        b_base = wt_base.branch
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
49
50
        wt_base.add('a')
51
        wt_base.add('b')
52
        wt_base.commit('first', rev_id='r@b-1')
53
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
54
        wt_child = b_base.bzrdir.sprout('child').open_workingtree()
55
        self.sftp_base = Branch.open(self.get_url('base'))
56
        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
57
        # check the branch histories are ready for using in tests.
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
58
        self.assertEqual(['r@b-1'], b_base.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
59
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
60
        return b_base, wt_child
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
61
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.
62
    def tearDown(self):
63
        self.sftp_base = None
64
        bzrlib.transport.sftp.clear_connection_cache()
65
        super(BoundSFTPBranch, self).tearDown()
66
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
67
    def test_simple_binding(self):
68
        self.build_tree(['base/', 'base/a', 'base/b', 'child/'])
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
69
        try:
70
            wt_base = BzrDir.create_standalone_workingtree(self.get_url('base'))
71
        except errors.NotLocalUrl:
72
            raise TestSkipped('Not a local URL')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
73
74
        wt_base.add('a')
75
        wt_base.add('b')
76
        wt_base.commit('first', rev_id='r@b-1')
77
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
78
        b_base = wt_base.branch
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
79
        # manually make a branch we can bind, because the default format
80
        # may not be bindable-from, and we want to test the side effects etc
81
        # of bondage.
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
82
        format = bzrdir.format_registry.make_bzrdir('knit')
83
        b_child = BzrDir.create_branch_convenience('child', format=format)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
84
        self.assertEqual(None, b_child.get_bound_location())
85
        self.assertEqual(None, b_child.get_master_branch())
86
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
87
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
88
        b_child.bind(sftp_b_base)
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
89
        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
90
        # the bind must not have given b_child history:
91
        self.assertEqual([], b_child.revision_history())
92
        # we should be able to update the branch at this point:
93
        self.assertEqual(None, b_child.update())
94
        # and now there must be history.
95
        self.assertEqual(['r@b-1'], b_child.revision_history())
96
        # this line is more of a working tree test line, but - what the hey,
97
        # it has work to do.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
98
        b_child.bzrdir.open_workingtree().update()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
99
        self.failUnlessExists('child/a')
100
        self.failUnlessExists('child/b')
101
102
        b_child.unbind()
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
103
        self.assertEqual(None, b_child.get_bound_location())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
104
105
    def test_bound_commit(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
106
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
107
108
        open('child/a', 'wb').write('new contents\n')
109
        wt_child.commit('modified a', rev_id='r@c-2')
110
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
111
        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.
112
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
113
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
114
    def test_bound_commit_fails_when_out_of_date(self):
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
115
        # Make sure commit fails if out of date.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
116
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
117
118
        open('base/a', 'wb').write('new base contents\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
119
        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.
120
121
        open('child/b', 'wb').write('new b child contents\n')
122
        self.assertRaises(errors.BoundBranchOutOfDate,
123
                wt_child.commit, 'child', rev_id='r@c-2')
124
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
125
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
126
127
        # This is all that cmd_update does
128
        wt_child.pull(sftp_b_base, overwrite=False)
129
130
        wt_child.commit('child', rev_id='r@c-3')
131
132
        self.assertEqual(['r@b-1', 'r@b-2', 'r@c-3'],
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
133
                wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
134
        self.assertEqual(['r@b-1', 'r@b-2', 'r@c-3'],
135
                b_base.revision_history())
136
        self.assertEqual(['r@b-1', 'r@b-2', 'r@c-3'],
137
                sftp_b_base.revision_history())
138
139
    def test_double_binding(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
140
        b_base, wt_child = self.create_branches()
141
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
142
        wt_child2 = wt_child.branch.create_checkout('child2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
143
144
        open('child2/a', 'wb').write('new contents\n')
145
        self.assertRaises(errors.CommitToDoubleBoundBranch,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
146
                wt_child2.commit, 'child2', rev_id='r@d-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
147
148
    def test_unbinding(self):
149
        from bzrlib.transport import get_transport
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
150
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
151
152
        # TestCaseWithSFTPServer only allows you to connect one time
153
        # to the SFTP server. So we have to create a connection and
154
        # keep it around, so that it can be reused
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
155
        __unused_t = get_transport(self.get_url('.'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
156
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
157
        wt_base = b_base.bzrdir.open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
158
        open('base/a', 'wb').write('new base contents\n')
159
        wt_base.commit('base', rev_id='r@b-2')
160
161
        open('child/b', 'wb').write('new b child contents\n')
162
        self.assertRaises(errors.BoundBranchOutOfDate,
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'], wt_child.branch.revision_history())
165
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
166
        wt_child.commit('child', rev_id='r@c-2')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
167
        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.
168
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
169
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
170
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
171
        self.assertRaises(errors.DivergedBranches,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
172
                wt_child.branch.bind, sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
173
174
    def test_commit_remote_bound(self):
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
175
        # Make sure it is detected if the current base is bound during the
176
        # objects lifetime, when the child goes to commit.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
177
        b_base, wt_child = self.create_branches()
178
179
        b_base.bzrdir.sprout('newbase')
180
181
        sftp_b_base = Branch.open(self.get_url('base'))
182
        sftp_b_newbase = Branch.open(self.get_url('newbase'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
183
184
        sftp_b_base.bind(sftp_b_newbase)
185
186
        open('child/a', 'wb').write('new contents\n')
187
        self.assertRaises(errors.CommitToDoubleBoundBranch,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
188
                wt_child.commit, 'failure', rev_id='r@c-2')
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
189
190
        self.assertEqual(['r@b-1'], b_base.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
191
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
192
        self.assertEqual(['r@b-1'], sftp_b_newbase.revision_history())
193
194
    def test_bind_diverged(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
195
        from bzrlib.builtins import merge
196
197
        b_base, wt_child = self.create_branches()
198
199
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
200
        open('child/a', 'ab').write('child contents\n')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
201
        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.
202
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
203
        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.
204
        self.assertEqual(['r@b-1'], b_base.revision_history())
205
206
        open('base/b', 'ab').write('base contents\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
207
        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.
208
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
209
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
210
        sftp_b_base = Branch.open(self.get_url('base'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
211
212
        self.assertRaises(errors.DivergedBranches,
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
213
                wt_child.branch.bind, sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
214
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
215
        wt_child.merge_from_branch(sftp_b_base)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
216
        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.
217
        wt_child.commit('merged', rev_id='r@c-3')
218
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
219
        # After a merge, trying to bind again should succeed but not push the
220
        # new change.
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
221
        wt_child.branch.bind(sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
222
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
223
        self.assertEqual(['r@b-1', 'r@b-2'], b_base.revision_history())
224
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3'],
225
            wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
226
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
227
    def test_bind_parent_ahead_preserves_parent(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
228
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
229
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
230
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
231
232
        open('a', 'ab').write('base changes\n')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
233
        wt_base = b_base.bzrdir.open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
234
        wt_base.commit('base', rev_id='r@b-2')
235
        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.
236
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
237
238
        sftp_b_base = Branch.open(self.get_url('base'))
239
        wt_child.branch.bind(sftp_b_base)
240
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
241
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
242
243
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
244
245
        # Check and make sure it also works if parent is ahead multiple
246
        wt_base.commit('base 3', rev_id='r@b-3', allow_pointless=True)
247
        wt_base.commit('base 4', rev_id='r@b-4', allow_pointless=True)
248
        wt_base.commit('base 5', rev_id='r@b-5', allow_pointless=True)
249
250
        self.assertEqual(['r@b-1', 'r@b-2', 'r@b-3', 'r@b-4', 'r@b-5'],
251
                b_base.revision_history())
252
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
253
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
254
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
255
        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
256
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
257
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
258
    def test_bind_child_ahead_preserves_child(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
259
        b_base, wt_child = self.create_branches()
260
261
        wt_child.branch.unbind()
262
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
263
        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.
264
        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.
265
        self.assertEqual(['r@b-1'], b_base.revision_history())
266
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
267
        sftp_b_base = Branch.open(self.get_url('base'))
268
        wt_child.branch.bind(sftp_b_base)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
269
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
270
        self.assertEqual(['r@b-1'], b_base.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
271
272
        # 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.
273
        wt_child.branch.unbind()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
274
        wt_child.commit('child 3', rev_id='r@c-3', allow_pointless=True)
275
        wt_child.commit('child 4', rev_id='r@c-4', allow_pointless=True)
276
        wt_child.commit('child 5', rev_id='r@c-5', allow_pointless=True)
277
278
        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.
279
                wt_child.branch.revision_history())
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
280
        self.assertEqual(['r@b-1'], b_base.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
281
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
282
        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
283
        self.assertEqual(['r@b-1'], b_base.revision_history())
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
284
285
    def test_commit_after_merge(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
286
        from bzrlib.builtins import merge
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
287
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
288
        b_base, wt_child = self.create_branches()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
289
290
        # We want merge to be able to be a local only
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
291
        # operation, because it does not alter the branch data.
292
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
293
        # But we can't fail afterwards
294
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
295
        wt_other = wt_child.bzrdir.sprout('other').open_workingtree()
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
296
297
        open('other/c', 'wb').write('file c\n')
298
        wt_other.add('c')
299
        wt_other.commit('adding c', rev_id='r@d-2')
300
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
301
        self.failIf(wt_child.branch.repository.has_revision('r@d-2'))
302
        self.failIf(b_base.repository.has_revision('r@d-2'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
303
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
304
        wt_child.merge_from_branch(wt_other.branch)
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
305
306
        self.failUnlessExists('child/c')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
307
        self.assertEqual(['r@d-2'], wt_child.get_parent_ids()[1:])
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
308
        self.failUnless(wt_child.branch.repository.has_revision('r@d-2'))
309
        self.failIf(b_base.repository.has_revision('r@d-2'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
310
311
        # 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
312
        # be pushed into base
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
313
        wt_child.commit('merge other', rev_id='r@c-2')
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
314
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
315
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
316
        self.failUnless(b_base.repository.has_revision('r@d-2'))
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
317
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
318
    def test_commit_fails(self):
1587.1.6 by Robert Collins
Update bound branch implementation to 0.8.
319
        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
320
321
        open('a', 'ab').write('child adds some text\n')
322
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
323
        # 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
324
        del b_base
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
325
        # 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
326
        os.rename('base', 'hidden_base')
327
328
        self.assertRaises(errors.BoundBranchConnectionFailure,
329
                wt_child.commit, 'added text', rev_id='r@c-2')
330
331
    # TODO: jam 20051231 We need invasive failure tests, so that we can show
332
    #       performance even when something fails.
1505.1.28 by John Arbash Meinel
todo
333
1505.1.27 by John Arbash Meinel
Adding tests against an sftp branch.
334
335
if not paramiko_loaded:
336
    del BoundSFTPBranch
337