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
243
244
tree.bzrdir.open_branch().set_revision_history([])
244
245
tree.set_parent_trees([])
245
246
tree.commit('revision 2', rev_id='2')
246
tree.bzrdir.open_repository().copy_content_into(shared_repo)
247
tree.branch.bzrdir.open_repository().copy_content_into(shared_repo)
247
248
dir = self.make_bzrdir('shared/source')
248
249
dir.create_branch()
249
250
target = dir.clone(self.get_url('shared/target'))
257
258
except errors.IncompatibleFormat:
259
260
tree = self.make_branch_and_tree('commit_tree')
260
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
261
self.build_tree(['commit_tree/foo'])
262
263
tree.commit('revision 1', rev_id='1')
263
tree.bzrdir.open_branch().set_revision_history([])
264
tree.branch.bzrdir.open_branch().set_revision_history([])
264
265
tree.set_parent_trees([])
265
266
tree.commit('revision 2', rev_id='2')
266
tree.bzrdir.open_repository().copy_content_into(shared_repo)
267
shared_repo.set_make_working_trees(False)
268
self.assertFalse(shared_repo.make_working_trees())
267
tree.branch.bzrdir.open_repository().copy_content_into(shared_repo)
268
if shared_repo.make_working_trees():
269
shared_repo.set_make_working_trees(False)
270
self.assertFalse(shared_repo.make_working_trees())
269
271
self.assertTrue(shared_repo.has_revision('1'))
270
272
dir = self.make_bzrdir('shared/source')
271
273
dir.create_branch()
280
282
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
281
283
tree = self.make_branch_and_tree('commit_tree')
282
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
284
self.build_tree(['commit_tree/foo'])
284
286
tree.commit('revision 1', rev_id='1')
285
287
dir = self.make_bzrdir('source')
302
304
# and clone it with a revision limit.
304
306
tree = self.make_branch_and_tree('commit_tree')
305
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
307
self.build_tree(['commit_tree/foo'])
307
309
tree.commit('revision 1', rev_id='1')
308
tree.bzrdir.open_branch().set_revision_history([])
310
tree.branch.bzrdir.open_branch().set_revision_history([])
309
311
tree.set_parent_trees([])
310
312
tree.commit('revision 2', rev_id='2')
311
313
source = self.make_repository('source')
312
tree.bzrdir.open_repository().copy_content_into(source)
314
tree.branch.bzrdir.open_repository().copy_content_into(source)
313
315
dir = source.bzrdir
314
316
target = dir.clone(self.get_url('target'), revision_id='2')
315
317
raise TestSkipped('revision limiting not strict yet')
317
319
def test_clone_bzrdir_branch_and_repo(self):
318
320
tree = self.make_branch_and_tree('commit_tree')
319
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
321
self.build_tree(['commit_tree/foo'])
321
323
tree.commit('revision 1')
322
324
source = self.make_branch('source')
337
339
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
338
340
# by default cloning into a shared repo uses the shared repo.
339
341
tree = self.make_branch_and_tree('commit_tree')
340
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
342
self.build_tree(['commit_tree/foo'])
342
344
tree.commit('revision 1')
343
345
source = self.make_branch('source')
357
359
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
358
360
# by default cloning into a shared repo uses the shared repo.
359
361
tree = self.make_branch_and_tree('commit_tree')
360
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
362
self.build_tree(['commit_tree/foo'])
362
364
tree.commit('revision 1')
363
365
source = self.make_branch('source')
397
399
# and clone it with a revision limit.
399
401
tree = self.make_branch_and_tree('commit_tree')
400
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
402
self.build_tree(['commit_tree/foo'])
402
404
tree.commit('revision 1', rev_id='1')
403
405
tree.commit('revision 2', rev_id='2', allow_pointless=True)
409
411
self.assertEqual('1', target.open_branch().last_revision())
411
413
def test_clone_bzrdir_tree_branch_repo(self):
412
tree = self.make_branch_and_tree('sourcce')
413
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
414
tree = self.make_branch_and_tree('source')
415
self.build_tree(['source/foo'])
415
417
tree.commit('revision 1')
416
418
dir = tree.bzrdir
429
431
target.open_workingtree().revert([])
431
433
def test_revert_inventory(self):
432
tree = self.make_branch_and_tree('sourcce')
433
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
434
tree = self.make_branch_and_tree('source')
435
self.build_tree(['source/foo'])
435
437
tree.commit('revision 1')
436
438
dir = tree.bzrdir
485
487
# This smoke test just checks the revision-id is right. Tree specific
486
488
# tests will check corner cases.
487
489
tree = self.make_branch_and_tree('source')
488
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
490
self.build_tree(['source/foo'])
490
492
tree.commit('revision 1', rev_id='1')
491
493
tree.commit('revision 2', rev_id='2', allow_pointless=True)
494
496
self.skipIfNoWorkingTree(target)
495
497
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
497
def test_clone_bzrdir_incomplete_source_with_basis(self):
498
# ensure that basis really does grab from the basis by having incomplete source
499
tree = self.make_branch_and_tree('commit_tree')
500
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
502
tree.commit('revision 1', rev_id='1')
503
source = self.make_branch_and_tree('source')
504
# this gives us an incomplete repository
505
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
506
tree.commit('revision 2', rev_id='2', allow_pointless=True)
507
tree.bzrdir.open_branch().copy_content_into(source.branch)
508
tree.copy_content_into(source)
509
self.assertFalse(source.branch.repository.has_revision('2'))
511
target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
512
self.assertEqual('2', target.open_branch().last_revision())
514
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
515
except errors.NoWorkingTree:
516
# It should have a working tree if it's able to have one, so if
517
# we're here make sure it really can't have one.
518
self.assertRaises(errors.NotLocalUrl, target.create_workingtree)
519
self.assertTrue(target.open_branch().repository.has_revision('2'))
521
499
def test_get_branch_reference_on_reference(self):
522
500
"""get_branch_reference should return the right url."""
523
501
referenced_branch = self.make_branch('referenced')
563
541
target = self.sproutOrSkip(dir, self.get_url('target/child'))
564
542
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
565
543
target.open_branch()
566
target.open_workingtree()
545
target.open_workingtree()
546
except errors.NotLocalUrl:
547
# bzrdir's that test against non-local urls are allowed to pass:
548
# whitelist them for now
549
self.assertIsInstance(target, RemoteBzrDir)
568
551
def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
569
552
# the force_new_repo parameter should force use of a new repo in an empty
618
601
def test_sprout_bzrdir_with_repository_to_shared(self):
619
602
tree = self.make_branch_and_tree('commit_tree')
620
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
603
self.build_tree(['commit_tree/foo'])
622
605
tree.commit('revision 1', rev_id='1')
623
606
tree.bzrdir.open_branch().set_revision_history([])
624
607
tree.set_parent_trees([])
625
608
tree.commit('revision 2', rev_id='2')
626
609
source = self.make_repository('source')
627
tree.bzrdir.open_repository().copy_content_into(source)
610
tree.branch.bzrdir.open_repository().copy_content_into(source)
628
611
dir = source.bzrdir
630
613
shared_repo = self.make_repository('target', shared=True)
640
623
except errors.IncompatibleFormat:
642
625
tree = self.make_branch_and_tree('commit_tree')
643
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
626
self.build_tree(['commit_tree/foo'])
645
628
tree.commit('revision 1', rev_id='1')
646
629
tree.bzrdir.open_branch().set_revision_history([])
647
630
tree.set_parent_trees([])
648
631
tree.commit('revision 2', rev_id='2')
649
tree.bzrdir.open_repository().copy_content_into(shared_repo)
632
tree.branch.bzrdir.open_repository().copy_content_into(shared_repo)
650
633
dir = self.make_bzrdir('shared/source')
651
634
dir.create_branch()
652
635
target = self.sproutOrSkip(dir, self.get_url('shared/target'))
660
643
except errors.IncompatibleFormat:
662
645
tree = self.make_branch_and_tree('commit_tree')
663
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
646
self.build_tree(['commit_tree/foo'])
665
648
tree.commit('revision 1', rev_id='1')
666
649
tree.bzrdir.open_branch().set_revision_history([])
667
650
tree.set_parent_trees([])
668
651
tree.commit('revision 2', rev_id='2')
669
tree.bzrdir.open_repository().copy_content_into(shared_repo)
670
shared_repo.set_make_working_trees(False)
671
self.assertFalse(shared_repo.make_working_trees())
652
tree.branch.bzrdir.open_repository().copy_content_into(shared_repo)
653
if shared_repo.make_working_trees():
654
shared_repo.set_make_working_trees(False)
655
self.assertFalse(shared_repo.make_working_trees())
672
656
self.assertTrue(shared_repo.has_revision('1'))
673
657
dir = self.make_bzrdir('shared/source')
674
658
dir.create_branch()
677
661
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
678
662
branch = target.open_branch()
679
663
self.assertTrue(branch.repository.has_revision('1'))
680
self.assertTrue(branch.repository.make_working_trees())
664
if not isinstance(branch.bzrdir, RemoteBzrDir):
665
self.assertTrue(branch.repository.make_working_trees())
681
666
self.assertFalse(branch.repository.is_shared())
683
668
def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
684
669
tree = self.make_branch_and_tree('commit_tree')
685
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
670
self.build_tree(['commit_tree/foo'])
687
672
tree.commit('revision 1', rev_id='1')
688
673
tree.bzrdir.open_branch().set_revision_history([])
689
674
tree.set_parent_trees([])
690
675
tree.commit('revision 2', rev_id='2')
691
676
source = self.make_repository('source')
692
tree.bzrdir.open_repository().copy_content_into(source)
677
tree.branch.bzrdir.open_repository().copy_content_into(source)
693
678
dir = source.bzrdir
695
680
shared_repo = self.make_repository('target', shared=True)
706
691
# and sprout it with a revision limit.
708
693
tree = self.make_branch_and_tree('commit_tree')
709
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
694
self.build_tree(['commit_tree/foo'])
711
696
tree.commit('revision 1', rev_id='1')
712
697
tree.bzrdir.open_branch().set_revision_history([])
713
698
tree.set_parent_trees([])
714
699
tree.commit('revision 2', rev_id='2')
715
700
source = self.make_repository('source')
716
tree.bzrdir.open_repository().copy_content_into(source)
701
tree.branch.bzrdir.open_repository().copy_content_into(source)
717
702
dir = source.bzrdir
718
703
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
719
704
raise TestSkipped('revision limiting not strict yet')
721
706
def test_sprout_bzrdir_branch_and_repo(self):
722
707
tree = self.make_branch_and_tree('commit_tree')
723
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
708
self.build_tree(['commit_tree/foo'])
725
710
tree.commit('revision 1')
726
711
source = self.make_branch('source')
727
tree.bzrdir.open_repository().copy_content_into(source.repository)
712
tree.branch.bzrdir.open_repository().copy_content_into(source.repository)
728
713
tree.bzrdir.open_branch().copy_content_into(source)
729
714
dir = source.bzrdir
730
715
target = self.sproutOrSkip(dir, self.get_url('target'))
748
733
# sprouting a branch with a repo into a shared repo uses the shared
750
735
tree = self.make_branch_and_tree('commit_tree')
751
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
736
self.build_tree(['commit_tree/foo'])
753
738
tree.commit('revision 1', rev_id='1')
754
739
source = self.make_branch('source')
755
tree.bzrdir.open_repository().copy_content_into(source.repository)
740
tree.branch.bzrdir.open_repository().copy_content_into(source.repository)
756
741
tree.bzrdir.open_branch().copy_content_into(source)
757
742
dir = source.bzrdir
766
751
# sprouting a branch with a repo into a shared repo uses the shared
768
753
tree = self.make_branch_and_tree('commit_tree')
769
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
754
self.build_tree(['commit_tree/foo'])
771
756
tree.commit('revision 1', rev_id='1')
772
757
source = self.make_branch('source')
773
tree.bzrdir.open_repository().copy_content_into(source.repository)
758
tree.branch.bzrdir.open_repository().copy_content_into(source.repository)
774
759
tree.bzrdir.open_branch().copy_content_into(source)
775
760
dir = source.bzrdir
859
844
# and sprout it with a revision limit.
861
846
tree = self.make_branch_and_tree('commit_tree')
862
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
847
self.build_tree(['commit_tree/foo'])
864
849
tree.commit('revision 1', rev_id='1')
865
850
tree.commit('revision 2', rev_id='2', allow_pointless=True)
866
851
source = self.make_branch('source')
867
tree.bzrdir.open_repository().copy_content_into(source.repository)
852
tree.branch.bzrdir.open_repository().copy_content_into(source.repository)
868
853
tree.bzrdir.open_branch().copy_content_into(source)
869
854
dir = source.bzrdir
870
855
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
871
856
self.assertEqual('1', target.open_branch().last_revision())
873
858
def test_sprout_bzrdir_tree_branch_repo(self):
874
tree = self.make_branch_and_tree('sourcce')
859
tree = self.make_branch_and_tree('source')
875
860
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
877
862
tree.commit('revision 1')
961
946
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
962
947
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
964
def test_sprout_bzrdir_incomplete_source_with_basis(self):
965
# ensure that basis really does grab from the basis by having incomplete source
966
tree = self.make_branch_and_tree('commit_tree')
967
self.build_tree(['commit_tree/foo'])
969
tree.commit('revision 1', rev_id='1')
970
source = self.make_branch_and_tree('source')
971
# this gives us an incomplete repository
972
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
973
tree.commit('revision 2', rev_id='2', allow_pointless=True)
974
tree.bzrdir.open_branch().copy_content_into(source.branch)
975
tree.copy_content_into(source)
976
self.assertFalse(source.branch.repository.has_revision('2'))
978
target = self.sproutOrSkip(dir, self.get_url('target'),
980
self.assertEqual('2', target.open_branch().last_revision())
981
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
982
self.assertTrue(target.open_branch().repository.has_revision('2'))
984
949
def test_format_initialize_find_open(self):
985
950
# loopback test to check the current format initializes to itself.
986
951
if not self.bzrdir_format.is_supported():
1117
1082
source = self.make_branch_and_tree('source')
1118
1083
source.commit('a', rev_id='a', allow_pointless=True)
1119
1084
source.commit('b', rev_id='b', allow_pointless=True)
1120
self.build_tree(['new/'])
1121
1086
t_new = t.clone('new')
1122
1087
made_control = self.bzrdir_format.initialize_on_transport(t_new)
1123
1088
source.branch.repository.clone(made_control)