~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/branch_implementations/test_bound_sftp.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
50
50
        wt_child = b_base.bzrdir.sprout('child').open_workingtree()
51
51
        self.sftp_base = Branch.open(self.get_url('base'))
52
52
        wt_child.branch.bind(self.sftp_base)
53
 
 
 
53
        # check the branch histories are ready for using in tests.
54
54
        self.assertEqual(['r@b-1'], b_base.revision_history())
55
55
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
56
 
 
57
56
        return b_base, wt_child
58
57
 
59
58
    def tearDown(self):
70
69
        wt_base.commit('first', rev_id='r@b-1')
71
70
 
72
71
        b_base = wt_base.branch
 
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.
73
75
        old_format = BzrDirFormat.get_default_format()
74
76
        BzrDirFormat.set_default_format(BzrDirMetaFormat1())
75
77
        try:
82
84
        sftp_b_base = Branch.open(self.get_url('base'))
83
85
        b_child.bind(sftp_b_base)
84
86
        self.assertEqual(sftp_b_base.base, b_child.get_bound_location())
85
 
        # this line is more of a working tree test line, but - what the hey.
 
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.
86
95
        b_child.bzrdir.open_workingtree().update()
87
96
        self.failUnlessExists('child/a')
88
97
        self.failUnlessExists('child/b')
99
108
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
100
109
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
101
110
 
102
 
    def test_bound_fail(self):
 
111
    def test_bound_commit_fails_when_out_of_date(self):
103
112
        # Make sure commit fails if out of date.
104
113
        b_base, wt_child = self.create_branches()
105
114
 
127
136
    def test_double_binding(self):
128
137
        b_base, wt_child = self.create_branches()
129
138
 
130
 
        wt_child2 = wt_child.bzrdir.sprout('child2').open_workingtree()
131
 
 
132
 
        wt_child2.branch.bind(wt_child.branch)
 
139
        wt_child2 = wt_child.branch.create_checkout('child2')
133
140
 
134
141
        open('child2/a', 'wb').write('new contents\n')
135
142
        self.assertRaises(errors.CommitToDoubleBoundBranch,
162
169
                wt_child.branch.bind, sftp_b_base)
163
170
 
164
171
    def test_commit_remote_bound(self):
165
 
        # Make sure it is detected if the current base
166
 
        # suddenly is bound when child goes to commit
 
172
        # Make sure it is detected if the current base is bound during the
 
173
        # objects lifetime, when the child goes to commit.
167
174
        b_base, wt_child = self.create_branches()
168
175
 
169
176
        b_base.bzrdir.sprout('newbase')
214
221
        self.assertRaises(errors.DivergedBranches,
215
222
                wt_child.branch.bind, sftp_b_base)
216
223
 
217
 
        # TODO: jam 20051230 merge_inner doesn't set pending merges
218
 
        #       Is this on purpose?
219
 
        #       merge_inner also doesn't fetch any missing revisions
220
 
        #merge_inner(wt_child.branch, sftp_b_base.revision_tree('r@b-2'), 
221
 
        #        wt_child.branch.revision_tree('r@b-1'))
222
 
        # TODO: jam 20051230 merge(..., (None, None), ...) seems to
223
 
        #       cause an infinite loop of some sort. It definitely doesn't
224
 
        #       work, you have to use list notation
225
 
        merge((sftp_b_base.base, 2), [None, None], this_dir=wt_child.branch.base)
226
 
 
 
224
        wt_child.merge_from_branch(sftp_b_base)
227
225
        self.assertEqual([wt_child_rev, 'r@b-2'], wt_child.get_parent_ids())
228
226
        wt_child.commit('merged', rev_id='r@c-3')
229
227
 
230
 
        # After a merge, trying to bind again should succeed
231
 
        # by pushing the new change to base
 
228
        # After a merge, trying to bind again should succeed but not push the
 
229
        # new change.
232
230
        wt_child.branch.bind(sftp_b_base)
233
231
 
234
 
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3'],
235
 
                b_base.revision_history())
236
 
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3'],
237
 
                wt_child.branch.revision_history())
 
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())
238
235
 
239
 
    def test_bind_parent_ahead(self):
 
236
    def test_bind_parent_ahead_preserves_parent(self):
240
237
        b_base, wt_child = self.create_branches()
241
238
 
242
239
        wt_child.branch.unbind()
