/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

Merge with walkdirs

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
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
5
5
# the Free Software Foundation; either version 2 of the License, or
30
30
    errors,
31
31
    help_topics,
32
32
    repository,
 
33
    osutils,
33
34
    symbol_versioning,
34
35
    urlutils,
35
36
    win32utils,
42
43
                           )
43
44
from bzrlib.tests import (
44
45
    TestCase,
 
46
    TestCaseWithMemoryTransport,
45
47
    TestCaseWithTransport,
46
48
    TestSkipped,
47
49
    test_sftp_transport
440
442
        self.assertEqual(parent_bzrdir.root_transport.base,
441
443
                         repo_policy._stack_on_pwd)
442
444
 
443
 
    def prepare_default_stacking(self):
 
445
    def prepare_default_stacking(self, child_format='development1'):
444
446
        parent_bzrdir = self.make_bzrdir('.')
445
 
        child_branch = self.make_branch('child', format='development1')
 
447
        child_branch = self.make_branch('child', format=child_format)
446
448
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
447
449
        new_child_transport = parent_bzrdir.transport.clone('child2')
448
450
        return child_branch, new_child_transport
459
461
        self.assertEqual(child_branch.base,
460
462
                         new_child.open_branch().get_stacked_on_url())
461
463
 
 
464
    def test_clone_ignores_policy_for_unsupported_formats(self):
 
465
        child_branch, new_child_transport = self.prepare_default_stacking(
 
466
            child_format='pack-0.92')
 
467
        new_child = child_branch.bzrdir.clone_on_transport(new_child_transport)
 
468
        self.assertRaises(errors.UnstackableBranchFormat,
 
469
                          new_child.open_branch().get_stacked_on_url)
 
470
 
 
471
    def test_sprout_ignores_policy_for_unsupported_formats(self):
 
472
        child_branch, new_child_transport = self.prepare_default_stacking(
 
473
            child_format='pack-0.92')
 
474
        new_child = child_branch.bzrdir.sprout(new_child_transport.base)
 
475
        self.assertRaises(errors.UnstackableBranchFormat,
 
476
                          new_child.open_branch().get_stacked_on_url)
 
477
 
 
478
    def test_sprout_upgrades_format_if_stacked_specified(self):
 
479
        child_branch, new_child_transport = self.prepare_default_stacking(
 
480
            child_format='pack-0.92')
 
481
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
 
482
                                               stacked=True)
 
483
        self.assertEqual(child_branch.bzrdir.root_transport.base,
 
484
                         new_child.open_branch().get_stacked_on_url())
 
485
        repo = new_child.open_repository()
 
486
        self.assertTrue(repo._format.supports_external_lookups)
 
487
        self.assertFalse(repo.supports_rich_root())
 
488
 
 
489
    def test_sprout_upgrades_to_rich_root_format_if_needed(self):
 
490
        child_branch, new_child_transport = self.prepare_default_stacking(
 
491
            child_format='rich-root-pack')
 
492
        def do_sprout():
 
493
            try:
 
494
                return child_branch.bzrdir.sprout(new_child_transport.base,
 
495
                                                  stacked=True)
 
496
            except errors.IncompatibleRepositories:
 
497
                raise AssertionError(
 
498
                    'Rich root format should be sprout-compatible')
 
499
        self.expectFailure('Rich root format should be sprout-compatible',
 
500
                           do_sprout)
 
501
        repo = new_child.open_repository()
 
502
        self.assertTrue(repo._format.supports_external_lookups)
 
503
        self.assertTrue(repo.supports_rich_root())
 
504
 
462
505
    def test_add_fallback_repo_handles_absolute_urls(self):
463
506
        stack_on = self.make_branch('stack_on', format='development1')
464
507
        repo = self.make_repository('repo', format='development1')
531
574
        self.assertEqual(os.path.realpath('topdir'),
532
575
                         self.local_branch_path(branch))
533
576
        self.assertEqual(
534
 
            os.path.realpath(os.path.join('topdir', '.bzr', 'repository')),
 
577
            osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
535
578
            repo.bzrdir.transport.local_abspath('repository'))
536
579
        self.assertEqual(relpath, 'foo')
537
580
 
544
587
        self.assertEqual(os.path.realpath('branch'),
545
588
                         self.local_branch_path(branch))
546
589
        self.assertEqual(
547
 
            os.path.realpath(os.path.join('branch', '.bzr', 'repository')),
 
590
            osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
548
591
            repo.bzrdir.transport.local_abspath('repository'))
549
592
        self.assertEqual(relpath, 'foo')
550
593
 
556
599
        self.assertEqual(tree, None)
557
600
        self.assertEqual(branch, None)
558
601
        self.assertEqual(
559
 
            os.path.realpath(os.path.join('repo', '.bzr', 'repository')),
 
602
            osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
560
603
            repo.bzrdir.transport.local_abspath('repository'))
561
604
        self.assertEqual(relpath, '')
562
605
 
