51
51
from bzrlib.trace import mutter
52
52
from bzrlib.transport import get_transport
53
53
from bzrlib.upgrade import upgrade
54
from bzrlib.remote import RemoteBzrDir
54
55
from bzrlib.repofmt import weaverepo
231
232
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
233
234
def test_clone_bzrdir_repository_branch_both_under_shared(self):
235
# Create a shared repository
235
237
shared_repo = self.make_repository('shared', shared=True)
236
238
except errors.IncompatibleFormat:
240
# Make a branch, 'commit_tree', and working tree outside of the shared
241
# repository, and commit some revisions to it.
238
242
tree = self.make_branch_and_tree('commit_tree')
239
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
243
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
241
245
tree.commit('revision 1', rev_id='1')
242
246
tree.bzrdir.open_branch().set_revision_history([])
243
247
tree.set_parent_trees([])
244
248
tree.commit('revision 2', rev_id='2')
245
tree.bzrdir.open_repository().copy_content_into(shared_repo)
249
# Copy the content (i.e. revisions) from the 'commit_tree' branch's
250
# repository into the shared repository.
251
tree.branch.repository.copy_content_into(shared_repo)
252
# Make a branch 'source' inside the shared repository.
246
253
dir = self.make_bzrdir('shared/source')
247
254
dir.create_branch()
255
# Clone 'source' to 'target', also inside the shared repository.
248
256
target = dir.clone(self.get_url('shared/target'))
257
# 'source', 'target', and the shared repo all have distinct bzrdirs.
249
258
self.assertNotEqual(dir.transport.base, target.transport.base)
250
259
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
260
# The shared repository will contain revisions from the 'commit_tree'
261
# repository, even revisions that are not part of the history of the
262
# 'commit_tree' branch.
251
263
self.assertTrue(shared_repo.has_revision('1'))
253
265
def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
256
268
except errors.IncompatibleFormat:
258
270
tree = self.make_branch_and_tree('commit_tree')
259
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
271
self.build_tree(['commit_tree/foo'])
261
273
tree.commit('revision 1', rev_id='1')
262
tree.bzrdir.open_branch().set_revision_history([])
274
tree.branch.bzrdir.open_branch().set_revision_history([])
263
275
tree.set_parent_trees([])
264
276
tree.commit('revision 2', rev_id='2')
265
tree.bzrdir.open_repository().copy_content_into(shared_repo)
266
shared_repo.set_make_working_trees(False)
267
self.assertFalse(shared_repo.make_working_trees())
277
tree.branch.repository.copy_content_into(shared_repo)
278
if shared_repo.make_working_trees():
279
shared_repo.set_make_working_trees(False)
280
self.assertFalse(shared_repo.make_working_trees())
268
281
self.assertTrue(shared_repo.has_revision('1'))
269
282
dir = self.make_bzrdir('shared/source')
270
283
dir.create_branch()
279
292
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
280
293
tree = self.make_branch_and_tree('commit_tree')
281
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
294
self.build_tree(['commit_tree/foo'])
283
296
tree.commit('revision 1', rev_id='1')
284
297
dir = self.make_bzrdir('source')
301
314
# and clone it with a revision limit.
303
316
tree = self.make_branch_and_tree('commit_tree')
304
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
317
self.build_tree(['commit_tree/foo'])
306
319
tree.commit('revision 1', rev_id='1')
307
tree.bzrdir.open_branch().set_revision_history([])
320
tree.branch.bzrdir.open_branch().set_revision_history([])
308
321
tree.set_parent_trees([])
309
322
tree.commit('revision 2', rev_id='2')
310
323
source = self.make_repository('source')
311
tree.bzrdir.open_repository().copy_content_into(source)
324
tree.branch.repository.copy_content_into(source)
312
325
dir = source.bzrdir
313
326
target = dir.clone(self.get_url('target'), revision_id='2')
314
327
raise TestSkipped('revision limiting not strict yet')
316
329
def test_clone_bzrdir_branch_and_repo(self):
317
330
tree = self.make_branch_and_tree('commit_tree')
318
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
331
self.build_tree(['commit_tree/foo'])
320
333
tree.commit('revision 1')
321
334
source = self.make_branch('source')
336
349
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
337
350
# by default cloning into a shared repo uses the shared repo.
338
351
tree = self.make_branch_and_tree('commit_tree')
339
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
352
self.build_tree(['commit_tree/foo'])
341
354
tree.commit('revision 1')
342
355
source = self.make_branch('source')
356
369
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
357
370
# by default cloning into a shared repo uses the shared repo.
358
371
tree = self.make_branch_and_tree('commit_tree')
359
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
372
self.build_tree(['commit_tree/foo'])
361
374
tree.commit('revision 1')
362
375
source = self.make_branch('source')
396
409
# and clone it with a revision limit.
398
411
tree = self.make_branch_and_tree('commit_tree')
399
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
412
self.build_tree(['commit_tree/foo'])
401
414
tree.commit('revision 1', rev_id='1')
402
415
tree.commit('revision 2', rev_id='2', allow_pointless=True)
408
421
self.assertEqual('1', target.open_branch().last_revision())
410
423
def test_clone_bzrdir_tree_branch_repo(self):
411
tree = self.make_branch_and_tree('sourcce')
412
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
424
tree = self.make_branch_and_tree('source')
425
self.build_tree(['source/foo'])
414
427
tree.commit('revision 1')
415
428
dir = tree.bzrdir
428
441
target.open_workingtree().revert([])
430
443
def test_revert_inventory(self):
431
tree = self.make_branch_and_tree('sourcce')
432
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
444
tree = self.make_branch_and_tree('source')
445
self.build_tree(['source/foo'])
434
447
tree.commit('revision 1')
435
448
dir = tree.bzrdir
484
497
# This smoke test just checks the revision-id is right. Tree specific
485
498
# tests will check corner cases.
486
499
tree = self.make_branch_and_tree('source')
487
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
500
self.build_tree(['source/foo'])
489
502
tree.commit('revision 1', rev_id='1')
490
503
tree.commit('revision 2', rev_id='2', allow_pointless=True)
493
506
self.skipIfNoWorkingTree(target)
494
507
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
509
def test_get_branch_reference_on_reference(self):
510
"""get_branch_reference should return the right url."""
511
referenced_branch = self.make_branch('referenced')
512
dir = self.make_bzrdir('source')
514
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
516
except errors.IncompatibleFormat:
517
# this is ok too, not all formats have to support references.
519
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
520
dir.get_branch_reference())
522
def test_get_branch_reference_on_non_reference(self):
523
"""get_branch_reference should return None for non-reference branches."""
524
branch = self.make_branch('referenced')
525
self.assertEqual(None, branch.bzrdir.get_branch_reference())
527
def test_get_branch_reference_no_branch(self):
528
"""get_branch_reference should not mask NotBranchErrors."""
529
dir = self.make_bzrdir('source')
531
# this format does not support branchless bzrdirs.
533
self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
496
535
def test_sprout_bzrdir_empty(self):
497
536
dir = self.make_bzrdir('source')
498
537
target = self.sproutOrSkip(dir, self.get_url('target'))
512
551
target = self.sproutOrSkip(dir, self.get_url('target/child'))
513
552
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
514
553
target.open_branch()
515
target.open_workingtree()
555
target.open_workingtree()
556
except errors.NotLocalUrl:
557
# bzrdir's that test against non-local urls are allowed to pass:
558
# whitelist them for now
559
self.assertIsInstance(target, RemoteBzrDir)
517
561
def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
518
562
# the force_new_repo parameter should force use of a new repo in an empty
567
611
def test_sprout_bzrdir_with_repository_to_shared(self):
568
612
tree = self.make_branch_and_tree('commit_tree')
569
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
613
self.build_tree(['commit_tree/foo'])
571
615
tree.commit('revision 1', rev_id='1')
572
616
tree.bzrdir.open_branch().set_revision_history([])
573
617
tree.set_parent_trees([])
574
618
tree.commit('revision 2', rev_id='2')
575
619
source = self.make_repository('source')
576
tree.bzrdir.open_repository().copy_content_into(source)
620
tree.branch.repository.copy_content_into(source)
577
621
dir = source.bzrdir
579
623
shared_repo = self.make_repository('target', shared=True)
589
633
except errors.IncompatibleFormat:
591
635
tree = self.make_branch_and_tree('commit_tree')
592
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
636
self.build_tree(['commit_tree/foo'])
594
638
tree.commit('revision 1', rev_id='1')
595
639
tree.bzrdir.open_branch().set_revision_history([])
596
640
tree.set_parent_trees([])
597
641
tree.commit('revision 2', rev_id='2')
598
tree.bzrdir.open_repository().copy_content_into(shared_repo)
642
tree.branch.repository.copy_content_into(shared_repo)
599
643
dir = self.make_bzrdir('shared/source')
600
644
dir.create_branch()
601
645
target = self.sproutOrSkip(dir, self.get_url('shared/target'))
609
653
except errors.IncompatibleFormat:
611
655
tree = self.make_branch_and_tree('commit_tree')
612
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
656
self.build_tree(['commit_tree/foo'])
614
658
tree.commit('revision 1', rev_id='1')
615
659
tree.bzrdir.open_branch().set_revision_history([])
616
660
tree.set_parent_trees([])
617
661
tree.commit('revision 2', rev_id='2')
618
tree.bzrdir.open_repository().copy_content_into(shared_repo)
619
shared_repo.set_make_working_trees(False)
620
self.assertFalse(shared_repo.make_working_trees())
662
tree.branch.repository.copy_content_into(shared_repo)
663
if shared_repo.make_working_trees():
664
shared_repo.set_make_working_trees(False)
665
self.assertFalse(shared_repo.make_working_trees())
621
666
self.assertTrue(shared_repo.has_revision('1'))
622
667
dir = self.make_bzrdir('shared/source')
623
668
dir.create_branch()
626
671
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
627
672
branch = target.open_branch()
628
673
self.assertTrue(branch.repository.has_revision('1'))
629
self.assertTrue(branch.repository.make_working_trees())
674
if not isinstance(branch.bzrdir, RemoteBzrDir):
675
self.assertTrue(branch.repository.make_working_trees())
630
676
self.assertFalse(branch.repository.is_shared())
632
678
def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
633
679
tree = self.make_branch_and_tree('commit_tree')
634
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
680
self.build_tree(['commit_tree/foo'])
636
682
tree.commit('revision 1', rev_id='1')
637
683
tree.bzrdir.open_branch().set_revision_history([])
638
684
tree.set_parent_trees([])
639
685
tree.commit('revision 2', rev_id='2')
640
686
source = self.make_repository('source')
641
tree.bzrdir.open_repository().copy_content_into(source)
687
tree.branch.repository.copy_content_into(source)
642
688
dir = source.bzrdir
644
690
shared_repo = self.make_repository('target', shared=True)
655
701
# and sprout it with a revision limit.
657
703
tree = self.make_branch_and_tree('commit_tree')
658
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
704
self.build_tree(['commit_tree/foo'])
660
706
tree.commit('revision 1', rev_id='1')
661
707
tree.bzrdir.open_branch().set_revision_history([])
662
708
tree.set_parent_trees([])
663
709
tree.commit('revision 2', rev_id='2')
664
710
source = self.make_repository('source')
665
tree.bzrdir.open_repository().copy_content_into(source)
711
tree.branch.repository.copy_content_into(source)
666
712
dir = source.bzrdir
667
713
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
668
714
raise TestSkipped('revision limiting not strict yet')
670
716
def test_sprout_bzrdir_branch_and_repo(self):
671
717
tree = self.make_branch_and_tree('commit_tree')
672
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
718
self.build_tree(['commit_tree/foo'])
674
720
tree.commit('revision 1')
675
721
source = self.make_branch('source')
676
tree.bzrdir.open_repository().copy_content_into(source.repository)
722
tree.branch.repository.copy_content_into(source.repository)
677
723
tree.bzrdir.open_branch().copy_content_into(source)
678
724
dir = source.bzrdir
679
725
target = self.sproutOrSkip(dir, self.get_url('target'))
697
743
# sprouting a branch with a repo into a shared repo uses the shared
699
745
tree = self.make_branch_and_tree('commit_tree')
700
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
746
self.build_tree(['commit_tree/foo'])
702
748
tree.commit('revision 1', rev_id='1')
703
749
source = self.make_branch('source')
704
tree.bzrdir.open_repository().copy_content_into(source.repository)
750
tree.branch.repository.copy_content_into(source.repository)
705
751
tree.bzrdir.open_branch().copy_content_into(source)
706
752
dir = source.bzrdir
715
761
# sprouting a branch with a repo into a shared repo uses the shared
717
763
tree = self.make_branch_and_tree('commit_tree')
718
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
764
self.build_tree(['commit_tree/foo'])
720
766
tree.commit('revision 1', rev_id='1')
721
767
source = self.make_branch('source')
722
tree.bzrdir.open_repository().copy_content_into(source.repository)
768
tree.branch.repository.copy_content_into(source.repository)
723
769
tree.bzrdir.open_branch().copy_content_into(source)
724
770
dir = source.bzrdir
808
854
# and sprout it with a revision limit.
810
856
tree = self.make_branch_and_tree('commit_tree')
811
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
857
self.build_tree(['commit_tree/foo'])
813
859
tree.commit('revision 1', rev_id='1')
814
860
tree.commit('revision 2', rev_id='2', allow_pointless=True)
815
861
source = self.make_branch('source')
816
tree.bzrdir.open_repository().copy_content_into(source.repository)
862
tree.branch.repository.copy_content_into(source.repository)
817
863
tree.bzrdir.open_branch().copy_content_into(source)
818
864
dir = source.bzrdir
819
865
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
820
866
self.assertEqual('1', target.open_branch().last_revision())
822
868
def test_sprout_bzrdir_tree_branch_repo(self):
823
tree = self.make_branch_and_tree('sourcce')
869
tree = self.make_branch_and_tree('source')
824
870
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
826
872
tree.commit('revision 1')
1046
1092
source = self.make_branch_and_tree('source')
1047
1093
source.commit('a', rev_id='a', allow_pointless=True)
1048
1094
source.commit('b', rev_id='b', allow_pointless=True)
1049
self.build_tree(['new/'])
1050
1096
t_new = t.clone('new')
1051
1097
made_control = self.bzrdir_format.initialize_on_transport(t_new)
1052
1098
source.branch.repository.clone(made_control)
1295
1341
def test_retire_bzrdir(self):
1296
1342
bd = self.make_bzrdir('.')
1343
transport = bd.root_transport
1297
1344
# must not overwrite existing directories
1298
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',])
1299
self.failUnlessExists('.bzr')
1345
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1346
transport=transport)
1347
self.failUnless(transport.has('.bzr'))
1300
1348
bd.retire_bzrdir()
1301
self.failIfExists('.bzr')
1302
self.failUnlessExists('.bzr.retired.1')
1349
self.failIf(transport.has('.bzr'))
1350
self.failUnless(transport.has('.bzr.retired.1'))
1304
1352
class TestBreakLock(TestCaseWithBzrDir):