250
247
        sftp_b_base = Branch.open(self.get_url('base'))
251
248
        wt_child.branch.bind(sftp_b_base)
252
249
 
253
 
        self.assertEqual(['r@b-1', 'r@b-2'], wt_child.branch.revision_history())
 
250
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
254
251
 
255
252
        wt_child.branch.unbind()
256
253
 
262
259
        self.assertEqual(['r@b-1', 'r@b-2', 'r@b-3', 'r@b-4', 'r@b-5'],
263
260
                b_base.revision_history())
264
261
 
265
 
        self.assertEqual(['r@b-1', 'r@b-2'], wt_child.branch.revision_history())
 
262
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
266
263
 
267
264
        wt_child.branch.bind(sftp_b_base)
268
 
        self.assertEqual(['r@b-1', 'r@b-2', 'r@b-3', 'r@b-4', 'r@b-5'],
269
 
                wt_child.branch.revision_history())
 
265
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
270
266
 
271
 
    def test_bind_child_ahead(self):
 
267
    def test_bind_child_ahead_preserves_child(self):
272
268
        b_base, wt_child = self.create_branches()
273
269
 
274
270
        wt_child.branch.unbind()
280
276
        sftp_b_base = Branch.open(self.get_url('base'))
281
277
        wt_child.branch.bind(sftp_b_base)
282
278
 
283
 
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
 
279
        self.assertEqual(['r@b-1'], b_base.revision_history())
284
280
 
285
281
        # Check and make sure it also works if child is ahead multiple
286
282
        wt_child.branch.unbind()
290
286
 
291
287
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3', 'r@c-4', 'r@c-5'],
292
288
                wt_child.branch.revision_history())
293
 
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
 
289
        self.assertEqual(['r@b-1'], b_base.revision_history())
294
290
 
295
291
        wt_child.branch.bind(sftp_b_base)
296
 
        self.assertEqual(['r@b-1', 'r@c-2', 'r@c-3', 'r@c-4', 'r@c-5'],
297
 
                b_base.revision_history())
 
292
        self.assertEqual(['r@b-1'], b_base.revision_history())
298
293
 
299
294
    def test_commit_after_merge(self):
300
295
        from bzrlib.builtins import merge
315
310
        self.failIf(wt_child.branch.repository.has_revision('r@d-2'))
316
311
        self.failIf(b_base.repository.has_revision('r@d-2'))
317
312
 
318
 
        # TODO: jam 20051230 merge_inner doesn't set pending merges
319
 
        #       Is this on purpose?
320
 
        #       merge_inner also doesn't fetch any missing revisions
321
 
        #merge_inner(wt_child.branch, b_other.revision_tree('r@d-2'),
322
 
        #        wt_child.branch.revision_tree('r@b-1'))
323
 
        merge((wt_other.branch.base, 2), [None, None], this_dir=wt_child.branch.base)
 
313
        wt_child.merge_from_branch(wt_other.branch)
324
314
 
325
315
        self.failUnlessExists('child/c')
326
316
        self.assertEqual(['r@d-2'], wt_child.get_parent_ids()[1:])
328
318
        self.failIf(b_base.repository.has_revision('r@d-2'))
329
319
 
330
320
        # Commit should succeed, and cause merged revisions to
331
 
        # be pulled into base
 
321
        # be pushed into base
332
322
        wt_child.commit('merge other', rev_id='r@c-2')
333
323
        self.assertEqual(['r@b-1', 'r@c-2'], wt_child.branch.revision_history())
334
324
        self.assertEqual(['r@b-1', 'r@c-2'], b_base.revision_history())
339
329
 
340
330
        open('a', 'ab').write('child adds some text\n')
341
331
 
 
332
        # this deletes the branch from memory
342
333
        del b_base
 
334
        # and this moves it out of the way on disk
343
335
        os.rename('base', 'hidden_base')
344
336
 
345
337
        self.assertRaises(errors.BoundBranchConnectionFailure,
356
348
        self.assertEqual(['r@b-1'], wt_child.branch.revision_history())
357
349
        self.assertEqual(['r@b-1', 'r@d-2'], wt_other.branch.revision_history())
358
350
 
 
351
        # this deletes the branch from memory
359
352
        del b_base
 
353
        # and this moves it out of the way on disk
360
354
        os.rename('base', 'hidden_base')
361
355
 
362
356
        self.assertRaises(errors.BoundBranchConnectionFailure,