571
614
        self.assertEqual(os.path.realpath('shared/branch'),
572
615
                         self.local_branch_path(branch))
573
616
        self.assertEqual(
574
 
            os.path.realpath(os.path.join('shared', '.bzr', 'repository')),
 
617
            osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
575
618
            repo.bzrdir.transport.local_abspath('repository'))
576
619
        self.assertEqual(relpath, '')
577
620
 
586
629
        self.assertEqual(os.path.realpath('foo'),
587
630
                         self.local_branch_path(branch))
588
631
        self.assertEqual(
589
 
            os.path.realpath(os.path.join('foo', '.bzr', 'repository')),
 
632
            osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
590
633
            repo.bzrdir.transport.local_abspath('repository'))
591
634
        self.assertEqual(relpath, 'bar')
592
635
 
599
642
        self.assertEqual(tree, None)
600
643
        self.assertEqual(branch, None)
601
644
        self.assertEqual(
602
 
            os.path.realpath(os.path.join('bar', '.bzr', 'repository')),
 
645
            osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
603
646
            repo.bzrdir.transport.local_abspath('repository'))
604
647
        self.assertEqual(relpath, 'baz')
605
648
 
1113
1156
        b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
1114
1157
        self.build_tree(['a'])
1115
1158
        self.assertEquals(['a'], self.get_ls())
 
1159
 
 
1160
 
 
1161
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
 
1162
    """Test BzrDirFormat implementation for TestBzrDirSprout."""
 
1163
 
 
1164
    def _open(self, transport):
 
1165
        return _TestBzrDir(transport, self)
 
1166
 
 
1167
 
 
1168
class _TestBzrDir(bzrdir.BzrDirMeta1):
 
1169
    """Test BzrDir implementation for TestBzrDirSprout.
 
1170
    
 
1171
    When created a _TestBzrDir already has repository and a branch.  The branch
 
1172
    is a test double as well.
 
1173
    """
 
1174
 
 
1175
    def __init__(self, *args, **kwargs):
 
1176
        super(_TestBzrDir, self).__init__(*args, **kwargs)
 
1177
        self.test_branch = _TestBranch()
 
1178
        self.test_branch.repository = self.create_repository()
 
1179
 
 
1180
    def open_branch(self, unsupported=False):
 
1181
        return self.test_branch
 
1182
 
 
1183
    def cloning_metadir(self, require_stacking=False):
 
1184
        return _TestBzrDirFormat()
 
1185
 
 
1186
 
 
1187
class _TestBranch(bzrlib.branch.Branch):
 
1188
    """Test Branch implementation for TestBzrDirSprout."""
 
1189
 
 
1190
    def __init__(self, *args, **kwargs):
 
1191
        super(_TestBranch, self).__init__(*args, **kwargs)
 
1192
        self.calls = []
 
1193
        self._parent = None
 
1194
 
 
1195
    def sprout(self, *args, **kwargs):
 
1196
        self.calls.append('sprout')
 
1197
        return _TestBranch()
 
1198
 
 
1199
    def copy_content_into(self, destination, revision_id=None):
 
1200
        self.calls.append('copy_content_into')
 
1201
 
 
1202
    def get_parent(self):
 
1203
        return self._parent
 
1204
 
 
1205
    def set_parent(self, parent):
 
1206
        self._parent = parent
 
1207
 
 
1208
 
 
1209
class TestBzrDirSprout(TestCaseWithMemoryTransport):
 
1210
 
 
1211
    def test_sprout_uses_branch_sprout(self):
 
1212
        """BzrDir.sprout calls Branch.sprout.
 
1213
 
 
1214
        Usually, BzrDir.sprout should delegate to the branch's sprout method
 
1215
        for part of the work.  This allows the source branch to control the
 
1216
        choice of format for the new branch.
 
1217
        
 
1218
        There are exceptions, but this tests avoids them:
 
1219
          - if there's no branch in the source bzrdir,
 
1220
          - or if the stacking has been requested and the format needs to be
 
1221
            overridden to satisfy that.
 
1222
        """
 
1223
        # Make an instrumented bzrdir.
 
1224
        t = self.get_transport('source')
 
1225
        t.ensure_base()
 
1226
        source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
 
1227
        # The instrumented bzrdir has a test_branch attribute that logs calls
 
1228
        # made to the branch contained in that bzrdir.  Initially the test
 
1229
        # branch exists but no calls have been made to it.
 
1230
        self.assertEqual([], source_bzrdir.test_branch.calls)
 
1231
 
 
1232
        # Sprout the bzrdir
 
1233
        target_url = self.get_url('target')
 
1234
        result = source_bzrdir.sprout(target_url, recurse='no')
 
1235
 
 
1236
        # The bzrdir called the branch's sprout method.
 
1237
        self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
 
1238
 
 
1239
    def test_sprout_parent(self):
 
1240
        grandparent_tree = self.make_branch('grandparent')
 
1241
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
 
1242
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
 
1243
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')