~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_bzrdir.py

  • Committer: Robert Collins
  • Date: 2008-09-02 05:28:37 UTC
  • mfrom: (3675 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3677.
  • Revision ID: robertc@robertcollins.net-20080902052837-ec3qlv41q5e7f6fl
Resolve conflicts with NEWS.

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
442
442
        self.assertEqual(parent_bzrdir.root_transport.base,
443
443
                         repo_policy._stack_on_pwd)
444
444
 
445
 
    def prepare_default_stacking(self):
 
445
    def prepare_default_stacking(self, child_format='development1'):
446
446
        parent_bzrdir = self.make_bzrdir('.')
447
 
        child_branch = self.make_branch('child', format='development1')
 
447
        child_branch = self.make_branch('child', format=child_format)
448
448
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
449
449
        new_child_transport = parent_bzrdir.transport.clone('child2')
450
450
        return child_branch, new_child_transport
461
461
        self.assertEqual(child_branch.base,
462
462
                         new_child.open_branch().get_stacked_on_url())
463
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
        new_child = child_branch.bzrdir.sprout(new_child_transport.base,
 
493
                                               stacked=True)
 
494
        repo = new_child.open_repository()
 
495
        self.assertTrue(repo._format.supports_external_lookups)
 
496
        self.assertTrue(repo.supports_rich_root())
 
497
 
464
498
    def test_add_fallback_repo_handles_absolute_urls(self):
465
499
        stack_on = self.make_branch('stack_on', format='development1')
466
500
        repo = self.make_repository('repo', format='development1')
1139
1173
    def open_branch(self, unsupported=False):
1140
1174
        return self.test_branch
1141
1175
 
1142
 
    def cloning_metadir(self):
 
1176
    def cloning_metadir(self, require_stacking=False):
1143
1177
        return _TestBzrDirFormat()
1144
1178
 
1145
1179
 
1149
1183
    def __init__(self, *args, **kwargs):
1150
1184
        super(_TestBranch, self).__init__(*args, **kwargs)
1151
1185
        self.calls = []
1152
 
    
 
1186
        self._parent = None
 
1187
 
1153
1188
    def sprout(self, *args, **kwargs):
1154
1189
        self.calls.append('sprout')
 
1190
        return _TestBranch()
 
1191
 
 
1192
    def copy_content_into(self, destination, revision_id=None):
 
1193
        self.calls.append('copy_content_into')
 
1194
 
 
1195
    def get_parent(self):
 
1196
        return self._parent
 
1197
 
 
1198
    def set_parent(self, parent):
 
1199
        self._parent = parent
1155
1200
 
1156
1201
 
1157
1202
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1182
1227
        result = source_bzrdir.sprout(target_url, recurse='no')
1183
1228
 
1184
1229
        # The bzrdir called the branch's sprout method.
1185
 
        self.assertEqual(['sprout'], source_bzrdir.test_branch.calls)
1186
 
        
 
1230
        self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
 
1231
 
 
1232
    def test_sprout_parent(self):
 
1233
        grandparent_tree = self.make_branch('grandparent')
 
1234
        parent = grandparent_tree.bzrdir.sprout('parent').open_branch()
 
1235
        branch_tree = parent.bzrdir.sprout('branch').open_branch()
 
1236
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')