132
137
raise TestSkipped("cannot make working tree with transport %r"
133
138
% a_bzrdir.transport)
135
def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None, basis=None,
140
def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
136
141
force_new_repo=False):
137
142
"""Sprout from_bzrdir into to_url, or raise TestSkipped.
151
155
dir = self.make_bzrdir('dir1')
152
156
dir.create_repository()
153
157
dir.create_branch()
154
wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
159
wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
160
except errors.NotLocalUrl:
161
raise TestSkipped("cannot make working tree with transport %r"
155
163
self.assertEqual([], wt.get_parent_ids())
157
165
def test_destroy_workingtree(self):
171
179
bzrdir.destroy_workingtree_metadata()
172
180
self.failUnlessExists('tree/file')
173
181
self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
183
def test_open_workingtree_raises_no_working_tree(self):
184
"""BzrDir.open_workingtree() should raise NoWorkingTree (rather than
185
e.g. NotLocalUrl) if there is no working tree.
187
dir = self.make_bzrdir('source')
188
vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
189
if vfs_dir.has_workingtree():
190
# This BzrDir format doesn't support BzrDirs without working trees,
191
# so this test is irrelevant.
193
self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
175
195
def test_clone_bzrdir_empty(self):
176
196
dir = self.make_bzrdir('source')
177
197
target = dir.clone(self.get_url('target'))
178
198
self.assertNotEqual(dir.transport.base, target.transport.base)
179
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
199
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
200
['./.bzr/merge-hashes'])
181
202
def test_clone_bzrdir_empty_force_new_ignored(self):
182
203
# the force_new_repo parameter should have no effect on an empty
184
205
dir = self.make_bzrdir('source')
185
206
target = dir.clone(self.get_url('target'), force_new_repo=True)
186
207
self.assertNotEqual(dir.transport.base, target.transport.base)
187
self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
208
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
209
['./.bzr/merge-hashes'])
189
211
def test_clone_bzrdir_repository(self):
190
212
tree = self.make_branch_and_tree('commit_tree')
198
220
target = dir.clone(self.get_url('target'))
199
221
self.assertNotEqual(dir.transport.base, target.transport.base)
200
222
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
201
['./.bzr/repository/inventory.knit',
224
'./.bzr/merge-hashes',
225
'./.bzr/repository/inventory.knit',
220
244
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
222
246
def test_clone_bzrdir_repository_branch_both_under_shared(self):
247
# Create a shared repository
224
249
shared_repo = self.make_repository('shared', shared=True)
225
250
except errors.IncompatibleFormat:
252
# Make a branch, 'commit_tree', and working tree outside of the shared
253
# repository, and commit some revisions to it.
227
254
tree = self.make_branch_and_tree('commit_tree')
228
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
255
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
230
257
tree.commit('revision 1', rev_id='1')
231
258
tree.bzrdir.open_branch().set_revision_history([])
232
259
tree.set_parent_trees([])
233
260
tree.commit('revision 2', rev_id='2')
234
tree.bzrdir.open_repository().copy_content_into(shared_repo)
261
# Copy the content (i.e. revisions) from the 'commit_tree' branch's
262
# repository into the shared repository.
263
tree.branch.repository.copy_content_into(shared_repo)
264
# Make a branch 'source' inside the shared repository.
235
265
dir = self.make_bzrdir('shared/source')
236
266
dir.create_branch()
267
# Clone 'source' to 'target', also inside the shared repository.
237
268
target = dir.clone(self.get_url('shared/target'))
269
# 'source', 'target', and the shared repo all have distinct bzrdirs.
238
270
self.assertNotEqual(dir.transport.base, target.transport.base)
239
271
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
272
# The shared repository will contain revisions from the 'commit_tree'
273
# repository, even revisions that are not part of the history of the
274
# 'commit_tree' branch.
240
275
self.assertTrue(shared_repo.has_revision('1'))
242
277
def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
245
280
except errors.IncompatibleFormat:
247
282
tree = self.make_branch_and_tree('commit_tree')
248
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
283
self.build_tree(['commit_tree/foo'])
250
285
tree.commit('revision 1', rev_id='1')
251
tree.bzrdir.open_branch().set_revision_history([])
286
tree.branch.bzrdir.open_branch().set_revision_history([])
252
287
tree.set_parent_trees([])
253
288
tree.commit('revision 2', rev_id='2')
254
tree.bzrdir.open_repository().copy_content_into(shared_repo)
255
shared_repo.set_make_working_trees(False)
256
self.assertFalse(shared_repo.make_working_trees())
289
tree.branch.repository.copy_content_into(shared_repo)
290
if shared_repo.make_working_trees():
291
shared_repo.set_make_working_trees(False)
292
self.assertFalse(shared_repo.make_working_trees())
257
293
self.assertTrue(shared_repo.has_revision('1'))
258
294
dir = self.make_bzrdir('shared/source')
259
295
dir.create_branch()
268
304
def test_clone_bzrdir_repository_under_shared_force_new_repo(self):
269
305
tree = self.make_branch_and_tree('commit_tree')
270
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
306
self.build_tree(['commit_tree/foo'])
272
308
tree.commit('revision 1', rev_id='1')
273
309
dir = self.make_bzrdir('source')
290
326
# and clone it with a revision limit.
292
328
tree = self.make_branch_and_tree('commit_tree')
293
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
329
self.build_tree(['commit_tree/foo'])
295
331
tree.commit('revision 1', rev_id='1')
296
tree.bzrdir.open_branch().set_revision_history([])
332
tree.branch.bzrdir.open_branch().set_revision_history([])
297
333
tree.set_parent_trees([])
298
334
tree.commit('revision 2', rev_id='2')
299
335
source = self.make_repository('source')
300
tree.bzrdir.open_repository().copy_content_into(source)
336
tree.branch.repository.copy_content_into(source)
301
337
dir = source.bzrdir
302
338
target = dir.clone(self.get_url('target'), revision_id='2')
303
339
raise TestSkipped('revision limiting not strict yet')
305
341
def test_clone_bzrdir_branch_and_repo(self):
306
342
tree = self.make_branch_and_tree('commit_tree')
307
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
343
self.build_tree(['commit_tree/foo'])
309
345
tree.commit('revision 1')
310
346
source = self.make_branch('source')
311
tree.bzrdir.open_repository().copy_content_into(source.repository)
312
tree.bzrdir.open_branch().copy_content_into(source)
347
tree.branch.repository.copy_content_into(source.repository)
348
tree.branch.copy_content_into(source)
313
349
dir = source.bzrdir
314
350
target = dir.clone(self.get_url('target'))
315
351
self.assertNotEqual(dir.transport.base, target.transport.base)
316
352
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
317
['./.bzr/stat-cache',
354
'./.bzr/basis-inventory-cache',
318
355
'./.bzr/checkout/stat-cache',
356
'./.bzr/merge-hashes',
319
357
'./.bzr/repository/inventory.knit',
322
361
def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
323
362
# by default cloning into a shared repo uses the shared repo.
324
363
tree = self.make_branch_and_tree('commit_tree')
325
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
364
self.build_tree(['commit_tree/foo'])
327
366
tree.commit('revision 1')
328
367
source = self.make_branch('source')
329
tree.bzrdir.open_repository().copy_content_into(source.repository)
330
tree.bzrdir.open_branch().copy_content_into(source)
368
tree.branch.repository.copy_content_into(source.repository)
369
tree.branch.copy_content_into(source)
332
371
self.make_repository('target', shared=True)
333
372
except errors.IncompatibleFormat:
342
381
def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
343
382
# by default cloning into a shared repo uses the shared repo.
344
383
tree = self.make_branch_and_tree('commit_tree')
345
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
384
self.build_tree(['commit_tree/foo'])
347
386
tree.commit('revision 1')
348
387
source = self.make_branch('source')
349
tree.bzrdir.open_repository().copy_content_into(source.repository)
350
tree.bzrdir.open_branch().copy_content_into(source)
388
tree.branch.repository.copy_content_into(source.repository)
389
tree.branch.copy_content_into(source)
352
391
self.make_repository('target', shared=True)
353
392
except errors.IncompatibleFormat:
382
421
# and clone it with a revision limit.
384
423
tree = self.make_branch_and_tree('commit_tree')
385
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
424
self.build_tree(['commit_tree/foo'])
387
426
tree.commit('revision 1', rev_id='1')
388
427
tree.commit('revision 2', rev_id='2', allow_pointless=True)
389
428
source = self.make_branch('source')
390
tree.bzrdir.open_repository().copy_content_into(source.repository)
391
tree.bzrdir.open_branch().copy_content_into(source)
429
tree.branch.repository.copy_content_into(source.repository)
430
tree.branch.copy_content_into(source)
392
431
dir = source.bzrdir
393
432
target = dir.clone(self.get_url('target'), revision_id='1')
394
433
self.assertEqual('1', target.open_branch().last_revision())
396
435
def test_clone_bzrdir_tree_branch_repo(self):
397
tree = self.make_branch_and_tree('sourcce')
398
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
436
tree = self.make_branch_and_tree('source')
437
self.build_tree(['source/foo'])
400
439
tree.commit('revision 1')
401
440
dir = tree.bzrdir
404
443
self.assertNotEqual(dir.transport.base, target.transport.base)
405
444
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
406
445
['./.bzr/stat-cache',
446
'./.bzr/checkout/dirstate',
407
447
'./.bzr/checkout/stat-cache',
448
'./.bzr/checkout/merge-hashes',
449
'./.bzr/merge-hashes',
408
450
'./.bzr/repository/inventory.knit',
411
453
target.open_workingtree().revert([])
413
455
def test_revert_inventory(self):
414
tree = self.make_branch_and_tree('sourcce')
415
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
456
tree = self.make_branch_and_tree('source')
457
self.build_tree(['source/foo'])
417
459
tree.commit('revision 1')
418
460
dir = tree.bzrdir
420
462
self.skipIfNoWorkingTree(target)
421
463
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
422
464
['./.bzr/stat-cache',
465
'./.bzr/checkout/dirstate',
423
466
'./.bzr/checkout/stat-cache',
467
'./.bzr/checkout/merge-hashes',
468
'./.bzr/merge-hashes',
424
469
'./.bzr/repository/inventory.knit',
427
472
target.open_workingtree().revert([])
428
473
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
429
474
['./.bzr/stat-cache',
475
'./.bzr/checkout/dirstate',
430
476
'./.bzr/checkout/stat-cache',
477
'./.bzr/checkout/merge-hashes',
478
'./.bzr/merge-hashes',
431
479
'./.bzr/repository/inventory.knit',
435
482
def test_clone_bzrdir_tree_branch_reference(self):
436
483
# a tree with a branch reference (aka a checkout)
437
484
# should stay a checkout on clone.
460
509
# This smoke test just checks the revision-id is right. Tree specific
461
510
# tests will check corner cases.
462
511
tree = self.make_branch_and_tree('source')
463
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
512
self.build_tree(['source/foo'])
465
514
tree.commit('revision 1', rev_id='1')
466
515
tree.commit('revision 2', rev_id='2', allow_pointless=True)
469
518
self.skipIfNoWorkingTree(target)
470
519
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
472
def test_clone_bzrdir_incomplete_source_with_basis(self):
473
# ensure that basis really does grab from the basis by having incomplete source
474
tree = self.make_branch_and_tree('commit_tree')
475
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
477
tree.commit('revision 1', rev_id='1')
478
source = self.make_branch_and_tree('source')
479
# this gives us an incomplete repository
480
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
481
tree.commit('revision 2', rev_id='2', allow_pointless=True)
482
tree.bzrdir.open_branch().copy_content_into(source.branch)
483
tree.copy_content_into(source)
484
self.assertFalse(source.branch.repository.has_revision('2'))
486
target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
487
self.assertEqual('2', target.open_branch().last_revision())
521
def test_get_branch_reference_on_reference(self):
522
"""get_branch_reference should return the right url."""
523
referenced_branch = self.make_branch('referenced')
524
dir = self.make_bzrdir('source')
489
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
490
except errors.NoWorkingTree:
491
# It should have a working tree if it's able to have one, so if
492
# we're here make sure it really can't have one.
493
self.assertRaises(errors.NotLocalUrl, target.create_workingtree)
494
self.assertTrue(target.open_branch().repository.has_revision('2'))
526
reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
528
except errors.IncompatibleFormat:
529
# this is ok too, not all formats have to support references.
531
self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
532
dir.get_branch_reference())
534
def test_get_branch_reference_on_non_reference(self):
535
"""get_branch_reference should return None for non-reference branches."""
536
branch = self.make_branch('referenced')
537
self.assertEqual(None, branch.bzrdir.get_branch_reference())
539
def test_get_branch_reference_no_branch(self):
540
"""get_branch_reference should not mask NotBranchErrors."""
541
dir = self.make_bzrdir('source')
543
# this format does not support branchless bzrdirs.
545
self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
496
547
def test_sprout_bzrdir_empty(self):
497
548
dir = self.make_bzrdir('source')
512
563
target = self.sproutOrSkip(dir, self.get_url('target/child'))
513
564
self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
514
565
target.open_branch()
515
target.open_workingtree()
567
target.open_workingtree()
568
except errors.NoWorkingTree:
569
# bzrdir's that never have working trees are allowed to pass;
570
# whitelist them for now.
571
self.assertIsInstance(target, RemoteBzrDir)
517
573
def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
518
574
# the force_new_repo parameter should force use of a new repo in an empty
545
601
self.assertNotEqual(dir.transport.base, target.transport.base)
546
602
# testing inventory isn't reasonable for repositories
547
603
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
548
['./.bzr/repository/inventory.knit',
609
'./.bzr/repository/inventory.knit',
552
612
# If we happen to have a tree, we'll guarantee everything
563
623
def test_sprout_bzrdir_with_repository_to_shared(self):
564
624
tree = self.make_branch_and_tree('commit_tree')
565
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
625
self.build_tree(['commit_tree/foo'])
567
627
tree.commit('revision 1', rev_id='1')
568
628
tree.bzrdir.open_branch().set_revision_history([])
569
629
tree.set_parent_trees([])
570
630
tree.commit('revision 2', rev_id='2')
571
631
source = self.make_repository('source')
572
tree.bzrdir.open_repository().copy_content_into(source)
632
tree.branch.repository.copy_content_into(source)
573
633
dir = source.bzrdir
575
635
shared_repo = self.make_repository('target', shared=True)
585
645
except errors.IncompatibleFormat:
587
647
tree = self.make_branch_and_tree('commit_tree')
588
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
648
self.build_tree(['commit_tree/foo'])
590
650
tree.commit('revision 1', rev_id='1')
591
651
tree.bzrdir.open_branch().set_revision_history([])
592
652
tree.set_parent_trees([])
593
653
tree.commit('revision 2', rev_id='2')
594
tree.bzrdir.open_repository().copy_content_into(shared_repo)
654
tree.branch.repository.copy_content_into(shared_repo)
595
655
dir = self.make_bzrdir('shared/source')
596
656
dir.create_branch()
597
657
target = self.sproutOrSkip(dir, self.get_url('shared/target'))
605
665
except errors.IncompatibleFormat:
607
667
tree = self.make_branch_and_tree('commit_tree')
608
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
668
self.build_tree(['commit_tree/foo'])
610
670
tree.commit('revision 1', rev_id='1')
611
671
tree.bzrdir.open_branch().set_revision_history([])
612
672
tree.set_parent_trees([])
613
673
tree.commit('revision 2', rev_id='2')
614
tree.bzrdir.open_repository().copy_content_into(shared_repo)
615
shared_repo.set_make_working_trees(False)
616
self.assertFalse(shared_repo.make_working_trees())
674
tree.branch.repository.copy_content_into(shared_repo)
675
if shared_repo.make_working_trees():
676
shared_repo.set_make_working_trees(False)
677
self.assertFalse(shared_repo.make_working_trees())
617
678
self.assertTrue(shared_repo.has_revision('1'))
618
679
dir = self.make_bzrdir('shared/source')
619
680
dir.create_branch()
622
683
self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
623
684
branch = target.open_branch()
624
685
self.assertTrue(branch.repository.has_revision('1'))
625
self.assertTrue(branch.repository.make_working_trees())
686
if not isinstance(branch.bzrdir, RemoteBzrDir):
687
self.assertTrue(branch.repository.make_working_trees())
626
688
self.assertFalse(branch.repository.is_shared())
628
690
def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
629
691
tree = self.make_branch_and_tree('commit_tree')
630
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
692
self.build_tree(['commit_tree/foo'])
632
694
tree.commit('revision 1', rev_id='1')
633
695
tree.bzrdir.open_branch().set_revision_history([])
634
696
tree.set_parent_trees([])
635
697
tree.commit('revision 2', rev_id='2')
636
698
source = self.make_repository('source')
637
tree.bzrdir.open_repository().copy_content_into(source)
699
tree.branch.repository.copy_content_into(source)
638
700
dir = source.bzrdir
640
702
shared_repo = self.make_repository('target', shared=True)
651
713
# and sprout it with a revision limit.
653
715
tree = self.make_branch_and_tree('commit_tree')
654
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
716
self.build_tree(['commit_tree/foo'])
656
718
tree.commit('revision 1', rev_id='1')
657
719
tree.bzrdir.open_branch().set_revision_history([])
658
720
tree.set_parent_trees([])
659
721
tree.commit('revision 2', rev_id='2')
660
722
source = self.make_repository('source')
661
tree.bzrdir.open_repository().copy_content_into(source)
723
tree.branch.repository.copy_content_into(source)
662
724
dir = source.bzrdir
663
725
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
664
726
raise TestSkipped('revision limiting not strict yet')
666
728
def test_sprout_bzrdir_branch_and_repo(self):
667
729
tree = self.make_branch_and_tree('commit_tree')
668
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
730
self.build_tree(['commit_tree/foo'])
670
732
tree.commit('revision 1')
671
733
source = self.make_branch('source')
672
tree.bzrdir.open_repository().copy_content_into(source.repository)
734
tree.branch.repository.copy_content_into(source.repository)
673
735
tree.bzrdir.open_branch().copy_content_into(source)
674
736
dir = source.bzrdir
675
737
target = self.sproutOrSkip(dir, self.get_url('target'))
676
738
self.assertNotEqual(dir.transport.base, target.transport.base)
677
739
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
678
['./.bzr/stat-cache',
741
'./.bzr/basis-inventory-cache',
742
'./.bzr/branch/branch.conf',
743
'./.bzr/branch/parent',
745
'./.bzr/checkout/inventory',
679
746
'./.bzr/checkout/stat-cache',
680
747
'./.bzr/inventory',
681
'./.bzr/checkout/inventory',
682
749
'./.bzr/repository/inventory.knit',
685
754
def test_sprout_bzrdir_branch_and_repo_shared(self):
686
755
# sprouting a branch with a repo into a shared repo uses the shared
688
757
tree = self.make_branch_and_tree('commit_tree')
689
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
758
self.build_tree(['commit_tree/foo'])
691
760
tree.commit('revision 1', rev_id='1')
692
761
source = self.make_branch('source')
693
tree.bzrdir.open_repository().copy_content_into(source.repository)
762
tree.branch.repository.copy_content_into(source.repository)
694
763
tree.bzrdir.open_branch().copy_content_into(source)
695
764
dir = source.bzrdir
704
773
# sprouting a branch with a repo into a shared repo uses the shared
706
775
tree = self.make_branch_and_tree('commit_tree')
707
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
776
self.build_tree(['commit_tree/foo'])
709
778
tree.commit('revision 1', rev_id='1')
710
779
source = self.make_branch('source')
711
tree.bzrdir.open_repository().copy_content_into(source.repository)
780
tree.branch.repository.copy_content_into(source.repository)
712
781
tree.bzrdir.open_branch().copy_content_into(source)
713
782
dir = source.bzrdir
797
866
# and sprout it with a revision limit.
799
868
tree = self.make_branch_and_tree('commit_tree')
800
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
869
self.build_tree(['commit_tree/foo'])
802
871
tree.commit('revision 1', rev_id='1')
803
872
tree.commit('revision 2', rev_id='2', allow_pointless=True)
804
873
source = self.make_branch('source')
805
tree.bzrdir.open_repository().copy_content_into(source.repository)
874
tree.branch.repository.copy_content_into(source.repository)
806
875
tree.bzrdir.open_branch().copy_content_into(source)
807
876
dir = source.bzrdir
808
877
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
809
878
self.assertEqual('1', target.open_branch().last_revision())
811
880
def test_sprout_bzrdir_tree_branch_repo(self):
812
tree = self.make_branch_and_tree('sourcce')
881
tree = self.make_branch_and_tree('source')
813
882
self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
815
884
tree.commit('revision 1')
817
886
target = self.sproutOrSkip(dir, self.get_url('target'))
818
887
self.assertNotEqual(dir.transport.base, target.transport.base)
819
888
self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
820
['./.bzr/stat-cache',
890
'./.bzr/branch/branch.conf',
891
'./.bzr/branch/parent',
892
'./.bzr/checkout/dirstate',
821
893
'./.bzr/checkout/stat-cache',
894
'./.bzr/checkout/inventory',
822
895
'./.bzr/inventory',
823
'./.bzr/checkout/inventory',
824
897
'./.bzr/repository/inventory.knit',
827
901
def test_sprout_bzrdir_tree_branch_reference(self):
838
912
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
839
913
tree = self.createWorkingTreeOrSkip(dir)
840
tree.bzrdir.root_transport.mkdir('subdir')
914
self.build_tree(['source/subdir/'])
841
915
tree.add('subdir')
842
916
target = self.sproutOrSkip(dir, self.get_url('target'))
843
917
self.assertNotEqual(dir.transport.base, target.transport.base)
864
938
self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
865
939
tree = self.createWorkingTreeOrSkip(dir)
866
self.build_tree(['foo'], transport=dir.root_transport)
940
self.build_tree(['source/foo'])
868
942
tree.commit('revision 1', rev_id='1')
869
943
tree.commit('revision 2', rev_id='2', allow_pointless=True)
886
960
# This smoke test just checks the revision-id is right. Tree specific
887
961
# tests will check corner cases.
888
962
tree = self.make_branch_and_tree('source')
889
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
963
self.build_tree(['source/foo'])
891
965
tree.commit('revision 1', rev_id='1')
892
966
tree.commit('revision 2', rev_id='2', allow_pointless=True)
894
968
target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
895
969
self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
897
def test_sprout_bzrdir_incomplete_source_with_basis(self):
898
# ensure that basis really does grab from the basis by having incomplete source
899
tree = self.make_branch_and_tree('commit_tree')
900
self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
902
tree.commit('revision 1', rev_id='1')
903
source = self.make_branch_and_tree('source')
904
# this gives us an incomplete repository
905
tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
906
tree.commit('revision 2', rev_id='2', allow_pointless=True)
907
tree.bzrdir.open_branch().copy_content_into(source.branch)
908
tree.copy_content_into(source)
909
self.assertFalse(source.branch.repository.has_revision('2'))
911
target = self.sproutOrSkip(dir, self.get_url('target'),
913
self.assertEqual('2', target.open_branch().last_revision())
914
self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
915
self.assertTrue(target.open_branch().repository.has_revision('2'))
917
971
def test_format_initialize_find_open(self):
918
972
# loopback test to check the current format initializes to itself.
919
973
if not self.bzrdir_format.is_supported():
981
1035
t = get_transport(self.get_url())
982
1036
made_control = self.bzrdir_format.initialize(t.base)
983
1037
made_repo = made_control.create_repository()
984
self.failUnless(isinstance(made_repo, repository.Repository))
1038
# Check that we have a repository object.
1039
made_repo.has_revision('foo')
985
1040
self.assertEqual(made_control, made_repo.bzrdir)
987
1042
def test_create_repository_shared(self):
1049
1104
source = self.make_branch_and_tree('source')
1050
1105
source.commit('a', rev_id='a', allow_pointless=True)
1051
1106
source.commit('b', rev_id='b', allow_pointless=True)
1052
self.build_tree(['new/'])
1053
1108
t_new = t.clone('new')
1054
1109
made_control = self.bzrdir_format.initialize_on_transport(t_new)
1055
1110
source.branch.repository.clone(made_control)
1066
1121
# because the default open will not open them and
1067
1122
# they may not be initializable.
1069
# this has to be tested with local access as we still support creating
1124
# this has to be tested with local access as we still support creating
1070
1125
# format 6 bzrdirs
1071
t = get_transport('.')
1072
made_control = self.bzrdir_format.initialize(t.base)
1073
made_repo = made_control.create_repository()
1074
made_branch = made_control.create_branch()
1075
made_tree = made_control.create_workingtree()
1126
t = self.get_transport()
1128
made_control = self.bzrdir_format.initialize(t.base)
1129
made_repo = made_control.create_repository()
1130
made_branch = made_control.create_branch()
1131
made_tree = made_control.create_workingtree()
1132
except errors.NotLocalUrl:
1133
raise TestSkipped("Can't initialize %r on transport %r"
1134
% (self.bzrdir_format, t))
1076
1135
opened_tree = made_control.open_workingtree()
1077
1136
self.assertEqual(made_control, opened_tree.bzrdir)
1078
1137
self.failUnless(isinstance(opened_tree, made_tree.__class__))
1106
1165
self.assertTrue(isinstance(dir.get_repository_transport(None),
1107
1166
transport.Transport))
1108
1167
# with a given format, either the bzr dir supports identifiable
1109
# repositoryes, or it supports anonymous repository formats, but not both.
1110
anonymous_format = repository.RepositoryFormat6()
1111
identifiable_format = repository.RepositoryFormat7()
1168
# repositories, or it supports anonymous repository formats, but not both.
1169
anonymous_format = weaverepo.RepositoryFormat6()
1170
identifiable_format = weaverepo.RepositoryFormat7()
1113
1172
found_transport = dir.get_repository_transport(anonymous_format)
1114
1173
self.assertRaises(errors.IncompatibleFormat,
1261
1320
dir = self.make_bzrdir('.')
1262
1321
if dir.can_convert_format():
1263
1322
# if its default updatable there must be an updater
1264
# (we change the default to match the lastest known format
1265
# as downgrades may not be available
1266
old_format = bzrdir.BzrDirFormat.get_default_format()
1267
bzrdir.BzrDirFormat.set_default_format(dir._format)
1269
self.assertTrue(isinstance(dir._format.get_converter(),
1272
bzrdir.BzrDirFormat.set_default_format(old_format)
1323
# (we force the latest known format as downgrades may not be
1325
self.assertTrue(isinstance(dir._format.get_converter(
1326
format=dir._format), bzrdir.Converter))
1273
1327
dir.needs_format_conversion(None)
1275
1329
def test_upgrade_new_instance(self):
1281
1335
self.createWorkingTreeOrSkip(dir)
1282
1336
if dir.can_convert_format():
1283
1337
# if its default updatable there must be an updater
1284
# (we change the default to match the lastest known format
1285
# as downgrades may not be available
1286
old_format = bzrdir.BzrDirFormat.get_default_format()
1287
bzrdir.BzrDirFormat.set_default_format(dir._format)
1338
# (we force the latest known format as downgrades may not be
1288
1340
pb = ui.ui_factory.nested_progress_bar()
1290
dir._format.get_converter(None).convert(dir, pb)
1342
dir._format.get_converter(format=dir._format).convert(dir, pb)
1292
bzrdir.BzrDirFormat.set_default_format(old_format)
1294
1345
# and it should pass 'check' now.
1295
1346
check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
1299
1350
text = dir._format.get_format_description()
1300
1351
self.failUnless(len(text))
1353
def test_retire_bzrdir(self):
1354
bd = self.make_bzrdir('.')
1355
transport = bd.root_transport
1356
# must not overwrite existing directories
1357
self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1358
transport=transport)
1359
self.failUnless(transport.has('.bzr'))
1361
self.failIf(transport.has('.bzr'))
1362
self.failUnless(transport.has('.bzr.retired.1'))
1303
1364
class TestBreakLock(TestCaseWithBzrDir):
1394
1455
bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1396
1457
tree.bzrdir.break_lock()
1397
except NotImplementedError:
1458
except (NotImplementedError, errors.LockActive):
1398
1459
# bzrdir does not support break_lock
1460
# or one of the locked objects (currently only tree does this)
1461
# raised a LockActive because we do still have a live locked
1401
1465
self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1416
1480
# they may not be initializable.
1418
1482
# supported formats must be able to init and open
1419
url = self.get_url('subdir')
1420
get_transport(self.get_url()).mkdir('subdir')
1421
made_control = self.bzrdir_format.initialize(url)
1483
# - do the vfs initialisation over the basic vfs transport
1484
# XXX: TODO this should become a 'bzrdirlocation' api call.
1485
url = self.get_vfs_only_url('subdir')
1486
get_transport(self.get_vfs_only_url()).mkdir('subdir')
1487
made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
1423
1489
repo = made_control.open_repository()
1424
1490
# if there is a repository, then the format cannot ever hit this