~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/bzrdir_implementations/test_bzrdir.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
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
 
55
from bzrlib.repofmt import weaverepo
54
56
 
55
57
 
56
58
class TestCaseWithBzrDir(TestCaseWithTransport):
96
98
        directories = ['.']
97
99
        while directories:
98
100
            dir = directories.pop()
99
 
            for path in source.list_dir(dir):
 
101
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
100
102
                path = dir + '/' + path
101
103
                if path in ignore_list:
102
104
                    continue
103
 
                stat = source.stat(path)
 
105
                try:
 
106
                    stat = source.stat(path)
 
107
                except errors.NoSuchFile:
 
108
                    self.fail('%s not in source' % path)
104
109
                if S_ISDIR(stat.st_mode):
105
110
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
106
111
                    directories.append(path)
132
137
            raise TestSkipped("cannot make working tree with transport %r"
133
138
                              % a_bzrdir.transport)
134
139
 
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.
138
143
        
141
146
        """
142
147
        try:
143
148
            target = from_bzrdir.sprout(to_url, revision_id=revision_id,
144
 
                                        basis=basis,
145
149
                                        force_new_repo=force_new_repo)
146
150
        except errors.NotLocalUrl:
147
151
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
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)
 
158
        try:
 
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"
 
162
                              % dir.transport)
155
163
        self.assertEqual([], wt.get_parent_ids())
156
164
 
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)
 
182
 
 
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.
 
186
        """
 
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.
 
192
            return
 
193
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
174
194
            
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'])
180
201
    
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'])
188
210
    
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',
 
223
                                    [
 
224
                                     './.bzr/merge-hashes',
 
225
                                     './.bzr/repository/inventory.knit',
202
226
                                     ])
203
227
 
204
228
 
220
244
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
221
245
 
222
246
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
 
247
        # Create a shared repository
223
248
        try:
224
249
            shared_repo = self.make_repository('shared', shared=True)
225
250
        except errors.IncompatibleFormat:
226
251
            return
 
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)
229
256
        tree.add('foo')
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'))
241
276
 
242
277
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
245
280
        except errors.IncompatibleFormat:
246
281
            return
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'])
249
284
        tree.add('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()
267
303
        
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'])
271
307
        tree.add('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.
291
327
        # 
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'])
294
330
        tree.add('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')
304
340
 
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'])
308
344
        tree.add('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',
 
353
                                    [
 
354
                                     './.bzr/basis-inventory-cache',
318
355
                                     './.bzr/checkout/stat-cache',
 
356
                                     './.bzr/merge-hashes',
319
357
                                     './.bzr/repository/inventory.knit',
320
 
                                     ])
 
358
                                     './.bzr/stat-cache',
 
359
                                    ])
321
360
 
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'])
326
365
        tree.add('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)
331
370
        try:
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'])
346
385
        tree.add('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)
351
390
        try:
352
391
            self.make_repository('target', shared=True)
353
392
        except errors.IncompatibleFormat:
382
421
        # and clone it with a revision limit.
383
422
        # 
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'])
386
425
        tree.add('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())
395
434
        
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'])
399
438
        tree.add('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',
409
451
                                     ])
410
452
 
411
453
        target.open_workingtree().revert([])
412
454
 
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'])
416
458
        tree.add('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',
425
470
                                     ])
426
471
 
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',
432
480
                                     ])
433
481
 
434
 
 
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.
450
497
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
451
498
                                    ['./.bzr/stat-cache',
452
499
                                     './.bzr/checkout/stat-cache',
 
500
                                     './.bzr/checkout/merge-hashes',
 
501
                                     './.bzr/merge-hashes',
453
502
                                     './.bzr/repository/inventory.knit',
454
503
                                     ])
455
504
 
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'])
464
513
        tree.add('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())
471
520
 
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('..'))
476
 
        tree.add('foo')
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'))
485
 
        dir = source.bzrdir
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')
488
525
        try:
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,
 
527
                referenced_branch)
 
528
        except errors.IncompatibleFormat:
 
529
            # this is ok too, not all formats have to support references.
 
530
            return
 
531
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
 
532
            dir.get_branch_reference())
 
533
 
 
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())
 
538
 
 
539
    def test_get_branch_reference_no_branch(self):
 
540
        """get_branch_reference should not mask NotBranchErrors."""
 
541
        dir = self.make_bzrdir('source')
 
542
        if dir.has_branch():
 
543
            # this format does not support branchless bzrdirs.
 
544
            return
 
545
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
495
546
 
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()
 
566
        try:
 
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)
516
572
 
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',
549
 
                                     './.bzr/inventory'
 
604
                                    [
 
605
                                     './.bzr/branch',
 
606
                                     './.bzr/checkout',
 
607
                                     './.bzr/inventory',
 
608
                                     './.bzr/parent',
 
609
                                     './.bzr/repository/inventory.knit',
550
610
                                     ])
