33
revision as _mod_revision,
39
from bzrlib.errors import (NoSuchRevision,
42
34
import bzrlib.revision
43
35
from bzrlib.tests import (
48
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
49
42
from bzrlib.transport.local import LocalTransport
50
43
from bzrlib.ui import (
51
44
CannedInputUIFactory,
53
from bzrlib.remote import RemoteBzrDir, RemoteRepository
54
from bzrlib.repofmt import weaverepo
46
from bzrlib.remote import (
57
53
class TestControlDir(TestCaseWithControlDir):
58
# Many of these tests test for disk equality rather than checking
59
# for semantic equivalence. This works well for some tests but
60
# is not good at handling changes in representation or the addition
61
# or removal of control data. It would be nice to for instance:
62
# sprout a new branch, check that the nickname has been reset by hand
63
# and then set the nickname to match the source branch, at which point
64
# a semantic equivalence should pass
66
def assertDirectoriesEqual(self, source, target, ignore_list=[]):
67
"""Assert that the content of source and target are identical.
69
paths in ignore list will be completely ignored.
71
We ignore paths that represent data which is allowed to change during
72
a clone or sprout: for instance, inventory.knit contains gzip fragements
73
which have timestamps in them, and as we have read the inventory from
74
the source knit, the already-read data is recompressed rather than
75
reading it again, which leads to changed timestamps. This is ok though,
76
because the inventory.kndx file is not ignored, and the integrity of
77
knit joins is tested by test_knit and test_versionedfile.
79
:seealso: Additionally, assertRepositoryHasSameItems provides value
80
rather than representation checking of repositories for
86
dir = directories.pop()
87
for path in set(source.list_dir(dir) + target.list_dir(dir)):
88
path = dir + '/' + path
89
if path in ignore_list:
92
stat = source.stat(path)
93
except errors.NoSuchFile:
94
self.fail('%s not in source' % path)
95
if S_ISDIR(stat.st_mode):
96
self.assertTrue(S_ISDIR(target.stat(path).st_mode))
97
directories.append(path)
99
self.assertEqualDiff(source.get(path).read(),
100
target.get(path).read(),
101
"text for file %r differs:\n" % path)
103
def assertRepositoryHasSameItems(self, left_repo, right_repo):
104
"""require left_repo and right_repo to contain the same data."""
105
# XXX: TODO: Doesn't work yet, because we need to be able to compare
106
# local repositories to remote ones... but this is an as-yet unsolved
107
# aspect of format management and the Remote protocols...
108
# self.assertEqual(left_repo._format.__class__,
109
# right_repo._format.__class__)
110
left_repo.lock_read()
112
right_repo.lock_read()
115
all_revs = left_repo.all_revision_ids()
116
self.assertEqual(left_repo.all_revision_ids(),
117
right_repo.all_revision_ids())
118
for rev_id in left_repo.all_revision_ids():
119
self.assertEqual(left_repo.get_revision(rev_id),
120
right_repo.get_revision(rev_id))
121
# Assert the revision trees (and thus the inventories) are equal
122
sort_key = lambda rev_tree: rev_tree.get_revision_id()
123
rev_trees_a = sorted(
124
left_repo.revision_trees(all_revs), key=sort_key)
125
rev_trees_b = sorted(
126
right_repo.revision_trees(all_revs), key=sort_key)
127
for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
128
self.assertEqual([], list(tree_a.iter_changes(tree_b)))
130
text_index = left_repo._generate_text_key_index()
131
self.assertEqual(text_index,
132
right_repo._generate_text_key_index())
134
for file_id, revision_id in text_index.iterkeys():
135
desired_files.append(
136
(file_id, revision_id, (file_id, revision_id)))
137
left_texts = list(left_repo.iter_files_bytes(desired_files))
138
right_texts = list(right_repo.iter_files_bytes(desired_files))
141
self.assertEqual(left_texts, right_texts)
143
for rev_id in all_revs:
145
left_text = left_repo.get_signature_text(rev_id)
146
except NoSuchRevision:
148
right_text = right_repo.get_signature_text(rev_id)
149
self.assertEqual(left_text, right_text)
155
55
def skipIfNoWorkingTree(self, a_bzrdir):
156
56
"""Raises TestSkipped if a_bzrdir doesn't have a working tree.
266
166
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
268
def test_clone_on_transport(self):
269
a_dir = self.make_bzrdir('source')
270
target_transport = a_dir.root_transport.clone('..').clone('target')
271
target = a_dir.clone_on_transport(target_transport)
272
self.assertNotEqual(a_dir.transport.base, target.transport.base)
273
self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
274
['./.bzr/merge-hashes'])
276
def test_clone_bzrdir_empty(self):
277
dir = self.make_bzrdir('source')
278
target = dir.clone(self.get_url('target'))
279
self.assertNotEqual(dir.transport.base, target.transport.base)
280
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
281
['./.bzr/merge-hashes'])
283
def test_clone_bzrdir_empty_force_new_ignored(self):
284
# the force_new_repo parameter should have no effect on an empty
285
# bzrdir's clone logic
286
dir = self.make_bzrdir('source')
287
target = dir.clone(self.get_url('target'), force_new_repo=True)
288
self.assertNotEqual(dir.transport.base, target.transport.base)
289
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
290
['./.bzr/merge-hashes'])
292
def test_clone_bzrdir_repository(self):
293
tree = self.make_branch_and_tree('commit_tree')
294
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
296
tree.commit('revision 1', rev_id='1')
297
dir = self.make_bzrdir('source')
298
repo = dir.create_repository()
299
repo.fetch(tree.branch.repository)
300
self.assertTrue(repo.has_revision('1'))
301
target = dir.clone(self.get_url('target'))
302
self.assertNotEqual(dir.transport.base, target.transport.base)
303
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
305
'./.bzr/merge-hashes',
308
self.assertRepositoryHasSameItems(tree.branch.repository,
309
target.open_repository())
311
168
def test_clone_bzrdir_repository_under_shared(self):
312
169
tree = self.make_branch_and_tree('commit_tree')
313
170
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
383
242
self.assertFalse(branch.repository.make_working_trees())
384
243
self.assertTrue(branch.repository.is_shared())
386
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
387
tree = self.make_branch_and_tree('commit_tree')
388
self.build_tree(['commit_tree/foo'])
390
tree.commit('revision 1', rev_id='1')
391
dir = self.make_bzrdir('source')
392
repo = dir.create_repository()
393
repo.fetch(tree.branch.repository)
394
self.assertTrue(repo.has_revision('1'))
396
self.make_repository('target', shared=True)
397
except errors.IncompatibleFormat:
399
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
400
self.assertNotEqual(dir.transport.base, target.transport.base)
401
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
402
['./.bzr/repository',
404
self.assertRepositoryHasSameItems(tree.branch.repository, repo)
406
245
def test_clone_bzrdir_repository_revision(self):
407
246
# test for revision limiting, [smoke test, not corner case checks].
408
247
# make a repository with some revisions,
442
282
tree_repo.get_signature_text(rev1),
443
283
target.repository.get_signature_text(rev1))
445
def test_clone_bzrdir_branch_and_repo(self):
446
tree = self.make_branch_and_tree('commit_tree')
447
self.build_tree(['commit_tree/foo'])
449
tree.commit('revision 1')
450
source = self.make_branch('source')
451
tree.branch.repository.copy_content_into(source.repository)
452
tree.branch.copy_content_into(source)
454
target = dir.clone(self.get_url('target'))
455
self.assertNotEqual(dir.transport.base, target.transport.base)
456
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
458
'./.bzr/basis-inventory-cache',
459
'./.bzr/checkout/stat-cache',
460
'./.bzr/merge-hashes',
464
self.assertRepositoryHasSameItems(
465
tree.branch.repository, target.open_repository())
467
285
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
468
286
# by default cloning into a shared repo uses the shared repo.
469
287
tree = self.make_branch_and_tree('commit_tree')
484
302
self.assertEqual(source.revision_history(),
485
303
target.open_branch().revision_history())
487
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
488
# by default cloning into a shared repo uses the shared repo.
489
tree = self.make_branch_and_tree('commit_tree')
490
self.build_tree(['commit_tree/foo'])
492
tree.commit('revision 1')
493
source = self.make_branch('source')
494
tree.branch.repository.copy_content_into(source.repository)
495
tree.branch.copy_content_into(source)
497
self.make_repository('target', shared=True)
498
except errors.IncompatibleFormat:
501
target = dir.clone(self.get_url('target/child'), force_new_repo=True)
502
self.assertNotEqual(dir.transport.base, target.transport.base)
503
repo = target.open_repository()
504
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
505
['./.bzr/repository',
507
self.assertRepositoryHasSameItems(tree.branch.repository, repo)
509
def test_clone_bzrdir_branch_reference(self):
510
# cloning should preserve the reference status of the branch in a bzrdir
511
referenced_branch = self.make_branch('referencced')
512
dir = self.make_bzrdir('source')
514
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
515
target_branch=referenced_branch)
516
except errors.IncompatibleFormat:
517
# this is ok too, not all formats have to support references.
519
target = dir.clone(self.get_url('target'))
520
self.assertNotEqual(dir.transport.base, target.transport.base)
521
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
523
305
def test_clone_bzrdir_branch_revision(self):
524
306
# test for revision limiting, [smoke test, not corner case checks].
525
307
# make a branch with some revisions,
537
319
target = dir.clone(self.get_url('target'), revision_id='1')
538
320
self.assertEqual('1', target.open_branch().last_revision())
540
def test_clone_bzrdir_tree_branch_repo(self):
541
tree = self.make_branch_and_tree('source')
542
self.build_tree(['source/foo'])
544
tree.commit('revision 1')
546
target = dir.clone(self.get_url('target'))
547
self.skipIfNoWorkingTree(target)
548
self.assertNotEqual(dir.transport.base, target.transport.base)
549
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
550
['./.bzr/stat-cache',
551
'./.bzr/checkout/dirstate',
552
'./.bzr/checkout/stat-cache',
553
'./.bzr/checkout/merge-hashes',
554
'./.bzr/merge-hashes',
557
self.assertRepositoryHasSameItems(tree.branch.repository,
558
target.open_repository())
559
target.open_workingtree().revert()
561
322
def test_clone_on_transport_preserves_repo_format(self):
562
323
if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
577
338
target_repo = target_repo._real_repository
578
339
self.assertEqual(target_repo._format, source_branch.repository._format)
580
def test_revert_inventory(self):
581
tree = self.make_branch_and_tree('source')
582
self.build_tree(['source/foo'])
584
tree.commit('revision 1')
586
target = dir.clone(self.get_url('target'))
587
self.skipIfNoWorkingTree(target)
588
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
589
['./.bzr/stat-cache',
590
'./.bzr/checkout/dirstate',
591
'./.bzr/checkout/stat-cache',
592
'./.bzr/checkout/merge-hashes',
593
'./.bzr/merge-hashes',
596
self.assertRepositoryHasSameItems(tree.branch.repository,
597
target.open_repository())
599
target.open_workingtree().revert()
600
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
601
['./.bzr/stat-cache',
602
'./.bzr/checkout/dirstate',
603
'./.bzr/checkout/stat-cache',
604
'./.bzr/checkout/merge-hashes',
605
'./.bzr/merge-hashes',
608
self.assertRepositoryHasSameItems(tree.branch.repository,
609
target.open_repository())
611
def test_clone_bzrdir_tree_branch_reference(self):
612
# a tree with a branch reference (aka a checkout)
613
# should stay a checkout on clone.
614
referenced_branch = self.make_branch('referencced')
615
dir = self.make_bzrdir('source')
617
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
618
target_branch=referenced_branch)
619
except errors.IncompatibleFormat:
620
# this is ok too, not all formats have to support references.
622
self.createWorkingTreeOrSkip(dir)
623
target = dir.clone(self.get_url('target'))
624
self.skipIfNoWorkingTree(target)
625
self.assertNotEqual(dir.transport.base, target.transport.base)
626
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
627
['./.bzr/stat-cache',
628
'./.bzr/checkout/stat-cache',
629
'./.bzr/checkout/merge-hashes',
630
'./.bzr/merge-hashes',
631
'./.bzr/repository/inventory.knit',
634
341
def test_clone_bzrdir_tree_revision(self):
635
342
# test for revision limiting, [smoke test, not corner case checks].
636
343
# make a tree with a revision with a last-revision
739
445
target.open_branch()
740
446
self.openWorkingTreeIfLocal(target)
742
def test_sprout_bzrdir_repository(self):
743
tree = self.make_branch_and_tree('commit_tree')
744
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
746
tree.commit('revision 1', rev_id='1')
747
dir = self.make_bzrdir('source')
748
repo = dir.create_repository()
749
repo.fetch(tree.branch.repository)
750
self.assertTrue(repo.has_revision('1'))
753
_mod_revision.is_null(_mod_revision.ensure_null(
754
dir.open_branch().last_revision())))
755
except errors.NotBranchError:
757
target = dir.sprout(self.get_url('target'))
758
self.assertNotEqual(dir.transport.base, target.transport.base)
759
# testing inventory isn't reasonable for repositories
760
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
766
'./.bzr/repository/inventory.knit',
769
local_inventory = dir.transport.local_abspath('inventory')
770
except errors.NotLocalUrl:
773
# If we happen to have a tree, we'll guarantee everything
774
# except for the tree root is the same.
775
inventory_f = file(local_inventory, 'rb')
776
self.addCleanup(inventory_f.close)
777
self.assertContainsRe(inventory_f.read(),
778
'<inventory format="5">\n</inventory>\n')
780
if e.errno != errno.ENOENT:
783
448
def test_sprout_bzrdir_with_repository_to_shared(self):
784
449
tree = self.make_branch_and_tree('commit_tree')
785
450
self.build_tree(['commit_tree/foo'])
787
452
tree.commit('revision 1', rev_id='1')
788
tree.bzrdir.open_branch().set_revision_history([])
453
tree.bzrdir.open_branch().generate_revision_history(
454
bzrlib.revision.NULL_REVISION)
789
455
tree.set_parent_trees([])
790
456
tree.commit('revision 2', rev_id='2')
791
457
source = self.make_repository('source')
884
557
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
885
558
raise TestSkipped('revision limiting not strict yet')
887
def test_sprout_bzrdir_branch_and_repo(self):
888
tree = self.make_branch_and_tree('commit_tree')
889
self.build_tree(['commit_tree/foo'])
891
tree.commit('revision 1')
892
source = self.make_branch('source')
893
tree.branch.repository.copy_content_into(source.repository)
894
tree.bzrdir.open_branch().copy_content_into(source)
896
target = dir.sprout(self.get_url('target'))
897
self.assertNotEqual(dir.transport.base, target.transport.base)
898
target_repo = target.open_repository()
899
self.assertRepositoryHasSameItems(source.repository, target_repo)
900
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
902
'./.bzr/basis-inventory-cache',
903
'./.bzr/branch/branch.conf',
904
'./.bzr/branch/parent',
906
'./.bzr/checkout/inventory',
907
'./.bzr/checkout/stat-cache',
915
560
def test_sprout_bzrdir_branch_and_repo_shared(self):
916
561
# sprouting a branch with a repo into a shared repo uses the shared
1036
681
target = dir.sprout(self.get_url('target'), revision_id='1')
1037
682
self.assertEqual('1', target.open_branch().last_revision())
1039
def test_sprout_bzrdir_tree_branch_repo(self):
1040
tree = self.make_branch_and_tree('source')
1041
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1043
tree.commit('revision 1')
1045
target = self.sproutOrSkip(dir, self.get_url('target'))
1046
self.assertNotEqual(dir.transport.base, target.transport.base)
1047
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1049
'./.bzr/branch/branch.conf',
1050
'./.bzr/branch/parent',
1051
'./.bzr/checkout/dirstate',
1052
'./.bzr/checkout/stat-cache',
1053
'./.bzr/checkout/inventory',
1056
'./.bzr/repository',
1057
'./.bzr/stat-cache',
1059
self.assertRepositoryHasSameItems(
1060
tree.branch.repository, target.open_repository())
684
def test_sprout_bzrdir_branch_with_tags(self):
685
# when sprouting a branch all revisions named in the tags are copied
687
builder = self.make_branch_builder('source')
688
source = fixtures.build_branch_with_non_ancestral_rev(builder)
690
source.tags.set_tag('tag-a', 'rev-2')
691
except errors.TagsNotSupported:
692
raise TestNotApplicable('Branch format does not support tags.')
693
# Now source has a tag not in its ancestry. Sprout its controldir.
695
target = dir.sprout(self.get_url('target'))
696
# The tag is present, and so is its revision.
697
new_branch = target.open_branch()
698
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
699
new_branch.repository.get_revision('rev-2')
701
def test_sprout_bzrdir_branch_with_absent_tag(self):
702
# tags referencing absent revisions are copied (and those absent
703
# revisions do not prevent the sprout.)
704
builder = self.make_branch_builder('source')
705
builder.build_commit(message="Rev 1", rev_id='rev-1')
706
source = builder.get_branch()
708
source.tags.set_tag('tag-a', 'missing-rev')
709
except errors.TagsNotSupported:
710
raise TestNotApplicable('Branch format does not support tags.')
711
# Now source has a tag pointing to an absent revision. Sprout its
714
target = dir.sprout(self.get_url('target'))
715
# The tag is present in the target
716
new_branch = target.open_branch()
717
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
719
def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
720
# tags referencing absent revisions are copied (and those absent
721
# revisions do not prevent the sprout.)
722
builder = self.make_branch_builder('source')
723
builder.build_commit(message="Rev 1", rev_id='rev-1')
724
source = builder.get_branch()
726
source.tags.set_tag('tag-a', 'missing-rev')
727
except errors.TagsNotSupported:
728
raise TestNotApplicable('Branch format does not support tags.')
729
# Now source has a tag pointing to an absent revision. Sprout its
732
target = dir.sprout(self.get_url('target'), source_branch=source)
733
# The tag is present in the target
734
new_branch = target.open_branch()
735
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
737
def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
738
# dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
739
# the branch at that bzrdir, the ancestry of all of those, but no other
740
# revs (not even the tip of the source branch).
741
builder = self.make_branch_builder('source')
742
builder.build_commit(message="Base", rev_id='base-rev')
743
# Make three parallel lines of ancestry off this base.
744
source = builder.get_branch()
745
builder.build_commit(message="Rev A1", rev_id='rev-a1')
746
builder.build_commit(message="Rev A2", rev_id='rev-a2')
747
builder.build_commit(message="Rev A3", rev_id='rev-a3')
748
source.set_last_revision_info(1, 'base-rev')
749
builder.build_commit(message="Rev B1", rev_id='rev-b1')
750
builder.build_commit(message="Rev B2", rev_id='rev-b2')
751
builder.build_commit(message="Rev B3", rev_id='rev-b3')
752
source.set_last_revision_info(1, 'base-rev')
753
builder.build_commit(message="Rev C1", rev_id='rev-c1')
754
builder.build_commit(message="Rev C2", rev_id='rev-c2')
755
builder.build_commit(message="Rev C3", rev_id='rev-c3')
756
# Set the branch tip to A2
757
source.set_last_revision_info(3, 'rev-a2')
759
# Create a tag for B2, and for an absent rev
760
source.tags.set_tag('tag-non-ancestry', 'rev-b2')
761
source.tags.set_tag('tag-absent', 'absent-rev')
762
except errors.TagsNotSupported:
763
raise TestNotApplicable('Branch format does not support tags.')
764
# And ask sprout for C2
766
target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
767
# The tags are present
768
new_branch = target.open_branch()
770
{'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
771
new_branch.tags.get_tag_dict())
772
# And the revs for A2, B2 and C2's ancestries are present, but no
775
['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
776
sorted(new_branch.repository.all_revision_ids()))
1062
778
def test_sprout_bzrdir_tree_branch_reference(self):
1063
779
# sprouting should create a repository if needed and a sprouted branch.
1360
1075
# Repositories are open write-locked
1361
1076
self.assertTrue(repo.is_write_locked())
1362
1077
self.addCleanup(repo.unlock)
1363
self.assertIsInstance(control, bzrdir.BzrDir)
1078
self.assertIsInstance(control, controldir.ControlDir)
1364
1079
opened = bzrdir.BzrDir.open(t.base)
1365
1080
expected_format = self.bzrdir_format
1366
if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
1367
# Current RemoteBzrDirFormat's do not reliably get network_name
1368
# set, so we skip a number of tests for RemoteBzrDirFormat's.
1369
self.assertIsInstance(control, RemoteBzrDir)
1371
if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
1372
bzrdir.BzrDirFormat6)):
1373
# Pre-metadir formats change when we are making something that
1374
# needs a metaformat, because clone is used for push.
1375
expected_format = bzrdir.BzrDirMetaFormat1()
1081
if need_meta and expected_format.fixed_components:
1082
# Pre-metadir formats change when we are making something that
1083
# needs a metaformat, because clone is used for push.
1084
expected_format = bzrdir.BzrDirMetaFormat1()
1085
if not isinstance(expected_format, RemoteBzrDirFormat):
1376
1086
self.assertEqual(control._format.network_name(),
1377
1087
expected_format.network_name())
1378
1088
self.assertEqual(control._format.network_name(),
1389
1099
# key in the registry gives back the same format. For remote obects
1390
1100
# we check that the network_name of the RemoteBzrDirFormat we have
1391
1101
# locally matches the actual format present on disk.
1392
if isinstance(format, bzrdir.RemoteBzrDirFormat):
1102
if isinstance(format, RemoteBzrDirFormat):
1393
1103
dir._ensure_real()
1394
1104
real_dir = dir._real_bzrdir
1395
1105
network_name = format.network_name()
1396
1106
self.assertEqual(real_dir._format.network_name(), network_name)
1398
registry = bzrdir.network_format_registry
1108
registry = controldir.network_format_registry
1399
1109
network_name = format.network_name()
1400
1110
looked_up_format = registry.get(network_name)
1401
self.assertEqual(format.__class__, looked_up_format.__class__)
1112
issubclass(format.__class__, looked_up_format.__class__))
1402
1113
# The network name must be a byte string.
1403
1114
self.assertIsInstance(network_name, str)
1405
1116
def test_open_not_bzrdir(self):
1406
1117
# test the formats specific behaviour for no-content or similar dirs.
1407
self.assertRaises(NotBranchError,
1118
self.assertRaises(errors.NotBranchError,
1408
1119
self.bzrdir_format.open,
1409
1120
transport.get_transport(self.get_readonly_url()))
1561
1272
made_repo = made_control.create_repository()
1562
1273
made_branch = made_control.create_branch()
1563
1274
made_tree = made_control.create_workingtree()
1564
except errors.NotLocalUrl:
1275
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1565
1276
raise TestSkipped("Can't initialize %r on transport %r"
1566
1277
% (self.bzrdir_format, t))
1567
1278
opened_tree = made_control.open_workingtree()
1568
1279
self.assertEqual(made_control, opened_tree.bzrdir)
1569
self.failUnless(isinstance(opened_tree, made_tree.__class__))
1570
self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1572
def test_get_branch_transport(self):
1573
dir = self.make_bzrdir('.')
1574
# without a format, get_branch_transport gives use a transport
1575
# which -may- point to an existing dir.
1576
self.assertTrue(isinstance(dir.get_branch_transport(None),
1577
transport.Transport))
1578
# with a given format, either the bzr dir supports identifiable
1579
# branches, or it supports anonymous branch formats, but not both.
1580
anonymous_format = bzrlib.branch.BzrBranchFormat4()
1581
identifiable_format = bzrlib.branch.BzrBranchFormat5()
1583
found_transport = dir.get_branch_transport(anonymous_format)
1584
self.assertRaises(errors.IncompatibleFormat,
1585
dir.get_branch_transport,
1586
identifiable_format)
1587
except errors.IncompatibleFormat:
1588
found_transport = dir.get_branch_transport(identifiable_format)
1589
self.assertTrue(isinstance(found_transport, transport.Transport))
1590
# and the dir which has been initialized for us must exist.
1591
found_transport.list_dir('.')
1593
def test_get_repository_transport(self):
1594
dir = self.make_bzrdir('.')
1595
# without a format, get_repository_transport gives use a transport
1596
# which -may- point to an existing dir.
1597
self.assertTrue(isinstance(dir.get_repository_transport(None),
1598
transport.Transport))
1599
# with a given format, either the bzr dir supports identifiable
1600
# repositories, or it supports anonymous repository formats, but not both.
1601
anonymous_format = weaverepo.RepositoryFormat6()
1602
identifiable_format = weaverepo.RepositoryFormat7()
1604
found_transport = dir.get_repository_transport(anonymous_format)
1605
self.assertRaises(errors.IncompatibleFormat,
1606
dir.get_repository_transport,
1607
identifiable_format)
1608
except errors.IncompatibleFormat:
1609
found_transport = dir.get_repository_transport(identifiable_format)
1610
self.assertTrue(isinstance(found_transport, transport.Transport))
1611
# and the dir which has been initialized for us must exist.
1612
found_transport.list_dir('.')
1614
def test_get_workingtree_transport(self):
1615
dir = self.make_bzrdir('.')
1616
# without a format, get_workingtree_transport gives use a transport
1617
# which -may- point to an existing dir.
1618
self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1619
transport.Transport))
1620
# with a given format, either the bzr dir supports identifiable
1621
# trees, or it supports anonymous tree formats, but not both.
1622
anonymous_format = workingtree.WorkingTreeFormat2()
1623
identifiable_format = workingtree.WorkingTreeFormat3()
1625
found_transport = dir.get_workingtree_transport(anonymous_format)
1626
self.assertRaises(errors.IncompatibleFormat,
1627
dir.get_workingtree_transport,
1628
identifiable_format)
1629
except errors.IncompatibleFormat:
1630
found_transport = dir.get_workingtree_transport(identifiable_format)
1631
self.assertTrue(isinstance(found_transport, transport.Transport))
1632
# and the dir which has been initialized for us must exist.
1633
found_transport.list_dir('.')
1280
self.assertIsInstance(opened_tree, made_tree.__class__)
1281
self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1635
1283
def test_root_transport(self):
1636
1284
dir = self.make_bzrdir('.')
1637
1285
self.assertEqual(dir.root_transport.base,
1638
transport.get_transport(self.get_url('.')).base)
1286
self.get_transport().base)
1640
1288
def test_find_repository_no_repo_under_standalone_branch(self):
1641
1289
# finding a repo stops at standalone branches even if there is a
1802
1452
def test_format_description(self):
1803
1453
dir = self.make_bzrdir('.')
1804
1454
text = dir._format.get_format_description()
1805
self.failUnless(len(text))
1807
def test_retire_bzrdir(self):
1808
bd = self.make_bzrdir('.')
1809
transport = bd.root_transport
1810
# must not overwrite existing directories
1811
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1812
transport=transport)
1813
self.failUnless(transport.has('.bzr'))
1815
self.failIf(transport.has('.bzr'))
1816
self.failUnless(transport.has('.bzr.retired.1'))
1818
def test_retire_bzrdir_limited(self):
1819
bd = self.make_bzrdir('.')
1820
transport = bd.root_transport
1821
# must not overwrite existing directories
1822
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1823
transport=transport)
1824
self.failUnless(transport.has('.bzr'))
1825
self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
1826
bd.retire_bzrdir, limit=0)
1455
self.assertTrue(len(text))
1829
1458
class TestBreakLock(TestCaseWithControlDir):