39
from bzrlib.errors import (NoSuchRevision,
42
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.
201
101
create_tree_if_local=create_tree_if_local)
104
def test_uninitializable(self):
105
if self.bzrdir_format.is_initializable():
106
raise TestNotApplicable("format is initializable")
107
t = self.get_transport()
108
self.assertRaises(errors.UninitializableFormat,
109
self.bzrdir_format.initialize, t.base)
111
def test_multiple_initialization(self):
112
# loopback test to check the current format initializes to itself.
113
if not self.bzrdir_format.is_initializable():
114
# unsupported formats are not loopback testable
115
# because the default open will not open them and
116
# they may not be initializable.
117
raise TestNotApplicable("format is not initializable")
118
self.bzrdir_format.initialize('.')
119
self.assertRaises(errors.AlreadyControlDirError,
120
self.bzrdir_format.initialize, '.')
204
122
def test_create_null_workingtree(self):
205
123
dir = self.make_bzrdir('dir1')
206
124
dir.create_repository()
207
125
dir.create_branch()
209
wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
210
except errors.NotLocalUrl:
127
wt = dir.create_workingtree(revision_id=_mod_revision.NULL_REVISION)
128
except (errors.NotLocalUrl, errors.UnsupportedOperation):
211
129
raise TestSkipped("cannot make working tree with transport %r"
213
131
self.assertEqual([], wt.get_parent_ids())
258
186
e.g. NotLocalUrl) if there is no working tree.
260
188
dir = self.make_bzrdir('source')
261
vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
189
vfs_dir = controldir.ControlDir.open(self.get_vfs_only_url('source'))
262
190
if vfs_dir.has_workingtree():
263
191
# This ControlDir format doesn't support ControlDirs without
264
192
# working trees, so this test is irrelevant.
193
raise TestNotApplicable("format does not support "
194
"control directories without working tree")
266
195
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
197
def test_clone_bzrdir_repository_under_shared(self):
312
198
tree = self.make_branch_and_tree('commit_tree')
313
199
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
383
283
self.assertFalse(branch.repository.make_working_trees())
384
284
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
286
def test_clone_bzrdir_repository_revision(self):
407
287
# test for revision limiting, [smoke test, not corner case checks].
408
288
# make a repository with some revisions,
442
323
tree_repo.get_signature_text(rev1),
443
324
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
326
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
468
327
# by default cloning into a shared repo uses the shared repo.
469
328
tree = self.make_branch_and_tree('commit_tree')
474
333
tree.branch.repository.copy_content_into(source.repository)
475
334
tree.branch.copy_content_into(source)
477
self.make_repository('target', shared=True)
336
shared_repo = self.make_repository('target', shared=True)
478
337
except errors.IncompatibleFormat:
338
raise TestNotApplicable("repository format does not support "
339
"shared repositories")
340
if not shared_repo._format.supports_nesting_repositories:
341
raise TestNotApplicable("format does not support nesting "
480
343
dir = source.bzrdir
481
344
target = dir.clone(self.get_url('target/child'))
482
345
self.assertNotEqual(dir.transport.base, target.transport.base)
483
346
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
484
self.assertEqual(source.revision_history(),
485
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)
347
self.assertEqual(source.last_revision(),
348
target.open_branch().last_revision())
523
350
def test_clone_bzrdir_branch_revision(self):
524
351
# test for revision limiting, [smoke test, not corner case checks].
537
364
target = dir.clone(self.get_url('target'), revision_id='1')
538
365
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
367
def test_clone_on_transport_preserves_repo_format(self):
562
if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
368
if self.bzrdir_format == controldir.format_registry.make_bzrdir('default'):
577
383
target_repo = target_repo._real_repository
578
384
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
386
def test_clone_bzrdir_tree_revision(self):
635
387
# test for revision limiting, [smoke test, not corner case checks].
636
388
# make a tree with a revision with a last-revision
662
414
repo.set_make_working_trees(False)
663
415
self.assertFalse(repo.make_working_trees())
666
a_dir = dir.clone(self.get_url('repo/a'))
417
a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
418
a_branch = a_dir.open_branch()
419
# If the new control dir actually uses the repository, it should
420
# not have a working tree.
421
if not a_branch.repository.has_same_location(repo):
422
raise TestNotApplicable('new control dir does not use repository')
668
423
self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
670
425
def test_clone_respects_stacked(self):
671
426
branch = self.make_branch('parent')
672
427
child_transport = self.get_transport('child')
673
child = branch.bzrdir.clone_on_transport(child_transport,
674
stacked_on=branch.base)
429
child = branch.bzrdir.clone_on_transport(child_transport,
430
stacked_on=branch.base)
431
except (errors.UnstackableBranchFormat,
432
errors.UnstackableRepositoryFormat):
433
raise TestNotApplicable("branch or repository format does "
434
"not support stacking")
675
435
self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
437
def test_set_branch_reference(self):
438
"""set_branch_reference creates a branch reference"""
439
referenced_branch = self.make_branch('referenced')
440
dir = self.make_bzrdir('source')
442
reference = dir.set_branch_reference(referenced_branch)
443
except errors.IncompatibleFormat:
444
# this is ok too, not all formats have to support references.
445
raise TestNotApplicable("control directory does not "
446
"support branch references")
448
referenced_branch.bzrdir.root_transport.abspath('') + '/',
449
dir.get_branch_reference())
451
def test_set_branch_reference_on_existing_reference(self):
452
"""set_branch_reference creates a branch reference"""
453
referenced_branch1 = self.make_branch('old-referenced')
454
referenced_branch2 = self.make_branch('new-referenced')
455
dir = self.make_bzrdir('source')
457
reference = dir.set_branch_reference(referenced_branch1)
458
except errors.IncompatibleFormat:
459
# this is ok too, not all formats have to support references.
460
raise TestNotApplicable("control directory does not "
461
"support branch references")
462
reference = dir.set_branch_reference(referenced_branch2)
464
referenced_branch2.bzrdir.root_transport.abspath('') + '/',
465
dir.get_branch_reference())
467
def test_set_branch_reference_on_existing_branch(self):
468
"""set_branch_reference creates a branch reference"""
469
referenced_branch = self.make_branch('referenced')
470
dir = self.make_branch('source').bzrdir
472
reference = dir.set_branch_reference(referenced_branch)
473
except errors.IncompatibleFormat:
474
# this is ok too, not all formats have to support references.
475
raise TestNotApplicable("control directory does not "
476
"support branch references")
478
referenced_branch.bzrdir.root_transport.abspath('') + '/',
479
dir.get_branch_reference())
677
481
def test_get_branch_reference_on_reference(self):
678
482
"""get_branch_reference should return the right url."""
679
483
referenced_branch = self.make_branch('referenced')
680
484
dir = self.make_bzrdir('source')
682
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
683
target_branch=referenced_branch)
486
dir.set_branch_reference(referenced_branch)
684
487
except errors.IncompatibleFormat:
685
488
# this is ok too, not all formats have to support references.
489
raise TestNotApplicable("control directory does not "
490
"support branch references")
687
491
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
688
492
dir.get_branch_reference())
734
540
self.make_repository('target', shared=True)
735
541
except errors.IncompatibleFormat:
542
raise TestNotApplicable("format does not support shared "
737
544
target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
738
545
target.open_repository()
739
546
target.open_branch()
740
547
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
549
def test_sprout_bzrdir_with_repository_to_shared(self):
784
550
tree = self.make_branch_and_tree('commit_tree')
785
551
self.build_tree(['commit_tree/foo'])
787
553
tree.commit('revision 1', rev_id='1')
788
tree.bzrdir.open_branch().set_revision_history([])
554
tree.bzrdir.open_branch().generate_revision_history(
555
_mod_revision.NULL_REVISION)
789
556
tree.set_parent_trees([])
790
557
tree.commit('revision 2', rev_id='2')
791
558
source = self.make_repository('source')
795
562
shared_repo = self.make_repository('target', shared=True)
796
563
except errors.IncompatibleFormat:
564
raise TestNotApplicable("format does not support "
565
"shared repositories")
798
566
target = dir.sprout(self.get_url('target/child'))
799
self.assertNotEqual(dir.transport.base, target.transport.base)
567
self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
800
568
self.assertTrue(shared_repo.has_revision('1'))
802
570
def test_sprout_bzrdir_repository_branch_both_under_shared(self):
804
572
shared_repo = self.make_repository('shared', shared=True)
805
573
except errors.IncompatibleFormat:
574
raise TestNotApplicable("format does not support shared "
576
if not shared_repo._format.supports_nesting_repositories:
577
raise TestNotApplicable("format does not support nesting "
807
579
tree = self.make_branch_and_tree('commit_tree')
808
580
self.build_tree(['commit_tree/foo'])
810
582
tree.commit('revision 1', rev_id='1')
811
tree.bzrdir.open_branch().set_revision_history([])
583
tree.bzrdir.open_branch().generate_revision_history(
584
_mod_revision.NULL_REVISION)
812
585
tree.set_parent_trees([])
813
586
tree.commit('revision 2', rev_id='2')
814
587
tree.branch.repository.copy_content_into(shared_repo)
884
670
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
885
671
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
673
def test_sprout_bzrdir_branch_and_repo_shared(self):
916
674
# sprouting a branch with a repo into a shared repo uses the shared
1036
796
target = dir.sprout(self.get_url('target'), revision_id='1')
1037
797
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())
799
def test_sprout_bzrdir_branch_with_tags(self):
800
# when sprouting a branch all revisions named in the tags are copied
802
builder = self.make_branch_builder('source')
803
source = fixtures.build_branch_with_non_ancestral_rev(builder)
805
source.tags.set_tag('tag-a', 'rev-2')
806
except errors.TagsNotSupported:
807
raise TestNotApplicable('Branch format does not support tags.')
808
source.get_config_stack().set('branch.fetch_tags', True)
809
# Now source has a tag not in its ancestry. Sprout its controldir.
811
target = dir.sprout(self.get_url('target'))
812
# The tag is present, and so is its revision.
813
new_branch = target.open_branch()
814
self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
815
new_branch.repository.get_revision('rev-2')
817
def test_sprout_bzrdir_branch_with_absent_tag(self):
818
# tags referencing absent revisions are copied (and those absent
819
# revisions do not prevent the sprout.)
820
builder = self.make_branch_builder('source')
821
builder.build_commit(message="Rev 1", rev_id='rev-1')
822
source = builder.get_branch()
824
source.tags.set_tag('tag-a', 'missing-rev')
825
except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
826
raise TestNotApplicable('Branch format does not support tags '
827
'or tags referencing ghost revisions.')
828
# Now source has a tag pointing to an absent revision. Sprout its
831
target = dir.sprout(self.get_url('target'))
832
# The tag is present in the target
833
new_branch = target.open_branch()
834
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
836
def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
837
# tags referencing absent revisions are copied (and those absent
838
# revisions do not prevent the sprout.)
839
builder = self.make_branch_builder('source')
840
builder.build_commit(message="Rev 1", rev_id='rev-1')
841
source = builder.get_branch()
843
source.tags.set_tag('tag-a', 'missing-rev')
844
except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
845
raise TestNotApplicable('Branch format does not support tags '
846
'or tags referencing missing revisions.')
847
# Now source has a tag pointing to an absent revision. Sprout its
850
target = dir.sprout(self.get_url('target'), source_branch=source)
851
# The tag is present in the target
852
new_branch = target.open_branch()
853
self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
855
def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
856
# dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
857
# the branch at that bzrdir, the ancestry of all of those, but no other
858
# revs (not even the tip of the source branch).
859
builder = self.make_branch_builder('source')
860
builder.build_commit(message="Base", rev_id='base-rev')
861
# Make three parallel lines of ancestry off this base.
862
source = builder.get_branch()
863
builder.build_commit(message="Rev A1", rev_id='rev-a1')
864
builder.build_commit(message="Rev A2", rev_id='rev-a2')
865
builder.build_commit(message="Rev A3", rev_id='rev-a3')
866
source.set_last_revision_info(1, 'base-rev')
867
builder.build_commit(message="Rev B1", rev_id='rev-b1')
868
builder.build_commit(message="Rev B2", rev_id='rev-b2')
869
builder.build_commit(message="Rev B3", rev_id='rev-b3')
870
source.set_last_revision_info(1, 'base-rev')
871
builder.build_commit(message="Rev C1", rev_id='rev-c1')
872
builder.build_commit(message="Rev C2", rev_id='rev-c2')
873
builder.build_commit(message="Rev C3", rev_id='rev-c3')
874
# Set the branch tip to A2
875
source.set_last_revision_info(3, 'rev-a2')
877
# Create a tag for B2, and for an absent rev
878
source.tags.set_tag('tag-non-ancestry', 'rev-b2')
879
except errors.TagsNotSupported:
880
raise TestNotApplicable('Branch format does not support tags ')
882
source.tags.set_tag('tag-absent', 'absent-rev')
883
except errors.GhostTagsNotSupported:
884
has_ghost_tag = False
887
source.get_config_stack().set('branch.fetch_tags', True)
888
# And ask sprout for C2
890
target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
891
# The tags are present
892
new_branch = target.open_branch()
895
{'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
896
new_branch.tags.get_tag_dict())
899
{'tag-non-ancestry': 'rev-b2'},
900
new_branch.tags.get_tag_dict())
901
# And the revs for A2, B2 and C2's ancestries are present, but no
904
['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
905
sorted(new_branch.repository.all_revision_ids()))
1062
907
def test_sprout_bzrdir_tree_branch_reference(self):
1063
908
# sprouting should create a repository if needed and a sprouted branch.
1183
1027
def test_format_initialize_find_open(self):
1184
1028
# loopback test to check the current format initializes to itself.
1185
if not self.bzrdir_format.is_supported():
1029
if not self.bzrdir_format.is_initializable():
1186
1030
# unsupported formats are not loopback testable
1187
1031
# because the default open will not open them and
1188
1032
# they may not be initializable.
1033
raise TestNotApplicable("format is not initializable")
1190
1034
# for remote formats, there must be no prior assumption about the
1191
1035
# network name to use - it's possible that this may somehow have got
1192
1036
# in through an unisolated test though - see
1193
1037
# <https://bugs.launchpad.net/bzr/+bug/504102>
1194
self.assertEquals(getattr(self.bzrdir_format,
1038
self.assertEqual(getattr(self.bzrdir_format,
1195
1039
'_network_name', None),
1197
1041
# supported formats must be able to init and open
1198
t = transport.get_transport(self.get_url())
1199
readonly_t = transport.get_transport(self.get_readonly_url())
1042
t = self.get_transport()
1043
readonly_t = self.get_readonly_transport()
1200
1044
made_control = self.bzrdir_format.initialize(t.base)
1201
self.failUnless(isinstance(made_control, controldir.ControlDir))
1045
self.assertIsInstance(made_control, controldir.ControlDir)
1046
if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
1202
1048
self.assertEqual(self.bzrdir_format,
1203
1049
controldir.ControlDirFormat.find_format(readonly_t))
1204
1050
direct_opened_dir = self.bzrdir_format.open(readonly_t)
1205
opened_dir = bzrdir.BzrDir.open(t.base)
1051
opened_dir = controldir.ControlDir.open(t.base)
1206
1052
self.assertEqual(made_control._format,
1207
1053
opened_dir._format)
1208
1054
self.assertEqual(direct_opened_dir._format,
1209
1055
opened_dir._format)
1210
self.failUnless(isinstance(opened_dir, controldir.ControlDir))
1056
self.assertIsInstance(opened_dir, controldir.ControlDir)
1212
1058
def test_format_initialize_on_transport_ex(self):
1213
1059
t = self.get_transport('dir')
1233
1078
self.assertInitializeEx(t, create_prefix=True)
1235
1080
def test_format_initialize_on_transport_ex_create_prefix_False(self):
1236
if not self.bzrdir_format.is_supported():
1237
# Not initializable - not a failure either.
1081
if not self.bzrdir_format.is_initializable():
1082
raise TestNotApplicable("format is not initializable")
1239
1083
t = self.get_transport('missing/dir')
1240
1084
self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1241
1085
create_prefix=False)
1243
1087
def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1244
1088
t = self.get_transport('repo')
1245
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1089
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1246
1090
repo_name = repo_fmt.repository_format.network_name()
1247
1091
repo = repo_fmt.initialize_on_transport_ex(t,
1248
1092
repo_format_name=repo_name, shared_repo=True)[0]
1249
1093
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1250
1094
force_new_repo=True, repo_format_name=repo_name)
1252
# uninitialisable format
1254
1095
self.assertNotEqual(repo.bzrdir.root_transport.base,
1255
1096
made_repo.bzrdir.root_transport.base)
1257
1098
def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1258
1099
t = self.get_transport('repo')
1259
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1100
repo_fmt = controldir.format_registry.make_bzrdir('1.9')
1260
1101
repo_name = repo_fmt.repository_format.network_name()
1261
1102
repo = repo_fmt.initialize_on_transport_ex(t,
1262
1103
repo_format_name=repo_name, shared_repo=True)[0]
1263
1104
made_repo, control = self.assertInitializeEx(t.clone('branch'),
1264
1105
force_new_repo=False, repo_format_name=repo_name)
1266
# uninitialisable format
1268
if not isinstance(control._format, (bzrdir.BzrDirFormat5,
1269
bzrdir.BzrDirFormat6,)):
1106
if not control._format.fixed_components:
1270
1107
self.assertEqual(repo.bzrdir.root_transport.base,
1271
1108
made_repo.bzrdir.root_transport.base)
1273
def test_format_initialize_on_transport_ex_stacked_on(self):
1274
# trunk is a stackable format. Note that its in the same server area
1275
# which is what launchpad does, but not sufficient to exercise the
1277
trunk = self.make_branch('trunk', format='1.9')
1278
t = self.get_transport('stacked')
1279
old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
1280
repo_name = old_fmt.repository_format.network_name()
1281
# Should end up with a 1.9 format (stackable)
1282
repo, control = self.assertInitializeEx(t, need_meta=True,
1283
repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
1285
# uninitialisable format
1287
self.assertLength(1, repo._fallback_repositories)
1289
def test_format_initialize_on_transport_ex_default_stack_on(self):
1290
# When initialize_on_transport_ex uses a stacked-on branch because of
1291
# a stacking policy on the target, the location of the fallback
1292
# repository is the same as the external location of the stacked-on
1294
balloon = self.make_bzrdir('balloon')
1295
if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
1296
stack_on = self.make_branch('stack-on', format='1.9')
1298
stack_on = self.make_branch('stack-on')
1299
config = self.make_bzrdir('.').get_config()
1301
config.set_default_stack_on('stack-on')
1302
except errors.BzrError:
1303
raise TestNotApplicable('Only relevant for stackable formats.')
1304
# Initialize a bzrdir subject to the policy.
1305
t = self.get_transport('stacked')
1306
repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1307
repo_name = repo_fmt.repository_format.network_name()
1308
repo, control = self.assertInitializeEx(
1309
t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1310
# self.addCleanup(repo.unlock)
1312
# uninitialisable format
1314
# There's one fallback repo, with a public location.
1315
self.assertLength(1, repo._fallback_repositories)
1316
fallback_repo = repo._fallback_repositories[0]
1318
stack_on.base, fallback_repo.bzrdir.root_transport.base)
1319
# The bzrdir creates a branch in stacking-capable format.
1320
new_branch = control.create_branch()
1321
self.assertTrue(new_branch._format.supports_stacking())
1323
1110
def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1324
1111
t = self.get_transport('dir')
1325
1112
repo, control = self.assertInitializeEx(t)
1351
1134
initialize_on_transport_ex.
1352
1135
:return: the resulting repo, control dir tuple.
1354
if not self.bzrdir_format.is_supported():
1355
# Not initializable - not a failure either.
1137
if not self.bzrdir_format.is_initializable():
1138
raise TestNotApplicable("control dir format is not "
1357
1140
repo, control, require_stacking, repo_policy = \
1358
1141
self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1359
1142
if repo is not None:
1360
1143
# Repositories are open write-locked
1361
1144
self.assertTrue(repo.is_write_locked())
1362
1145
self.addCleanup(repo.unlock)
1363
self.assertIsInstance(control, bzrdir.BzrDir)
1364
opened = bzrdir.BzrDir.open(t.base)
1146
self.assertIsInstance(control, controldir.ControlDir)
1147
opened = controldir.ControlDir.open(t.base)
1365
1148
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()
1149
if not isinstance(expected_format, RemoteBzrDirFormat):
1376
1150
self.assertEqual(control._format.network_name(),
1377
1151
expected_format.network_name())
1378
1152
self.assertEqual(control._format.network_name(),
1389
1163
# key in the registry gives back the same format. For remote obects
1390
1164
# we check that the network_name of the RemoteBzrDirFormat we have
1391
1165
# locally matches the actual format present on disk.
1392
if isinstance(format, bzrdir.RemoteBzrDirFormat):
1166
if isinstance(format, RemoteBzrDirFormat):
1393
1167
dir._ensure_real()
1394
1168
real_dir = dir._real_bzrdir
1395
1169
network_name = format.network_name()
1396
1170
self.assertEqual(real_dir._format.network_name(), network_name)
1398
registry = bzrdir.network_format_registry
1172
registry = controldir.network_format_registry
1399
1173
network_name = format.network_name()
1400
1174
looked_up_format = registry.get(network_name)
1401
self.assertEqual(format.__class__, looked_up_format.__class__)
1176
issubclass(format.__class__, looked_up_format.__class__))
1402
1177
# The network name must be a byte string.
1403
1178
self.assertIsInstance(network_name, str)
1405
1180
def test_open_not_bzrdir(self):
1406
1181
# test the formats specific behaviour for no-content or similar dirs.
1407
self.assertRaises(NotBranchError,
1182
self.assertRaises(errors.NotBranchError,
1408
1183
self.bzrdir_format.open,
1409
transport.get_transport(self.get_readonly_url()))
1184
transport.get_transport_from_url(self.get_readonly_url()))
1411
1186
def test_create_branch(self):
1412
1187
# a bzrdir can construct a branch and repository for itself.
1413
if not self.bzrdir_format.is_supported():
1188
if not self.bzrdir_format.is_initializable():
1414
1189
# unsupported formats are not loopback testable
1415
1190
# because the default open will not open them and
1416
1191
# they may not be initializable.
1418
t = transport.get_transport(self.get_url())
1192
raise TestNotApplicable("format is not initializable")
1193
t = self.get_transport()
1419
1194
made_control = self.bzrdir_format.initialize(t.base)
1420
1195
made_repo = made_control.create_repository()
1421
1196
made_branch = made_control.create_branch()
1422
self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1197
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1198
self.assertEqual(made_control, made_branch.bzrdir)
1200
def test_create_branch_append_revisions_only(self):
1201
# a bzrdir can construct a branch and repository for itself.
1202
if not self.bzrdir_format.is_initializable():
1203
# unsupported formats are not loopback testable
1204
# because the default open will not open them and
1205
# they may not be initializable.
1206
raise TestNotApplicable("format is not initializable")
1207
t = self.get_transport()
1208
made_control = self.bzrdir_format.initialize(t.base)
1209
made_repo = made_control.create_repository()
1211
made_branch = made_control.create_branch(
1212
append_revisions_only=True)
1213
except errors.UpgradeRequired:
1214
raise TestNotApplicable("format does not support "
1215
"append_revisions_only setting")
1216
self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1217
self.assertEqual(True, made_branch.get_append_revisions_only())
1423
1218
self.assertEqual(made_control, made_branch.bzrdir)
1425
1220
def test_open_branch(self):
1426
if not self.bzrdir_format.is_supported():
1221
if not self.bzrdir_format.is_initializable():
1427
1222
# unsupported formats are not loopback testable
1428
1223
# because the default open will not open them and
1429
1224
# they may not be initializable.
1431
t = transport.get_transport(self.get_url())
1225
raise TestNotApplicable("format is not initializable")
1226
t = self.get_transport()
1432
1227
made_control = self.bzrdir_format.initialize(t.base)
1433
1228
made_repo = made_control.create_repository()
1434
1229
made_branch = made_control.create_branch()
1435
1230
opened_branch = made_control.open_branch()
1436
1231
self.assertEqual(made_control, opened_branch.bzrdir)
1437
self.failUnless(isinstance(opened_branch, made_branch.__class__))
1438
self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1232
self.assertIsInstance(opened_branch, made_branch.__class__)
1233
self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1440
1235
def test_list_branches(self):
1441
if not self.bzrdir_format.is_supported():
1442
# unsupported formats are not loopback testable
1443
# because the default open will not open them and
1444
# they may not be initializable.
1446
t = transport.get_transport(self.get_url())
1236
if not self.bzrdir_format.is_initializable():
1237
raise TestNotApplicable("format is not initializable")
1238
t = self.get_transport()
1447
1239
made_control = self.bzrdir_format.initialize(t.base)
1448
1240
made_repo = made_control.create_repository()
1449
1241
made_branch = made_control.create_branch()
1450
1242
branches = made_control.list_branches()
1451
self.assertEquals(1, len(branches))
1452
self.assertEquals(made_branch.base, branches[0].base)
1243
self.assertEqual(1, len(branches))
1244
self.assertEqual(made_branch.base, branches[0].base)
1454
1246
made_control.destroy_branch()
1455
1247
except errors.UnsupportedOperation:
1456
1248
pass # Not all bzrdirs support destroying directories
1458
self.assertEquals([], made_control.list_branches())
1250
self.assertEqual([], made_control.list_branches())
1252
def test_get_branches(self):
1253
repo = self.make_repository('branch-1')
1254
target_branch = repo.bzrdir.create_branch()
1255
self.assertEqual([""], repo.bzrdir.get_branches().keys())
1460
1257
def test_create_repository(self):
1461
1258
# a bzrdir can construct a repository for itself.
1462
if not self.bzrdir_format.is_supported():
1259
if not self.bzrdir_format.is_initializable():
1463
1260
# unsupported formats are not loopback testable
1464
1261
# because the default open will not open them and
1465
1262
# they may not be initializable.
1467
t = transport.get_transport(self.get_url())
1263
raise TestNotApplicable("format is not initializable")
1264
t = self.get_transport()
1468
1265
made_control = self.bzrdir_format.initialize(t.base)
1469
1266
made_repo = made_control.create_repository()
1470
1267
# Check that we have a repository object.
1474
1271
def test_create_repository_shared(self):
1475
1272
# a bzrdir can create a shared repository or
1476
1273
# fail appropriately
1477
if not self.bzrdir_format.is_supported():
1274
if not self.bzrdir_format.is_initializable():
1478
1275
# unsupported formats are not loopback testable
1479
1276
# because the default open will not open them and
1480
1277
# they may not be initializable.
1482
t = transport.get_transport(self.get_url())
1278
raise TestNotApplicable("format is not initializable")
1279
t = self.get_transport()
1483
1280
made_control = self.bzrdir_format.initialize(t.base)
1485
1282
made_repo = made_control.create_repository(shared=True)
1486
1283
except errors.IncompatibleFormat:
1487
1284
# Old bzrdir formats don't support shared repositories
1488
1285
# and should raise IncompatibleFormat
1286
raise TestNotApplicable("format does not support shared "
1490
1288
self.assertTrue(made_repo.is_shared())
1492
1290
def test_create_repository_nonshared(self):
1493
1291
# a bzrdir can create a non-shared repository
1494
if not self.bzrdir_format.is_supported():
1292
if not self.bzrdir_format.is_initializable():
1495
1293
# unsupported formats are not loopback testable
1496
1294
# because the default open will not open them and
1497
1295
# they may not be initializable.
1499
t = transport.get_transport(self.get_url())
1296
raise TestNotApplicable("format is not initializable")
1297
t = self.get_transport()
1500
1298
made_control = self.bzrdir_format.initialize(t.base)
1501
made_repo = made_control.create_repository(shared=False)
1300
made_repo = made_control.create_repository(shared=False)
1301
except errors.IncompatibleFormat:
1302
# Some control dir formats don't support non-shared repositories
1303
# and should raise IncompatibleFormat
1304
raise TestNotApplicable("format does not support shared "
1502
1306
self.assertFalse(made_repo.is_shared())
1504
1308
def test_open_repository(self):
1505
if not self.bzrdir_format.is_supported():
1309
if not self.bzrdir_format.is_initializable():
1506
1310
# unsupported formats are not loopback testable
1507
1311
# because the default open will not open them and
1508
1312
# they may not be initializable.
1510
t = transport.get_transport(self.get_url())
1313
raise TestNotApplicable("format is not initializable")
1314
t = self.get_transport()
1511
1315
made_control = self.bzrdir_format.initialize(t.base)
1512
1316
made_repo = made_control.create_repository()
1513
1317
opened_repo = made_control.open_repository()
1514
1318
self.assertEqual(made_control, opened_repo.bzrdir)
1515
self.failUnless(isinstance(opened_repo, made_repo.__class__))
1516
self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1319
self.assertIsInstance(opened_repo, made_repo.__class__)
1320
self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1518
1322
def test_create_workingtree(self):
1519
1323
# a bzrdir can construct a working tree for itself.
1520
if not self.bzrdir_format.is_supported():
1324
if not self.bzrdir_format.is_initializable():
1521
1325
# unsupported formats are not loopback testable
1522
1326
# because the default open will not open them and
1523
1327
# they may not be initializable.
1328
raise TestNotApplicable("format is not initializable")
1525
1329
t = self.get_transport()
1526
1330
made_control = self.bzrdir_format.initialize(t.base)
1527
1331
made_repo = made_control.create_repository()
1528
1332
made_branch = made_control.create_branch()
1529
1333
made_tree = self.createWorkingTreeOrSkip(made_control)
1530
self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1334
self.assertIsInstance(made_tree, workingtree.WorkingTree)
1531
1335
self.assertEqual(made_control, made_tree.bzrdir)
1533
1337
def test_create_workingtree_revision(self):
1534
1338
# a bzrdir can construct a working tree for itself @ a specific revision.
1339
if not self.bzrdir_format.is_initializable():
1340
raise TestNotApplicable("format is not initializable")
1535
1341
t = self.get_transport()
1536
1342
source = self.make_branch_and_tree('source')
1537
1343
source.commit('a', rev_id='a', allow_pointless=True)
1561
1364
made_repo = made_control.create_repository()
1562
1365
made_branch = made_control.create_branch()
1563
1366
made_tree = made_control.create_workingtree()
1564
except errors.NotLocalUrl:
1367
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1565
1368
raise TestSkipped("Can't initialize %r on transport %r"
1566
1369
% (self.bzrdir_format, t))
1567
1370
opened_tree = made_control.open_workingtree()
1568
1371
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('.')
1372
self.assertIsInstance(opened_tree, made_tree.__class__)
1373
self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1375
def test_get_selected_branch(self):
1376
# The segment parameters are accessible from the root transport
1377
# if a URL with segment parameters is opened.
1378
if not self.bzrdir_format.is_initializable():
1379
raise TestNotApplicable("format is not initializable")
1380
t = self.get_transport()
1382
made_control = self.bzrdir_format.initialize(t.base)
1383
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1384
raise TestSkipped("Can't initialize %r on transport %r"
1385
% (self.bzrdir_format, t))
1386
dir = controldir.ControlDir.open(t.base+",branch=foo")
1387
self.assertEqual({"branch": "foo"},
1388
dir.user_transport.get_segment_parameters())
1389
self.assertEqual("foo", dir._get_selected_branch())
1391
def test_get_selected_branch_none_selected(self):
1392
# _get_selected_branch defaults to None
1393
if not self.bzrdir_format.is_initializable():
1394
raise TestNotApplicable("format is not initializable")
1395
t = self.get_transport()
1397
made_control = self.bzrdir_format.initialize(t.base)
1398
except (errors.NotLocalUrl, errors.UnsupportedOperation):
1399
raise TestSkipped("Can't initialize %r on transport %r"
1400
% (self.bzrdir_format, t))
1401
dir = controldir.ControlDir.open(t.base)
1402
self.assertEqual(u"", dir._get_selected_branch())
1635
1404
def test_root_transport(self):
1636
1405
dir = self.make_bzrdir('.')
1637
1406
self.assertEqual(dir.root_transport.base,
1638
transport.get_transport(self.get_url('.')).base)
1407
self.get_transport().base)
1640
1409
def test_find_repository_no_repo_under_standalone_branch(self):
1641
1410
# finding a repo stops at standalone branches even if there is a
1767
1557
old_url, new_url = tree.bzrdir.backup_bzrdir()
1768
1558
old_path = urlutils.local_path_from_url(old_url)
1769
1559
new_path = urlutils.local_path_from_url(new_url)
1770
self.failUnlessExists(old_path)
1771
self.failUnlessExists(new_path)
1560
self.assertPathExists(old_path)
1561
self.assertPathExists(new_path)
1772
1562
for (((dir_relpath1, _), entries1),
1773
1563
((dir_relpath2, _), entries2)) in izip(
1774
1564
osutils.walkdirs(old_path),
1775
1565
osutils.walkdirs(new_path)):
1776
self.assertEquals(dir_relpath1, dir_relpath2)
1566
self.assertEqual(dir_relpath1, dir_relpath2)
1777
1567
for f1, f2 in zip(entries1, entries2):
1778
self.assertEquals(f1[0], f2[0])
1779
self.assertEquals(f1[2], f2[2])
1568
self.assertEqual(f1[0], f2[0])
1569
self.assertEqual(f1[2], f2[2])
1780
1570
if f1[2] == "file":
1781
1571
osutils.compare_files(open(f1[4]), open(f2[4]))
1802
1592
def test_format_description(self):
1803
1593
dir = self.make_bzrdir('.')
1804
1594
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)
1595
self.assertTrue(len(text))
1829
1598
class TestBreakLock(TestCaseWithControlDir):