551
611
        try:
552
612
            # If we happen to have a tree, we'll guarantee everything
562
622
 
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'])
566
626
        tree.add('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
574
634
        try:
575
635
            shared_repo = self.make_repository('target', shared=True)
585
645
        except errors.IncompatibleFormat:
586
646
            return
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'])
589
649
        tree.add('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:
606
666
            return
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'])
609
669
        tree.add('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())
627
689
 
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'])
631
693
        tree.add('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
639
701
        try:
640
702
            shared_repo = self.make_repository('target', shared=True)
651
713
        # and sprout it with a revision limit.
652
714
        # 
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'])
655
717
        tree.add('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')
665
727
 
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'])
669
731
        tree.add('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',
 
740
                                    [
 
741
                                     './.bzr/basis-inventory-cache',
 
742
                                     './.bzr/branch/branch.conf',
 
743
                                     './.bzr/branch/parent',
 
744
                                     './.bzr/checkout',
 
745
                                     './.bzr/checkout/inventory',
679
746
                                     './.bzr/checkout/stat-cache',
680
747
                                     './.bzr/inventory',
681
 
                                     './.bzr/checkout/inventory',
 
748
                                     './.bzr/parent',
682
749
                                     './.bzr/repository/inventory.knit',
 
750
                                     './.bzr/stat-cache',
 
751
                                     './foo',
683
752
                                     ])
684
753
 
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
687
756
        # repo
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'])
690
759
        tree.add('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
696
765
        try:
704
773
        # sprouting a branch with a repo into a shared repo uses the shared
705
774
        # repo
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'])
708
777
        tree.add('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
714
783
        try:
797
866
        # and sprout it with a revision limit.
798
867
        # 
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'])
801
870
        tree.add('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())
810
879
        
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('..'))
814
883
        tree.add('foo')
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',
 
889
                                    [
 
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',
 
896
                                     './.bzr/parent',
824
897
                                     './.bzr/repository/inventory.knit',
 
898
                                     './.bzr/stat-cache',
825
899
                                     ])
826
900
 
827
901
    def test_sprout_bzrdir_tree_branch_reference(self):
837
911
            return
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)
863
937
            return
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'])
867
941
        tree.add('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'])
890
964
        tree.add('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())
896
970
 
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)
901
 
        tree.add('foo')
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'))
910
 
        dir = source.bzrdir
911
 
        target = self.sproutOrSkip(dir, self.get_url('target'),
912
 
                                   basis=tree.bzrdir)
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'))
916
 
 
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)
986
1041
 
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/'])
 
1107
        t.mkdir('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.
1068
1123
            return
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()
 
1127
        try:
 
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()
1112
1171
        try:
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)
1268
 
            try:
1269
 
                self.assertTrue(isinstance(dir._format.get_converter(),
1270
 
                                           bzrdir.Converter))
1271
 
            finally:
1272
 
                bzrdir.BzrDirFormat.set_default_format(old_format)
 
1323
            # (we force the latest known format as downgrades may not be
 
1324
            # available
 
1325
            self.assertTrue(isinstance(dir._format.get_converter(
 
1326
                format=dir._format), bzrdir.Converter))
1273
1327
        dir.needs_format_conversion(None)
1274
1328
 
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
 
1339
            # available
1288
1340
            pb = ui.ui_factory.nested_progress_bar()
1289
1341
            try:
1290
 
                dir._format.get_converter(None).convert(dir, pb)
 
1342
                dir._format.get_converter(format=dir._format).convert(dir, pb)
1291
1343
            finally:
1292
 
                bzrdir.BzrDirFormat.set_default_format(old_format)
1293
1344
                pb.finished()
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))
1301
1352
 
 
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'))
 
1360
        bd.retire_bzrdir()
 
1361
        self.failIf(transport.has('.bzr'))
 
1362
        self.failUnless(transport.has('.bzr.retired.1'))
1302
1363
 
1303
1364
class TestBreakLock(TestCaseWithBzrDir):
1304
1365
 
1394
1455
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1395
1456
        try:
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
 
1462
            # object.
1399
1463
            tree.unlock()
1400
1464
            return
1401
1465
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1416
1480
            # they may not be initializable.
1417
1481
            return
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'))
1422
1488
        try:
1423
1489
            repo = made_control.open_repository()
1424
1490
            # if there is a repository, then the format cannot ever hit this 
1426
1492
            return
1427
1493
        except errors.NoRepositoryPresent:
1428
1494
            pass
1429
 
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
 
1495
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1430
1496
        self.assertRaises(errors.NoRepositoryPresent,
1431
 
                          opened_control.find_repository)
 
1497
                          made_control.find_repository)
1432
1498