140
140
# wt_a might be a lightweight checkout, so get a hold of the actual
141
141
# branch (because you can't do a partial clone of a lightweight
143
branch = wt_a.branch.bzrdir.open_branch()
143
branch = wt_a.branch.controldir.open_branch()
144
144
# Then make a branch where the new repository is, but specify a revision
145
145
# ID. The new branch's history will stop at the specified revision.
146
br_b = branch.clone(repo_b.bzrdir, revision_id='1')
146
br_b = branch.clone(repo_b.controldir, revision_id='1')
147
147
self.assertEqual('1', br_b.last_revision())
149
149
def get_parented_branch(self):
152
152
wt_a.add(['one'])
153
153
wt_a.commit('commit one', rev_id='1')
155
branch_b = wt_a.branch.bzrdir.sprout('b', revision_id='1').open_branch()
155
branch_b = wt_a.branch.controldir.sprout('b', revision_id='1').open_branch()
156
156
self.assertEqual(wt_a.branch.base, branch_b.get_parent())
165
165
branch_b = self.get_parented_branch()
166
166
repo_c = self.make_repository('c')
167
167
branch_b.repository.copy_content_into(repo_c)
168
branch_c = branch_b.clone(repo_c.bzrdir)
168
branch_c = branch_b.clone(repo_c.controldir)
169
169
self.assertNotEqual(None, branch_c.get_parent())
170
170
self.assertEqual(branch_b.get_parent(), branch_c.get_parent())
174
174
branch_b.set_parent(random_parent)
175
175
repo_d = self.make_repository('d')
176
176
branch_b.repository.copy_content_into(repo_d)
177
branch_d = branch_b.clone(repo_d.bzrdir)
177
branch_d = branch_b.clone(repo_d.controldir)
178
178
self.assertEqual(random_parent, branch_d.get_parent())
180
180
def test_submit_branch(self):
302
302
repo = self.make_repository('.', shared=True)
303
303
except errors.IncompatibleFormat:
305
if repo.bzrdir._format.colocated_branches:
305
if repo.controldir._format.colocated_branches:
306
306
raise tests.TestNotApplicable(
307
307
"control dir does not support colocated branches")
308
self.assertEqual(0, len(repo.bzrdir.list_branches()))
308
self.assertEqual(0, len(repo.controldir.list_branches()))
309
309
if not self.bzrdir_format.colocated_branches:
310
310
raise tests.TestNotApplicable("control dir format does not support "
311
311
"colocated branches")
313
child_branch1 = self.branch_format.initialize(repo.bzrdir,
313
child_branch1 = self.branch_format.initialize(repo.controldir,
315
315
except errors.UninitializableFormat:
316
316
# branch references are not default init'able and
317
317
# not all bzrdirs support colocated branches.
319
self.assertEqual(1, len(repo.bzrdir.list_branches()))
320
self.branch_format.initialize(repo.bzrdir, name='branch2')
321
self.assertEqual(2, len(repo.bzrdir.list_branches()))
319
self.assertEqual(1, len(repo.controldir.list_branches()))
320
self.branch_format.initialize(repo.controldir, name='branch2')
321
self.assertEqual(2, len(repo.controldir.list_branches()))
323
323
def test_create_append_revisions_only(self):
328
328
for val in (True, False):
330
branch = self.branch_format.initialize(repo.bzrdir,
330
branch = self.branch_format.initialize(repo.controldir,
331
331
append_revisions_only=True)
332
332
except (errors.UninitializableFormat, errors.UpgradeRequired):
333
333
# branch references are not default init'able and
334
334
# not all branches support append_revisions_only
336
336
self.assertEqual(True, branch.get_append_revisions_only())
337
repo.bzrdir.destroy_branch()
337
repo.controldir.destroy_branch()
339
339
def test_get_set_append_revisions_only(self):
340
340
branch = self.make_branch('.')
353
353
repo = self.make_repository('.', shared=True)
354
354
except errors.IncompatibleFormat:
355
355
raise tests.TestNotApplicable("requires shared repository support")
356
child_transport = repo.bzrdir.root_transport.clone('child')
356
child_transport = repo.controldir.root_transport.clone('child')
357
357
child_transport.mkdir('.')
359
359
child_dir = self.bzrdir_format.initialize_on_transport(child_transport)
364
364
except errors.UninitializableFormat:
365
365
# branch references are not default init'able.
367
self.assertEqual(repo.bzrdir.root_transport.base,
368
child_branch.repository.bzrdir.root_transport.base)
367
self.assertEqual(repo.controldir.root_transport.base,
368
child_branch.repository.controldir.root_transport.base)
369
369
child_branch = _mod_branch.Branch.open(self.get_url('child'))
370
self.assertEqual(repo.bzrdir.root_transport.base,
371
child_branch.repository.bzrdir.root_transport.base)
370
self.assertEqual(repo.controldir.root_transport.base,
371
child_branch.repository.controldir.root_transport.base)
373
373
def test_format_description(self):
374
374
tree = self.make_branch_and_tree('tree')
434
434
# open the branch via a readonly transport
435
435
url = self.get_readonly_url(urlutils.basename(tree_a.branch.base))
436
436
t = transport.get_transport_from_url(url)
437
if not tree_a.branch.bzrdir._format.supports_transport(t):
437
if not tree_a.branch.controldir._format.supports_transport(t):
438
438
raise tests.TestNotApplicable("format does not support transport")
439
439
source_branch = _mod_branch.Branch.open(url)
440
440
# sanity check that the test will be valid
451
451
url = self.get_readonly_url(
452
452
osutils.basename(tree_a.branch.base.rstrip('/')))
453
453
t = transport.get_transport_from_url(url)
454
if not tree_a.branch.bzrdir._format.supports_transport(t):
454
if not tree_a.branch.controldir._format.supports_transport(t):
455
455
raise tests.TestNotApplicable("format does not support transport")
456
456
source_branch = _mod_branch.Branch.open(url)
457
457
# sanity check that the test will be valid
530
530
_mod_branch.Branch.open_containing,
531
531
self.get_readonly_url('g/p/q'))
532
532
branch = self.make_branch('.')
533
if not branch.bzrdir._format.supports_transport(
533
if not branch.controldir._format.supports_transport(
534
534
transport.get_transport_from_url(self.get_readonly_url('.'))):
535
535
raise tests.TestNotApplicable("format does not support transport")
536
536
branch, relpath = _mod_branch.Branch.open_containing(
648
648
made_branch = self.make_branch('.')
649
649
self.assertEqual(None,
650
made_branch._format.get_reference(made_branch.bzrdir))
650
made_branch._format.get_reference(made_branch.controldir))
652
652
def test_set_reference(self):
653
653
"""set_reference on all regular branches should be callable."""
659
659
this_branch = self.make_branch('this')
660
660
other_branch = self.make_branch('other')
662
this_branch._format.set_reference(this_branch.bzrdir, None,
662
this_branch._format.set_reference(this_branch.controldir, None,
664
664
except NotImplementedError:
668
ref = this_branch._format.get_reference(this_branch.bzrdir)
668
ref = this_branch._format.get_reference(this_branch.controldir)
669
669
self.assertEqual(ref, other_branch.base)
671
671
def test_format_initialize_find_open(self):
685
685
opened_control = controldir.ControlDir.open(readonly_t.base)
686
686
direct_opened_branch = opened_control.open_branch()
687
687
self.assertEqual(direct_opened_branch.__class__, made_branch.__class__)
688
self.assertEqual(opened_control, direct_opened_branch.bzrdir)
688
self.assertEqual(opened_control, direct_opened_branch.controldir)
689
689
self.assertIsInstance(direct_opened_branch._format,
690
690
self.branch_format.__class__)
794
794
except errors.UpgradeRequired:
795
795
raise tests.TestSkipped('Format does not support strict history')
796
796
tree1.commit('empty commit')
797
tree2 = tree1.bzrdir.sprout('tree2').open_workingtree()
797
tree2 = tree1.controldir.sprout('tree2').open_workingtree()
798
798
tree2.commit('empty commit 2')
799
799
tree1.pull(tree2.branch)
800
800
tree1.commit('empty commit 3')
804
804
tree2.commit('empty commit 5')
805
805
self.assertRaises(errors.AppendRevisionsOnlyViolation, tree1.pull,
807
tree3 = tree1.bzrdir.sprout('tree3').open_workingtree()
807
tree3 = tree1.controldir.sprout('tree3').open_workingtree()
808
808
tree3.merge_from_branch(tree2.branch)
809
809
tree3.commit('empty commit 6')
810
810
tree2.pull(tree3.branch)
860
860
reference_parent = tree.branch.reference_parent('subtree-id',
861
861
urlutils.relative_url(
862
862
tree.branch.user_url, subtree.branch.user_url),
863
possible_transports=[subtree.bzrdir.root_transport])
863
possible_transports=[subtree.controldir.root_transport])
865
865
def test_get_reference_info(self):
866
866
branch = self.make_branch('branch')
958
958
def test_sprout_copies_reference_location(self):
959
959
branch = self.make_branch_with_reference('branch', '../reference')
960
new_branch = branch.bzrdir.sprout('new-branch').open_branch()
960
new_branch = branch.controldir.sprout('new-branch').open_branch()
961
961
self.assertEqual('../reference',
962
962
new_branch.get_reference_info('file-id')[1])
964
964
def test_clone_copies_reference_location(self):
965
965
branch = self.make_branch_with_reference('branch', '../reference')
966
new_branch = branch.bzrdir.clone('new-branch').open_branch()
966
new_branch = branch.controldir.clone('new-branch').open_branch()
967
967
self.assertEqual('../reference',
968
968
new_branch.get_reference_info('file-id')[1])
970
970
def test_copied_locations_are_rebased(self):
971
971
branch = self.make_branch_with_reference('branch', 'reference')
972
new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
972
new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
973
973
self.assertEqual('../reference',
974
974
new_branch.get_reference_info('file-id')[1])
992
992
def test_update_references_skips_known_references(self):
993
993
branch = self.make_branch_with_reference('branch', 'reference')
994
new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
994
new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
995
995
new_branch.set_reference_info('file-id', '../foo', '../foo')
996
996
new_branch.update_references(branch)
997
997
self.assertEqual('reference',
1000
1000
def test_pull_updates_references(self):
1001
1001
branch = self.make_branch_with_reference('branch', 'reference')
1002
new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
1002
new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
1003
1003
new_branch.set_reference_info('file-id2', '../foo', '../foo')
1004
1004
branch.pull(new_branch)
1005
1005
self.assertEqual('foo',
1008
1008
def test_push_updates_references(self):
1009
1009
branch = self.make_branch_with_reference('branch', 'reference')
1010
new_branch = branch.bzrdir.sprout('branch/new-branch').open_branch()
1010
new_branch = branch.controldir.sprout('branch/new-branch').open_branch()
1011
1011
new_branch.set_reference_info('file-id2', '../foo', '../foo')
1012
1012
new_branch.push(branch)
1013
1013
self.assertEqual('foo',