32
33
revision as _mod_revision,
38
40
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
39
from bzrlib.check import check
41
from bzrlib.check import check_branch
40
42
from bzrlib.errors import (FileExists,
56
58
from bzrlib.transport import get_transport
57
59
from bzrlib.transport.local import LocalTransport
58
60
from bzrlib.upgrade import upgrade
59
from bzrlib.remote import RemoteBzrDir
61
from bzrlib.remote import RemoteBzrDir, RemoteRepository
60
62
from bzrlib.repofmt import weaverepo
73
75
"""Assert that the content of source and target are identical.
75
77
paths in ignore list will be completely ignored.
77
79
We ignore paths that represent data which is allowed to change during
78
80
a clone or sprout: for instance, inventory.knit contains gzip fragements
79
which have timestamps in them, and as we have read the inventory from
81
which have timestamps in them, and as we have read the inventory from
80
82
the source knit, the already-read data is recompressed rather than
81
83
reading it again, which leads to changed timestamps. This is ok though,
82
84
because the inventory.kndx file is not ignored, and the integrity of
124
126
for rev_id in left_repo.all_revision_ids():
125
127
self.assertEqual(left_repo.get_revision(rev_id),
126
128
right_repo.get_revision(rev_id))
128
left_inv_weave = left_repo.get_inventory_weave()
129
right_inv_weave = right_repo.get_inventory_weave()
130
self.assertEqual(set(left_inv_weave.versions()),
131
set(right_inv_weave.versions()))
132
# XXX: currently this does not handle indirectly referenced
133
# inventories (e.g. where the inventory is a delta basis for
134
# one that is fully present but that the revid for that
135
# inventory is not yet present.)
136
self.assertEqual(set(left_inv_weave.versions()), set(all_revs))
137
left_trees = left_repo.revision_trees(all_revs)
138
right_trees = right_repo.revision_trees(all_revs)
139
for left_tree, right_tree in izip(left_trees, right_trees):
140
self.assertEqual(left_tree.inventory, right_tree.inventory)
129
# Assert the revision trees (and thus the inventories) are equal
130
sort_key = lambda rev_tree: rev_tree.get_revision_id()
131
rev_trees_a = sorted(
132
left_repo.revision_trees(all_revs), key=sort_key)
133
rev_trees_b = sorted(
134
right_repo.revision_trees(all_revs), key=sort_key)
135
for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
136
self.assertEqual([], list(tree_a.iter_changes(tree_b)))
142
138
text_index = left_repo._generate_text_key_index()
143
139
self.assertEqual(text_index,
144
140
right_repo._generate_text_key_index())
145
142
for file_id, revision_id in text_index.iterkeys():
146
left_weave = left_repo.weave_store.get_weave(
147
file_id, left_repo.get_transaction())
148
right_weave = right_repo.weave_store.get_weave(
149
file_id, right_repo.get_transaction())
151
left_weave.get_text(revision_id),
152
right_weave.get_text(revision_id))
143
desired_files.append(
144
(file_id, revision_id, (file_id, revision_id)))
145
left_texts = list(left_repo.iter_files_bytes(desired_files))
146
right_texts = list(right_repo.iter_files_bytes(desired_files))
149
self.assertEqual(left_texts, right_texts)
154
151
for rev_id in all_revs:
174
171
raise TestSkipped("bzrdir on transport %r has no working tree"
175
172
% a_bzrdir.transport)
174
def openWorkingTreeIfLocal(self, a_bzrdir):
175
"""If a_bzrdir is on a local transport, call open_workingtree() on it.
177
if not isinstance(a_bzrdir.root_transport, LocalTransport):
178
# it's not local, but that's ok
180
a_bzrdir.open_workingtree()
177
182
def createWorkingTreeOrSkip(self, a_bzrdir):
178
183
"""Create a working tree on a_bzrdir, or raise TestSkipped.
180
185
A simple wrapper for create_workingtree that translates NotLocalUrl into
181
186
TestSkipped. Returns the newly created working tree.
187
192
% a_bzrdir.transport)
189
194
def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
190
force_new_repo=False, accelerator_tree=None):
195
force_new_repo=False, accelerator_tree=None,
196
create_tree_if_local=True):
191
197
"""Sprout from_bzrdir into to_url, or raise TestSkipped.
193
199
A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
194
200
TestSkipped. Returns the newly sprouted bzrdir.
199
205
target = from_bzrdir.sprout(to_url, revision_id=revision_id,
200
206
force_new_repo=force_new_repo,
201
207
possible_transports=[to_transport],
202
accelerator_tree=accelerator_tree)
208
accelerator_tree=accelerator_tree,
209
create_tree_if_local=create_tree_if_local)
205
212
def test_create_null_workingtree(self):
289
296
self.assertNotEqual(dir.transport.base, target.transport.base)
290
297
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
291
298
['./.bzr/merge-hashes'])
293
300
def test_clone_bzrdir_repository(self):
294
301
tree = self.make_branch_and_tree('commit_tree')
295
302
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
306
313
'./.bzr/merge-hashes',
307
314
'./.bzr/repository',
309
self.assertRepositoryHasSameItems(tree.branch.repository, repo)
316
self.assertRepositoryHasSameItems(tree.branch.repository,
317
target.open_repository())
311
319
def test_clone_bzrdir_repository_under_shared(self):
312
320
tree = self.make_branch_and_tree('commit_tree')
382
390
self.assertTrue(branch.repository.has_revision('1'))
383
391
self.assertFalse(branch.repository.make_working_trees())
384
392
self.assertTrue(branch.repository.is_shared())
386
394
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
387
395
tree = self.make_branch_and_tree('commit_tree')
388
396
self.build_tree(['commit_tree/foo'])
407
415
# test for revision limiting, [smoke test, not corner case checks].
408
416
# make a repository with some revisions,
409
417
# and clone it with a revision limit.
411
419
tree = self.make_branch_and_tree('commit_tree')
412
420
self.build_tree(['commit_tree/foo'])
503
511
# test for revision limiting, [smoke test, not corner case checks].
504
512
# make a branch with some revisions,
505
513
# and clone it with a revision limit.
507
515
tree = self.make_branch_and_tree('commit_tree')
508
516
self.build_tree(['commit_tree/foo'])
515
523
dir = source.bzrdir
516
524
target = dir.clone(self.get_url('target'), revision_id='1')
517
525
self.assertEqual('1', target.open_branch().last_revision())
519
527
def test_clone_bzrdir_tree_branch_repo(self):
520
528
tree = self.make_branch_and_tree('source')
521
529
self.build_tree(['source/foo'])
546
554
# Ensure no format data is cached
547
555
a_dir = bzrlib.branch.Branch.open_from_transport(
548
556
self.get_transport('source')).bzrdir
549
target_transport = a_dir.root_transport.clone('..').clone('target')
557
target_transport = self.get_transport('target')
550
558
target_bzrdir = a_dir.clone_on_transport(target_transport)
551
559
target_repo = target_bzrdir.open_repository()
560
source_branch = bzrlib.branch.Branch.open(
561
self.get_vfs_only_url('source'))
562
if isinstance(target_repo, RemoteRepository):
563
target_repo._ensure_real()
564
target_repo = target_repo._real_repository
552
565
self.assertEqual(target_repo._format, source_branch.repository._format)
554
567
def test_revert_inventory(self):
583
596
target.open_repository())
585
598
def test_clone_bzrdir_tree_branch_reference(self):
586
# a tree with a branch reference (aka a checkout)
599
# a tree with a branch reference (aka a checkout)
587
600
# should stay a checkout on clone.
588
601
referenced_branch = self.make_branch('referencced')
589
602
dir = self.make_bzrdir('source')
641
654
a_dir.open_branch()
642
655
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
657
def test_clone_respects_stacked(self):
658
branch = self.make_branch('parent')
659
child_transport = self.get_transport('child')
660
child = branch.bzrdir.clone_on_transport(child_transport,
661
stacked_on=branch.base)
662
self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
644
664
def test_get_branch_reference_on_reference(self):
645
665
"""get_branch_reference should return the right url."""
646
666
referenced_branch = self.make_branch('referenced')
670
690
def test_sprout_bzrdir_empty(self):
671
691
dir = self.make_bzrdir('source')
672
target = self.sproutOrSkip(dir, self.get_url('target'))
692
target = dir.sprout(self.get_url('target'))
673
693
self.assertNotEqual(dir.transport.base, target.transport.base)
674
694
# creates a new repository branch and tree
675
695
target.open_repository()
676
696
target.open_branch()
677
target.open_workingtree()
697
self.openWorkingTreeIfLocal(target)
679
699
def test_sprout_bzrdir_empty_under_shared_repo(self):
680
700
# sprouting an empty dir into a repo uses the repo
683
703
self.make_repository('target', shared=True)
684
704
except errors.IncompatibleFormat:
686
target = self.sproutOrSkip(dir, self.get_url('target/child'))
706
target = dir.sprout(self.get_url('target/child'))
687
707
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
688
708
target.open_branch()
701
721
self.make_repository('target', shared=True)
702
722
except errors.IncompatibleFormat:
704
target = self.sproutOrSkip(dir, self.get_url('target/child'),
724
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
706
725
target.open_repository()
707
726
target.open_branch()
708
target.open_workingtree()
727
self.openWorkingTreeIfLocal(target)
710
729
def test_sprout_bzrdir_repository(self):
711
730
tree = self.make_branch_and_tree('commit_tree')
712
731
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
722
741
dir.open_branch().last_revision())))
723
742
except errors.NotBranchError:
725
target = self.sproutOrSkip(dir, self.get_url('target'))
744
target = dir.sprout(self.get_url('target'))
726
745
self.assertNotEqual(dir.transport.base, target.transport.base)
727
746
# testing inventory isn't reasonable for repositories
728
747
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
737
756
# If we happen to have a tree, we'll guarantee everything
738
757
# except for the tree root is the same.
739
758
inventory_f = file(dir.transport.base+'inventory', 'rb')
740
self.assertContainsRe(inventory_f.read(),
759
self.assertContainsRe(inventory_f.read(),
741
760
'<inventory file_id="TREE_ROOT[^"]*"'
742
761
' format="5">\n</inventory>\n')
743
762
inventory_f.close()
760
779
shared_repo = self.make_repository('target', shared=True)
761
780
except errors.IncompatibleFormat:
763
target = self.sproutOrSkip(dir, self.get_url('target/child'))
782
target = dir.sprout(self.get_url('target/child'))
764
783
self.assertNotEqual(dir.transport.base, target.transport.base)
765
784
self.assertTrue(shared_repo.has_revision('1'))
779
798
tree.branch.repository.copy_content_into(shared_repo)
780
799
dir = self.make_bzrdir('shared/source')
781
800
dir.create_branch()
782
target = self.sproutOrSkip(dir, self.get_url('shared/target'))
801
target = dir.sprout(self.get_url('shared/target'))
783
802
self.assertNotEqual(dir.transport.base, target.transport.base)
784
803
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
785
804
self.assertTrue(shared_repo.has_revision('1'))
803
822
self.assertTrue(shared_repo.has_revision('1'))
804
823
dir = self.make_bzrdir('shared/source')
805
824
dir.create_branch()
806
target = self.sproutOrSkip(dir, self.get_url('target'))
825
target = dir.sprout(self.get_url('target'))
807
826
self.assertNotEqual(dir.transport.base, target.transport.base)
808
827
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
809
828
branch = target.open_branch()
827
846
shared_repo = self.make_repository('target', shared=True)
828
847
except errors.IncompatibleFormat:
830
target = self.sproutOrSkip(dir, self.get_url('target/child'),
849
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
832
850
self.assertNotEqual(dir.transport.base, target.transport.base)
833
851
self.assertFalse(shared_repo.has_revision('1'))
836
854
# test for revision limiting, [smoke test, not corner case checks].
837
855
# make a repository with some revisions,
838
856
# and sprout it with a revision limit.
840
858
tree = self.make_branch_and_tree('commit_tree')
841
859
self.build_tree(['commit_tree/foo'])
859
877
tree.branch.repository.copy_content_into(source.repository)
860
878
tree.bzrdir.open_branch().copy_content_into(source)
861
879
dir = source.bzrdir
862
target = self.sproutOrSkip(dir, self.get_url('target'))
880
target = dir.sprout(self.get_url('target'))
863
881
self.assertNotEqual(dir.transport.base, target.transport.base)
882
target_repo = target.open_repository()
883
self.assertRepositoryHasSameItems(source.repository, target_repo)
864
884
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
866
886
'./.bzr/basis-inventory-cache',
891
911
shared_repo = self.make_repository('target', shared=True)
892
912
except errors.IncompatibleFormat:
894
target = self.sproutOrSkip(dir, self.get_url('target/child'))
914
target = dir.sprout(self.get_url('target/child'))
895
915
self.assertTrue(shared_repo.has_revision('1'))
897
917
def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
909
929
shared_repo = self.make_repository('target', shared=True)
910
930
except errors.IncompatibleFormat:
912
target = self.sproutOrSkip(dir, self.get_url('target/child'),
932
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
914
933
self.assertNotEqual(dir.transport.base, target.transport.base)
915
934
self.assertFalse(shared_repo.has_revision('1'))
917
936
def test_sprout_bzrdir_branch_reference(self):
918
937
# sprouting should create a repository if needed and a sprouted branch.
919
referenced_branch = self.make_branch('referencced')
938
referenced_branch = self.make_branch('referenced')
920
939
dir = self.make_bzrdir('source')
922
941
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
925
944
# this is ok too, not all formats have to support references.
927
946
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
928
target = self.sproutOrSkip(dir, self.get_url('target'))
947
target = dir.sprout(self.get_url('target'))
929
948
self.assertNotEqual(dir.transport.base, target.transport.base)
930
949
# we want target to have a branch that is in-place.
931
950
self.assertEqual(target, target.open_branch().bzrdir)
932
# and as we dont support repositories being detached yet, a repo in
951
# and as we dont support repositories being detached yet, a repo in
934
953
target.open_repository()
949
968
shared_repo = self.make_repository('target', shared=True)
950
969
except errors.IncompatibleFormat:
952
target = self.sproutOrSkip(dir, self.get_url('target/child'))
971
target = dir.sprout(self.get_url('target/child'))
953
972
self.assertNotEqual(dir.transport.base, target.transport.base)
954
973
# we want target to have a branch that is in-place.
955
974
self.assertEqual(target, target.open_branch().bzrdir)
956
975
# and we want no repository as the target is shared
957
self.assertRaises(errors.NoRepositoryPresent,
976
self.assertRaises(errors.NoRepositoryPresent,
958
977
target.open_repository)
959
978
# and we want revision '1' in the shared repo
960
979
self.assertTrue(shared_repo.has_revision('1'))
975
994
shared_repo = self.make_repository('target', shared=True)
976
995
except errors.IncompatibleFormat:
978
target = self.sproutOrSkip(dir, self.get_url('target/child'),
997
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
980
998
self.assertNotEqual(dir.transport.base, target.transport.base)
981
999
# we want target to have a branch that is in-place.
982
1000
self.assertEqual(target, target.open_branch().bzrdir)
989
1007
# test for revision limiting, [smoke test, not corner case checks].
990
1008
# make a repository with some revisions,
991
1009
# and sprout it with a revision limit.
993
1011
tree = self.make_branch_and_tree('commit_tree')
994
1012
self.build_tree(['commit_tree/foo'])
999
1017
tree.branch.repository.copy_content_into(source.repository)
1000
1018
tree.bzrdir.open_branch().copy_content_into(source)
1001
1019
dir = source.bzrdir
1002
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1020
target = dir.sprout(self.get_url('target'), revision_id='1')
1003
1021
self.assertEqual('1', target.open_branch().last_revision())
1005
1023
def test_sprout_bzrdir_tree_branch_repo(self):
1006
1024
tree = self.make_branch_and_tree('source')
1007
1025
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1040
1058
tree = self.createWorkingTreeOrSkip(dir)
1041
1059
self.build_tree(['source/subdir/'])
1042
1060
tree.add('subdir')
1043
target = self.sproutOrSkip(dir, self.get_url('target'))
1061
target = dir.sprout(self.get_url('target'))
1044
1062
self.assertNotEqual(dir.transport.base, target.transport.base)
1045
1063
# we want target to have a branch that is in-place.
1046
1064
self.assertEqual(target, target.open_branch().bzrdir)
1047
# and as we dont support repositories being detached yet, a repo in
1065
# and as we dont support repositories being detached yet, a repo in
1049
1067
target.open_repository()
1050
1068
result_tree = target.open_workingtree()
1073
1091
self.assertNotEqual(dir.transport.base, target.transport.base)
1074
1092
# we want target to have a branch that is in-place.
1075
1093
self.assertEqual(target, target.open_branch().bzrdir)
1076
# and as we dont support repositories being detached yet, a repo in
1094
# and as we dont support repositories being detached yet, a repo in
1078
1096
target.open_repository()
1079
1097
# we trust that the working tree sprouting works via the other tests.
1106
1124
accelerator_tree=tree)
1107
1125
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
1127
def test_sprout_branch_no_tree(self):
1128
tree = self.make_branch_and_tree('source')
1129
self.build_tree(['source/foo'])
1131
tree.commit('revision 1', rev_id='1')
1132
tree.commit('revision 2', rev_id='2', allow_pointless=True)
1134
if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
1135
self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
1136
self.get_url('target'),
1137
create_tree_if_local=False)
1139
target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
1140
self.failIfExists('target/foo')
1141
self.assertEqual(tree.branch.last_revision(),
1142
target.open_branch().last_revision())
1109
1144
def test_format_initialize_find_open(self):
1110
1145
# loopback test to check the current format initializes to itself.
1111
1146
if not self.bzrdir_format.is_supported():
1128
1163
opened_dir._format)
1129
1164
self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
1166
def test_format_network_name(self):
1167
# All control formats must have a network name.
1168
dir = self.make_bzrdir('.')
1169
format = dir._format
1170
# We want to test that the network_name matches the actual format on
1171
# disk. For local control dirsthat means that using network_name as a
1172
# key in the registry gives back the same format. For remote obects
1173
# we check that the network_name of the RemoteBzrDirFormat we have
1174
# locally matches the actual format present on disk.
1175
if isinstance(format, bzrdir.RemoteBzrDirFormat):
1177
real_dir = dir._real_bzrdir
1178
network_name = format.network_name()
1179
self.assertEqual(real_dir._format.network_name(), network_name)
1181
registry = bzrdir.network_format_registry
1182
network_name = format.network_name()
1183
looked_up_format = registry.get(network_name)
1184
self.assertEqual(format.__class__, looked_up_format.__class__)
1185
# The network name must be a byte string.
1186
self.assertIsInstance(network_name, str)
1131
1188
def test_open_not_bzrdir(self):
1132
1189
# test the formats specific behaviour for no-content or similar dirs.
1133
1190
self.assertRaises(NotBranchError,
1147
1204
made_branch = made_control.create_branch()
1148
1205
self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1149
1206
self.assertEqual(made_control, made_branch.bzrdir)
1151
1208
def test_open_branch(self):
1152
1209
if not self.bzrdir_format.is_supported():
1153
1210
# unsupported formats are not loopback testable
1178
1235
self.assertEqual(made_control, made_repo.bzrdir)
1180
1237
def test_create_repository_shared(self):
1181
# a bzrdir can create a shared repository or
1238
# a bzrdir can create a shared repository or
1182
1239
# fail appropriately
1183
1240
if not self.bzrdir_format.is_supported():
1184
1241
# unsupported formats are not loopback testable
1196
1253
self.assertTrue(made_repo.is_shared())
1198
1255
def test_create_repository_nonshared(self):
1199
# a bzrdir can create a non-shared repository
1256
# a bzrdir can create a non-shared repository
1200
1257
if not self.bzrdir_format.is_supported():
1201
1258
# unsupported formats are not loopback testable
1202
1259
# because the default open will not open them and
1206
1263
made_control = self.bzrdir_format.initialize(t.base)
1207
1264
made_repo = made_control.create_repository(shared=False)
1208
1265
self.assertFalse(made_repo.is_shared())
1210
1267
def test_open_repository(self):
1211
1268
if not self.bzrdir_format.is_supported():
1212
1269
# unsupported formats are not loopback testable
1235
1292
made_tree = self.createWorkingTreeOrSkip(made_control)
1236
1293
self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1237
1294
self.assertEqual(made_control, made_tree.bzrdir)
1239
1296
def test_create_workingtree_revision(self):
1240
1297
# a bzrdir can construct a working tree for itself @ a specific revision.
1241
1298
t = self.get_transport()
1252
1309
except errors.NotLocalUrl:
1253
1310
raise TestSkipped("Can't make working tree on transport %r" % t)
1254
1311
self.assertEqual(['a'], made_tree.get_parent_ids())
1256
1313
def test_open_workingtree(self):
1257
1314
if not self.bzrdir_format.is_supported():
1258
1315
# unsupported formats are not loopback testable
1360
1417
self.get_url('intermediate/child'))
1362
1419
child_repo = innermost_control.open_repository()
1363
# if there is a repository, then the format cannot ever hit this
1420
# if there is a repository, then the format cannot ever hit this
1366
1423
except errors.NoRepositoryPresent:
1381
1438
made_control = self.bzrdir_format.initialize(url)
1383
1440
child_repo = made_control.open_repository()
1384
# if there is a repository, then the format cannot ever hit this
1441
# if there is a repository, then the format cannot ever hit this
1387
1444
except errors.NoRepositoryPresent:
1389
1446
found_repo = made_control.find_repository()
1390
1447
self.assertEqual(repo.bzrdir.root_transport.base,
1391
1448
found_repo.bzrdir.root_transport.base)
1393
1450
def test_find_repository_standalone_with_containing_shared_repository(self):
1394
1451
# find repo inside a standalone repo inside a shared repo finds the standalone repo
1422
1479
containing_repo.bzrdir.root_transport.base)
1424
1481
def test_find_repository_with_nested_dirs_works(self):
1425
# find repo inside a bzrdir inside a bzrdir inside a shared repo
1482
# find repo inside a bzrdir inside a bzrdir inside a shared repo
1426
1483
# finds the outer shared repo.
1428
1485
repo = self.make_repository('.', shared=True)
1435
1492
made_control = self.bzrdir_format.initialize(url)
1437
1494
child_repo = made_control.open_repository()
1438
# if there is a repository, then the format cannot ever hit this
1495
# if there is a repository, then the format cannot ever hit this
1441
1498
except errors.NoRepositoryPresent:
1444
1501
self.get_url('intermediate/child'))
1446
1503
child_repo = innermost_control.open_repository()
1447
# if there is a repository, then the format cannot ever hit this
1504
# if there is a repository, then the format cannot ever hit this
1450
1507
except errors.NoRepositoryPresent:
1452
1509
found_repo = innermost_control.find_repository()
1453
1510
self.assertEqual(repo.bzrdir.root_transport.base,
1454
1511
found_repo.bzrdir.root_transport.base)
1456
1513
def test_can_and_needs_format_conversion(self):
1457
1514
# check that we can ask an instance if its upgradable
1458
1515
dir = self.make_bzrdir('.')
1459
1516
if dir.can_convert_format():
1460
# if its default updatable there must be an updater
1517
# if its default updatable there must be an updater
1461
1518
# (we force the latest known format as downgrades may not be
1463
1520
self.assertTrue(isinstance(dir._format.get_converter(
1464
1521
format=dir._format), bzrdir.Converter))
1465
dir.needs_format_conversion(None)
1522
dir.needs_format_conversion(
1523
bzrdir.BzrDirFormat.get_default_format())
1525
def test_backup_copies_existing(self):
1526
tree = self.make_branch_and_tree('test')
1527
self.build_tree(['test/a'])
1528
tree.add(['a'], ['a-id'])
1529
tree.commit('some data to be copied.')
1530
old_url, new_url = tree.bzrdir.backup_bzrdir()
1531
old_path = urlutils.local_path_from_url(old_url)
1532
new_path = urlutils.local_path_from_url(new_url)
1533
self.failUnlessExists(old_path)
1534
self.failUnlessExists(new_path)
1535
for (((dir_relpath1, _), entries1),
1536
((dir_relpath2, _), entries2)) in izip(
1537
osutils.walkdirs(old_path),
1538
osutils.walkdirs(new_path)):
1539
self.assertEquals(dir_relpath1, dir_relpath2)
1540
for f1, f2 in zip(entries1, entries2):
1541
self.assertEquals(f1[0], f2[0])
1542
self.assertEquals(f1[2], f2[2])
1544
osutils.compare_files(open(f1[4]), open(f2[4]))
1467
1546
def test_upgrade_new_instance(self):
1468
1547
"""Does an available updater work?"""
1472
1551
dir.create_branch()
1473
1552
self.createWorkingTreeOrSkip(dir)
1474
1553
if dir.can_convert_format():
1475
# if its default updatable there must be an updater
1554
# if its default updatable there must be an updater
1476
1555
# (we force the latest known format as downgrades may not be
1478
1557
pb = ui.ui_factory.nested_progress_bar()
1483
1562
# and it should pass 'check' now.
1484
check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
1563
check_branch(bzrdir.BzrDir.open(self.get_url('.')).open_branch(),
1486
1566
def test_format_description(self):
1487
1567
dir = self.make_bzrdir('.')
1507
1587
transport=transport)
1508
1588
self.failUnless(transport.has('.bzr'))
1509
1589
self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
1510
bd.retire_bzrdir, limit=0)
1590
bd.retire_bzrdir, limit=0)
1513
1593
class TestBreakLock(TestCaseWithBzrDir):
1602
1682
self.assertRaises(errors.LockBroken, master.unlock)
1604
1684
def test_break_lock_tree(self):
1605
# break lock with a tree should unlock the tree but not try the
1606
# branch explicitly. However this is very hard to test for as we
1607
# dont have a tree reference class, nor is one needed;
1685
# break lock with a tree should unlock the tree but not try the
1686
# branch explicitly. However this is very hard to test for as we
1687
# dont have a tree reference class, nor is one needed;
1608
1688
# the worst case if this code unlocks twice is an extra question
1610
1690
tree = self.make_branch_and_tree('.')
1627
1707
self.assertRaises(errors.LockBroken, tree.unlock)
1710
class TestTransportConfig(TestCaseWithBzrDir):
1712
def test_get_config(self):
1713
my_dir = self.make_bzrdir('.')
1714
config = my_dir.get_config()
1717
isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1718
"%r should support configs" % my_dir)
1719
raise TestNotApplicable(
1720
'This BzrDir format does not support configs.')
1721
config.set_default_stack_on('http://example.com')
1722
self.assertEqual('http://example.com', config.get_default_stack_on())
1723
my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
1724
config2 = my_dir2.get_config()
1725
self.assertEqual('http://example.com', config2.get_default_stack_on())
1630
1728
class ChrootedBzrDirTests(ChrootedTestCase):
1632
1730
def test_find_repository_no_repository(self):
1633
# loopback test to check the current format fails to find a
1731
# loopback test to check the current format fails to find a
1634
1732
# share repository correctly.
1635
1733
if not self.bzrdir_format.is_supported():
1636
1734
# unsupported formats are not loopback testable
1645
1743
made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1647
1745
repo = made_control.open_repository()
1648
# if there is a repository, then the format cannot ever hit this
1746
# if there is a repository, then the format cannot ever hit this
1651
1749
except errors.NoRepositoryPresent: