667
673
target = dir.sprout(self.get_url('target'), revision_id='1')
668
674
self.assertEqual('1', target.open_branch().last_revision())
676
def test_sprout_bzrdir_branch_with_tags(self):
677
# when sprouting a branch all revisions named in the tags are copied
679
builder = self.make_branch_builder('source')
680
source = fixtures.build_branch_with_non_ancestral_rev(builder)
682
source.tags.set_tag('tag-a', 'rev-2')
683
except errors.TagsNotSupported:
684
raise TestNotApplicable('Branch format does not support tags.')
685
# Now source has a tag not in its ancestry. Sprout its controldir.
687
target = dir.sprout(self.get_url('target'))
688
# The tag is present, and so is its revision.
689
new_branch = target.open_branch()
690
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
691
new_branch.repository.get_revision('rev-2')
693
def test_sprout_bzrdir_branch_with_absent_tag(self):
694
# tags referencing absent revisions are copied (and those absent
695
# revisions do not prevent the sprout.)
696
builder = self.make_branch_builder('source')
697
builder.build_commit(message="Rev 1", rev_id='rev-1')
698
source = builder.get_branch()
700
source.tags.set_tag('tag-a', 'missing-rev')
701
except errors.TagsNotSupported:
702
raise TestNotApplicable('Branch format does not support tags.')
703
# Now source has a tag pointing to an absent revision. Sprout its
706
target = dir.sprout(self.get_url('target'))
707
# The tag is present in the target
708
new_branch = target.open_branch()
709
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
711
def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
712
# tags referencing absent revisions are copied (and those absent
713
# revisions do not prevent the sprout.)
714
builder = self.make_branch_builder('source')
715
builder.build_commit(message="Rev 1", rev_id='rev-1')
716
source = builder.get_branch()
718
source.tags.set_tag('tag-a', 'missing-rev')
719
except errors.TagsNotSupported:
720
raise TestNotApplicable('Branch format does not support tags.')
721
# Now source has a tag pointing to an absent revision. Sprout its
724
target = dir.sprout(self.get_url('target'), source_branch=source)
725
# The tag is present in the target
726
new_branch = target.open_branch()
727
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
729
def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
730
# dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
731
# the branch at that bzrdir, the ancestry of all of those, but no other
732
# revs (not even the tip of the source branch).
733
builder = self.make_branch_builder('source')
734
builder.build_commit(message="Base", rev_id='base-rev')
735
# Make three parallel lines of ancestry off this base.
736
source = builder.get_branch()
737
builder.build_commit(message="Rev A1", rev_id='rev-a1')
738
builder.build_commit(message="Rev A2", rev_id='rev-a2')
739
builder.build_commit(message="Rev A3", rev_id='rev-a3')
740
source.set_last_revision_info(1, 'base-rev')
741
builder.build_commit(message="Rev B1", rev_id='rev-b1')
742
builder.build_commit(message="Rev B2", rev_id='rev-b2')
743
builder.build_commit(message="Rev B3", rev_id='rev-b3')
744
source.set_last_revision_info(1, 'base-rev')
745
builder.build_commit(message="Rev C1", rev_id='rev-c1')
746
builder.build_commit(message="Rev C2", rev_id='rev-c2')
747
builder.build_commit(message="Rev C3", rev_id='rev-c3')
748
# Set the branch tip to A2
749
source.set_last_revision_info(3, 'rev-a2')
751
# Create a tag for B2, and for an absent rev
752
source.tags.set_tag('tag-non-ancestry', 'rev-b2')
753
source.tags.set_tag('tag-absent', 'absent-rev')
754
except errors.TagsNotSupported:
755
raise TestNotApplicable('Branch format does not support tags.')
756
# And ask sprout for C2
758
target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
759
# The tags are present
760
new_branch = target.open_branch()
762
{'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
763
new_branch.tags.get_tag_dict())
764
# And the revs for A2, B2 and C2's ancestries are present, but no
767
['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
768
sorted(new_branch.repository.all_revision_ids()))
670
770
def test_sprout_bzrdir_tree_branch_reference(self):
671
771
# sprouting should create a repository if needed and a sprouted branch.
672
772
# the tree state should not be copied.
755
855
tree.commit('revision 1', rev_id='1')
756
856
tree.commit('revision 2', rev_id='2', allow_pointless=True)
757
857
dir = tree.bzrdir
758
if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
759
self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
760
self.get_url('target'),
761
create_tree_if_local=False)
763
target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
859
target = dir.sprout(self.get_url('target'),
860
create_tree_if_local=False)
861
except errors.MustHaveWorkingTree:
862
raise TestNotApplicable("control dir format requires working tree")
764
863
self.failIfExists('target/foo')
765
864
self.assertEqual(tree.branch.last_revision(),
766
865
target.open_branch().last_revision())
968
1067
# Repositories are open write-locked
969
1068
self.assertTrue(repo.is_write_locked())
970
1069
self.addCleanup(repo.unlock)
971
self.assertIsInstance(control, bzrdir.BzrDir)
1070
self.assertIsInstance(control, controldir.ControlDir)
972
1071
opened = bzrdir.BzrDir.open(t.base)
973
1072
expected_format = self.bzrdir_format
974
if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
975
# Current RemoteBzrDirFormat's do not reliably get network_name
976
# set, so we skip a number of tests for RemoteBzrDirFormat's.
977
self.assertIsInstance(control, RemoteBzrDir)
979
if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
980
bzrdir.BzrDirFormat6)):
981
# Pre-metadir formats change when we are making something that
982
# needs a metaformat, because clone is used for push.
983
expected_format = bzrdir.BzrDirMetaFormat1()
1073
if need_meta and expected_format.fixed_components:
1074
# Pre-metadir formats change when we are making something that
1075
# needs a metaformat, because clone is used for push.
1076
expected_format = bzrdir.BzrDirMetaFormat1()
1077
if not isinstance(expected_format, RemoteBzrDirFormat):
984
1078
self.assertEqual(control._format.network_name(),
985
1079
expected_format.network_name())
986
1080
self.assertEqual(control._format.network_name(),
1178
1272
self.failUnless(isinstance(opened_tree, made_tree.__class__))
1179
1273
self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1181
def test_get_branch_transport(self):
1182
dir = self.make_bzrdir('.')
1183
# without a format, get_branch_transport gives use a transport
1184
# which -may- point to an existing dir.
1185
self.assertTrue(isinstance(dir.get_branch_transport(None),
1186
transport.Transport))
1187
# with a given format, either the bzr dir supports identifiable
1188
# branches, or it supports anonymous branch formats, but not both.
1189
anonymous_format = bzrlib.branch.BzrBranchFormat4()
1190
identifiable_format = bzrlib.branch.BzrBranchFormat5()
1192
found_transport = dir.get_branch_transport(anonymous_format)
1193
self.assertRaises(errors.IncompatibleFormat,
1194
dir.get_branch_transport,
1195
identifiable_format)
1196
except errors.IncompatibleFormat:
1197
found_transport = dir.get_branch_transport(identifiable_format)
1198
self.assertTrue(isinstance(found_transport, transport.Transport))
1199
# and the dir which has been initialized for us must exist.
1200
found_transport.list_dir('.')
1202
def test_get_repository_transport(self):
1203
dir = self.make_bzrdir('.')
1204
# without a format, get_repository_transport gives use a transport
1205
# which -may- point to an existing dir.
1206
self.assertTrue(isinstance(dir.get_repository_transport(None),
1207
transport.Transport))
1208
# with a given format, either the bzr dir supports identifiable
1209
# repositories, or it supports anonymous repository formats, but not both.
1210
anonymous_format = weaverepo.RepositoryFormat6()
1211
identifiable_format = weaverepo.RepositoryFormat7()
1213
found_transport = dir.get_repository_transport(anonymous_format)
1214
self.assertRaises(errors.IncompatibleFormat,
1215
dir.get_repository_transport,
1216
identifiable_format)
1217
except errors.IncompatibleFormat:
1218
found_transport = dir.get_repository_transport(identifiable_format)
1219
self.assertTrue(isinstance(found_transport, transport.Transport))
1220
# and the dir which has been initialized for us must exist.
1221
found_transport.list_dir('.')
1223
def test_get_workingtree_transport(self):
1224
dir = self.make_bzrdir('.')
1225
# without a format, get_workingtree_transport gives use a transport
1226
# which -may- point to an existing dir.
1227
self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1228
transport.Transport))
1229
# with a given format, either the bzr dir supports identifiable
1230
# trees, or it supports anonymous tree formats, but not both.
1231
anonymous_format = workingtree.WorkingTreeFormat2()
1232
identifiable_format = workingtree.WorkingTreeFormat3()
1234
found_transport = dir.get_workingtree_transport(anonymous_format)
1235
self.assertRaises(errors.IncompatibleFormat,
1236
dir.get_workingtree_transport,
1237
identifiable_format)
1238
except errors.IncompatibleFormat:
1239
found_transport = dir.get_workingtree_transport(identifiable_format)
1240
self.assertTrue(isinstance(found_transport, transport.Transport))
1241
# and the dir which has been initialized for us must exist.
1242
found_transport.list_dir('.')
1244
1275
def test_root_transport(self):
1245
1276
dir = self.make_bzrdir('.')
1246
1277
self.assertEqual(dir.root_transport.base,
1247
transport.get_transport(self.get_url('.')).base)
1278
self.get_transport().base)
1249
1280
def test_find_repository_no_repo_under_standalone_branch(self):
1250
1281
# finding a repo stops at standalone branches even if there is a