/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.2 by Vincent Ladeuil
Fix assertNotEquals being deprecated by using assertNotEqual.
1
# Copyright (C) 2006-2013, 2016 Canonical Ltd
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
2
#
1534.4.39 by Robert Collins
Basic BzrDir support.
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
7
#
1534.4.39 by Robert Collins
Basic BzrDir support.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
12
#
1534.4.39 by Robert Collins
Basic BzrDir support.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.39 by Robert Collins
Basic BzrDir support.
16
17
"""Tests for the BzrDir facility and any format specific tests.
18
4523.1.4 by Martin Pool
Rename remaining *_implementations tests
19
For interface contract tests, see tests/per_bzr_dir.
1534.4.39 by Robert Collins
Basic BzrDir support.
20
"""
21
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
22
import os
3023.1.3 by Alexander Belchenko
John's review
23
import subprocess
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
24
import sys
1534.4.39 by Robert Collins
Basic BzrDir support.
25
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
26
from .. import (
5215.4.1 by Marius Kruger
BzrDir.find_branches should not fall over when encountering branches with missing repos
27
    branch,
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
28
    bzr,
6015.15.7 by John Arbash Meinel
Fix the 11 tests that still failed.
29
    config,
5363.2.6 by Jelmer Vernooij
Add ControlDirFormat.{un,}register_{server_,}prober.
30
    controldir,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
31
    errors,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
32
    help_topics,
5535.3.9 by Andrew Bennetts
Fix test failures.
33
    lock,
2100.3.35 by Aaron Bentley
equality operations on bzrdir
34
    repository,
5535.4.15 by Andrew Bennetts
Fix a test failure.
35
    revision as _mod_revision,
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
36
    osutils,
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
37
    transport as _mod_transport,
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
38
    urlutils,
3023.1.2 by Alexander Belchenko
Martin's review.
39
    win32utils,
6670.4.1 by Jelmer Vernooij
Update imports.
40
    )
41
from ..bzr import (
42
    branch as bzrbranch,
43
    bzrdir,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
44
    remote,
5816.5.4 by Jelmer Vernooij
Merge bzr.dev.
45
    workingtree_3,
5816.5.6 by Jelmer Vernooij
Fix default working tree format.
46
    workingtree_4,
2204.4.1 by Aaron Bentley
Add 'formats' help topic
47
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
48
import breezy.branch
6670.4.1 by Jelmer Vernooij
Update imports.
49
import breezy.bzr.branch
50
from ..bzr.fullhistory import BzrBranchFormat5
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
51
from ..errors import (
5582.10.50 by Jelmer Vernooij
Move more weave-specific tests to bzrlib.plugins.weave_fmt.
52
    NotBranchError,
53
    NoColocatedBranchSupport,
54
    UnknownFormatError,
55
    UnsupportedFormatError,
56
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
57
from . import (
2164.2.16 by Vincent Ladeuil
Add tests.
58
    TestCase,
3583.1.2 by Andrew Bennetts
Add test for fix.
59
    TestCaseWithMemoryTransport,
2164.2.16 by Vincent Ladeuil
Add tests.
60
    TestCaseWithTransport,
3023.1.2 by Alexander Belchenko
Martin's review.
61
    TestSkipped,
2164.2.16 by Vincent Ladeuil
Add tests.
62
    )
7186.1.1 by Martin
Fix E27* lint errors
63
from . import (
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
64
    http_server,
65
    http_utils,
2164.2.16 by Vincent Ladeuil
Add tests.
66
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
67
from ..transport import (
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
68
    memory,
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
69
    pathfilter,
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
70
    )
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
71
from ..transport.http import HttpTransport
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
72
from ..transport.nosmart import NoSmartTransportDecorator
73
from ..transport.readonly import ReadonlyTransportDecorator
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
74
from ..bzr import knitrepo, knitpack_repo
1534.4.39 by Robert Collins
Basic BzrDir support.
75
76
77
class TestDefaultFormat(TestCase):
78
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
79
    def test_get_set_default_format(self):
1534.4.39 by Robert Collins
Basic BzrDir support.
80
        old_format = bzrdir.BzrDirFormat.get_default_format()
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
81
        # default is BzrDirMetaFormat1
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
82
        self.assertIsInstance(old_format, bzrdir.BzrDirMetaFormat1)
5363.2.7 by Jelmer Vernooij
Fix tests.
83
        controldir.ControlDirFormat._set_default_format(SampleBzrDirFormat())
1534.4.39 by Robert Collins
Basic BzrDir support.
84
        # creating a bzr dir should now create an instrumented dir.
85
        try:
1685.1.42 by John Arbash Meinel
A couple more fixes to make sure memory:/// works correctly.
86
            result = bzrdir.BzrDir.create('memory:///')
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
87
            self.assertIsInstance(result, SampleBzrDir)
1534.4.39 by Robert Collins
Basic BzrDir support.
88
        finally:
5363.2.7 by Jelmer Vernooij
Fix tests.
89
            controldir.ControlDirFormat._set_default_format(old_format)
1534.4.39 by Robert Collins
Basic BzrDir support.
90
        self.assertEqual(old_format, bzrdir.BzrDirFormat.get_default_format())
91
92
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
93
class DeprecatedBzrDirFormat(bzrdir.BzrDirFormat):
94
    """A deprecated bzr dir format."""
95
96
2204.4.1 by Aaron Bentley
Add 'formats' help topic
97
class TestFormatRegistry(TestCase):
98
99
    def make_format_registry(self):
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
100
        my_format_registry = controldir.ControlDirFormatRegistry()
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
101
        my_format_registry.register('deprecated', DeprecatedBzrDirFormat,
7143.15.2 by Jelmer Vernooij
Run autopep8.
102
                                    'Some format.  Slower and unawesome and deprecated.',
103
                                    deprecated=True)
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
104
        my_format_registry.register_lazy('lazy', 'breezy.tests.test_bzrdir',
7143.15.2 by Jelmer Vernooij
Run autopep8.
105
                                         'DeprecatedBzrDirFormat', 'Format registered lazily',
106
                                         deprecated=True)
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
107
        bzr.register_metadir(my_format_registry, 'knit',
7143.15.2 by Jelmer Vernooij
Run autopep8.
108
                             'breezy.bzr.knitrepo.RepositoryFormatKnit1',
109
                             'Format using knits',
110
                             )
2204.4.1 by Aaron Bentley
Add 'formats' help topic
111
        my_format_registry.set_default('knit')
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
112
        bzr.register_metadir(my_format_registry,
7143.15.2 by Jelmer Vernooij
Run autopep8.
113
                             'branch6',
114
                             'breezy.bzr.knitrepo.RepositoryFormatKnit3',
115
                             'Experimental successor to knit.  Use at your own risk.',
116
                             branch_format='breezy.bzr.branch.BzrBranchFormat6',
117
                             experimental=True)
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
118
        bzr.register_metadir(my_format_registry,
7143.15.2 by Jelmer Vernooij
Run autopep8.
119
                             'hidden format',
120
                             'breezy.bzr.knitrepo.RepositoryFormatKnit3',
121
                             'Experimental successor to knit.  Use at your own risk.',
122
                             branch_format='breezy.bzr.branch.BzrBranchFormat6', hidden=True)
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
123
        my_format_registry.register('hiddendeprecated', DeprecatedBzrDirFormat,
7143.15.2 by Jelmer Vernooij
Run autopep8.
124
                                    'Old format.  Slower and does not support things. ', hidden=True)
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
125
        my_format_registry.register_lazy('hiddenlazy', 'breezy.tests.test_bzrdir',
7143.15.2 by Jelmer Vernooij
Run autopep8.
126
                                         'DeprecatedBzrDirFormat', 'Format registered lazily',
127
                                         deprecated=True, hidden=True)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
128
        return my_format_registry
129
130
    def test_format_registry(self):
131
        my_format_registry = self.make_format_registry()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
132
        my_bzrdir = my_format_registry.make_controldir('lazy')
133
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
134
        my_bzrdir = my_format_registry.make_controldir('deprecated')
135
        self.assertIsInstance(my_bzrdir, DeprecatedBzrDirFormat)
136
        my_bzrdir = my_format_registry.make_controldir('default')
137
        self.assertIsInstance(my_bzrdir.repository_format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
138
                              knitrepo.RepositoryFormatKnit1)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
139
        my_bzrdir = my_format_registry.make_controldir('knit')
140
        self.assertIsInstance(my_bzrdir.repository_format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
141
                              knitrepo.RepositoryFormatKnit1)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
142
        my_bzrdir = my_format_registry.make_controldir('branch6')
2230.3.55 by Aaron Bentley
Updates from review
143
        self.assertIsInstance(my_bzrdir.get_branch_format(),
6670.4.1 by Jelmer Vernooij
Update imports.
144
                              breezy.bzr.branch.BzrBranchFormat6)
2204.4.1 by Aaron Bentley
Add 'formats' help topic
145
146
    def test_get_help(self):
147
        my_format_registry = self.make_format_registry()
2204.4.7 by Aaron Bentley
restore register_lazy, remove register_factory, other updates
148
        self.assertEqual('Format registered lazily',
149
                         my_format_registry.get_help('lazy'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
150
        self.assertEqual('Format using knits',
2204.4.1 by Aaron Bentley
Add 'formats' help topic
151
                         my_format_registry.get_help('knit'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
152
        self.assertEqual('Format using knits',
2204.4.1 by Aaron Bentley
Add 'formats' help topic
153
                         my_format_registry.get_help('default'))
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
154
        self.assertEqual('Some format.  Slower and unawesome and deprecated.',
155
                         my_format_registry.get_help('deprecated'))
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
156
2204.4.1 by Aaron Bentley
Add 'formats' help topic
157
    def test_help_topic(self):
158
        topics = help_topics.HelpTopicRegistry()
3892.1.3 by Ian Clatworthy
tweak test suite to support the split up formats topic
159
        registry = self.make_format_registry()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
160
        topics.register('current-formats', registry.help_topic,
3892.1.3 by Ian Clatworthy
tweak test suite to support the split up formats topic
161
                        'Current formats')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
162
        topics.register('other-formats', registry.help_topic,
3892.1.3 by Ian Clatworthy
tweak test suite to support the split up formats topic
163
                        'Other formats')
164
        new = topics.get_detail('current-formats')
165
        rest = topics.get_detail('other-formats')
2939.2.3 by Ian Clatworthy
add tests for experimental formats including help content checking
166
        experimental, deprecated = rest.split('Deprecated formats')
4927.2.10 by Ian Clatworthy
fix test failures
167
        self.assertContainsRe(new, 'formats-help')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
168
        self.assertContainsRe(new,
7143.15.2 by Jelmer Vernooij
Run autopep8.
169
                              ':knit:\n    \\(native\\) \\(default\\) Format using knits\n')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
170
        self.assertContainsRe(experimental,
7143.15.2 by Jelmer Vernooij
Run autopep8.
171
                              ':branch6:\n    \\(native\\) Experimental successor to knit')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
172
        self.assertContainsRe(deprecated,
7143.15.2 by Jelmer Vernooij
Run autopep8.
173
                              ':lazy:\n    \\(native\\) Format registered lazily\n')
1551.13.2 by Aaron Bentley
Hide dirstate-with-subtree format
174
        self.assertNotContainsRe(new, 'hidden')
2204.4.1 by Aaron Bentley
Add 'formats' help topic
175
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
176
    def test_set_default_repository(self):
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
177
        default_factory = controldir.format_registry.get('default')
178
        old_default = [k for k, v in controldir.format_registry.iteritems()
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
179
                       if v == default_factory and k != 'default'][0]
7143.15.2 by Jelmer Vernooij
Run autopep8.
180
        controldir.format_registry.set_default_repository(
181
            'dirstate-with-subtree')
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
182
        try:
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
183
            self.assertIs(controldir.format_registry.get('dirstate-with-subtree'),
184
                          controldir.format_registry.get('default'))
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
185
            self.assertIs(
5651.3.9 by Jelmer Vernooij
Avoid using deprecated functions.
186
                repository.format_registry.get_default().__class__,
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
187
                knitrepo.RepositoryFormatKnit3)
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
188
        finally:
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
189
            controldir.format_registry.set_default_repository(old_default)
2204.4.11 by Aaron Bentley
deprecate Repository.set_default_format, update upgrade tests
190
3152.2.2 by Robert Collins
The bzrdir format registry now accepts an ``alias`` keyword to
191
    def test_aliases(self):
5363.2.10 by Jelmer Vernooij
base ControlDir on ControlComponent.
192
        a_registry = controldir.ControlDirFormatRegistry()
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
193
        a_registry.register('deprecated', DeprecatedBzrDirFormat,
7143.15.2 by Jelmer Vernooij
Run autopep8.
194
                            'Old format.  Slower and does not support stuff',
195
                            deprecated=True)
6929.10.2 by Jelmer Vernooij
Add register_alias option.
196
        a_registry.register_alias('deprecatedalias', 'deprecated')
6929.10.11 by Jelmer Vernooij
Fix more tests.
197
        self.assertEqual({'deprecatedalias': 'deprecated'},
198
                         a_registry.aliases())
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
199
2220.2.25 by Martin Pool
doc
200
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
201
class SampleBranch(breezy.branch.Branch):
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
202
    """A dummy branch for guess what, dummy use."""
203
204
    def __init__(self, dir):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
205
        self.controldir = dir
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
206
207
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
208
class SampleRepository(breezy.repository.Repository):
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
209
    """A dummy repo."""
210
211
    def __init__(self, dir):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
212
        self.controldir = dir
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
213
214
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
215
class SampleBzrDir(bzrdir.BzrDir):
216
    """A sample BzrDir implementation to allow testing static methods."""
217
1841.2.1 by Jelmer Vernooij
Fix handling of `shared' parameter in BzrDir.create_repository().
218
    def create_repository(self, shared=False):
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
219
        """See ControlDir.create_repository."""
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
220
        return "A repository"
221
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
222
    def open_repository(self):
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
223
        """See ControlDir.open_repository."""
3928.3.4 by John Arbash Meinel
SampleBzrDir now needs to return a real repo from open_repository
224
        return SampleRepository(self)
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
225
5051.3.3 by Jelmer Vernooij
Add tests for colo branches.
226
    def create_branch(self, name=None):
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
227
        """See ControlDir.create_branch."""
5051.3.3 by Jelmer Vernooij
Add tests for colo branches.
228
        if name is not None:
229
            raise NoColocatedBranchSupport(self)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
230
        return SampleBranch(self)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
231
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
232
    def create_workingtree(self):
6472.2.2 by Jelmer Vernooij
Use controldir rather than bzrdir in a couple more places.
233
        """See ControlDir.create_workingtree."""
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
234
        return "A tree"
235
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
236
1534.4.39 by Robert Collins
Basic BzrDir support.
237
class SampleBzrDirFormat(bzrdir.BzrDirFormat):
238
    """A sample format
239
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
240
    this format is initializable, unsupported to aid in testing the
1534.4.39 by Robert Collins
Basic BzrDir support.
241
    open and open_downlevel routines.
242
    """
243
244
    def get_format_string(self):
245
        """See BzrDirFormat.get_format_string()."""
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
246
        return b"Sample .bzr dir format."
1534.4.39 by Robert Collins
Basic BzrDir support.
247
2830.1.1 by Ian Clatworthy
bzrdir.py code clean-ups
248
    def initialize_on_transport(self, t):
1534.4.39 by Robert Collins
Basic BzrDir support.
249
        """Create a bzr dir."""
250
        t.mkdir('.bzr')
1955.3.9 by John Arbash Meinel
Find more occurrances of put() and replace with put_file or put_bytes
251
        t.put_bytes('.bzr/branch-format', self.get_format_string())
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
252
        return SampleBzrDir(t, self)
1534.4.39 by Robert Collins
Basic BzrDir support.
253
254
    def is_supported(self):
255
        return False
256
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
257
    def open(self, transport, _found=None):
1534.4.39 by Robert Collins
Basic BzrDir support.
258
        return "opened branch."
259
6213.1.7 by Jelmer Vernooij
Features doesn't use format string.
260
    @classmethod
261
    def from_string(cls, format_string):
262
        return cls()
263
1534.4.39 by Robert Collins
Basic BzrDir support.
264
5669.1.2 by Jelmer Vernooij
Review comments from Vincent.
265
class BzrDirFormatTest1(bzrdir.BzrDirMetaFormat1):
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
266
267
    @staticmethod
268
    def get_format_string():
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
269
        return b"Test format 1"
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
270
271
5669.1.2 by Jelmer Vernooij
Review comments from Vincent.
272
class BzrDirFormatTest2(bzrdir.BzrDirMetaFormat1):
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
273
274
    @staticmethod
275
    def get_format_string():
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
276
        return b"Test format 2"
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
277
278
1534.4.39 by Robert Collins
Basic BzrDir support.
279
class TestBzrDirFormat(TestCaseWithTransport):
280
    """Tests for the BzrDirFormat facility."""
281
282
    def test_find_format(self):
283
        # is the right format object found for a branch?
284
        # create a branch with a few known format objects.
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
285
        bzr.BzrProber.formats.register(BzrDirFormatTest1.get_format_string(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
286
                                       BzrDirFormatTest1())
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
287
        self.addCleanup(bzr.BzrProber.formats.remove,
7143.15.2 by Jelmer Vernooij
Run autopep8.
288
                        BzrDirFormatTest1.get_format_string())
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
289
        bzr.BzrProber.formats.register(BzrDirFormatTest2.get_format_string(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
290
                                       BzrDirFormatTest2())
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
291
        self.addCleanup(bzr.BzrProber.formats.remove,
7143.15.2 by Jelmer Vernooij
Run autopep8.
292
                        BzrDirFormatTest2.get_format_string())
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
293
        t = self.get_transport()
1534.4.39 by Robert Collins
Basic BzrDir support.
294
        self.build_tree(["foo/", "bar/"], transport=t)
7143.15.2 by Jelmer Vernooij
Run autopep8.
295
1534.4.39 by Robert Collins
Basic BzrDir support.
296
        def check_format(format, url):
297
            format.initialize(url)
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
298
            t = _mod_transport.get_transport_from_path(url)
1534.4.39 by Robert Collins
Basic BzrDir support.
299
            found_format = bzrdir.BzrDirFormat.find_format(t)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
300
            self.assertIsInstance(found_format, format.__class__)
5669.1.2 by Jelmer Vernooij
Review comments from Vincent.
301
        check_format(BzrDirFormatTest1(), "foo")
302
        check_format(BzrDirFormatTest2(), "bar")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
303
1534.4.39 by Robert Collins
Basic BzrDir support.
304
    def test_find_format_nothing_there(self):
305
        self.assertRaises(NotBranchError,
306
                          bzrdir.BzrDirFormat.find_format,
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
307
                          _mod_transport.get_transport_from_path('.'))
1534.4.39 by Robert Collins
Basic BzrDir support.
308
309
    def test_find_format_unknown_format(self):
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
310
        t = self.get_transport()
1534.4.39 by Robert Collins
Basic BzrDir support.
311
        t.mkdir('.bzr')
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
312
        t.put_bytes('.bzr/branch-format', b'')
1534.4.39 by Robert Collins
Basic BzrDir support.
313
        self.assertRaises(UnknownFormatError,
314
                          bzrdir.BzrDirFormat.find_format,
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
315
                          _mod_transport.get_transport_from_path('.'))
1534.4.39 by Robert Collins
Basic BzrDir support.
316
7123.2.1 by Jelmer Vernooij
Improve error message if line endings in format file were corrupted.
317
    def test_find_format_line_endings(self):
318
        t = self.get_transport()
319
        t.mkdir('.bzr')
320
        t.put_bytes('.bzr/branch-format', b'Corrupt line endings\r\n')
321
        self.assertRaises(errors.LineEndingError,
322
                          bzrdir.BzrDirFormat.find_format,
323
                          _mod_transport.get_transport_from_path('.'))
324
1534.4.39 by Robert Collins
Basic BzrDir support.
325
    def test_register_unregister_format(self):
326
        format = SampleBzrDirFormat()
327
        url = self.get_url()
328
        # make a bzrdir
329
        format.initialize(url)
330
        # register a format for it.
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
331
        bzr.BzrProber.formats.register(format.get_format_string(), format)
1534.4.39 by Robert Collins
Basic BzrDir support.
332
        # which bzrdir.Open will refuse (not supported)
333
        self.assertRaises(UnsupportedFormatError, bzrdir.BzrDir.open, url)
1596.2.1 by Robert Collins
Fix BzrDir.open_containing of unsupported branches.
334
        # which bzrdir.open_containing will refuse (not supported)
7143.15.2 by Jelmer Vernooij
Run autopep8.
335
        self.assertRaises(UnsupportedFormatError,
336
                          bzrdir.BzrDir.open_containing, url)
1534.4.39 by Robert Collins
Basic BzrDir support.
337
        # but open_downlevel will work
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
338
        t = _mod_transport.get_transport_from_url(url)
1534.4.39 by Robert Collins
Basic BzrDir support.
339
        self.assertEqual(format.open(t), bzrdir.BzrDir.open_unsupported(url))
340
        # unregister the format
6695.5.1 by Jelmer Vernooij
Move bzr format registration to breezy.bzr.
341
        bzr.BzrProber.formats.remove(format.get_format_string())
1534.4.39 by Robert Collins
Basic BzrDir support.
342
        # now open_downlevel should fail too.
7143.15.2 by Jelmer Vernooij
Run autopep8.
343
        self.assertRaises(UnknownFormatError,
344
                          bzrdir.BzrDir.open_unsupported, url)
1534.4.39 by Robert Collins
Basic BzrDir support.
345
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
346
    def test_create_branch_and_repo_uses_default(self):
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
347
        format = SampleBzrDirFormat()
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
348
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url(),
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
349
                                                      format=format)
350
        self.assertTrue(isinstance(branch, SampleBranch))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
351
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
352
    def test_create_branch_and_repo_under_shared(self):
353
        # creating a branch and repo in a shared repo uses the
354
        # shared repository
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
355
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
356
        self.make_repository('.', shared=True, format=format)
357
        branch = bzrdir.BzrDir.create_branch_and_repo(
358
            self.get_url('child'), format=format)
359
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
360
                          branch.controldir.open_repository)
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
361
362
    def test_create_branch_and_repo_under_shared_force_new(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
363
        # creating a branch and repo in a shared repo can be forced to
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
364
        # make a new repo
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
365
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
366
        self.make_repository('.', shared=True, format=format)
367
        branch = bzrdir.BzrDir.create_branch_and_repo(self.get_url('child'),
368
                                                      force_new_repo=True,
369
                                                      format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
370
        branch.controldir.open_repository()
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
371
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
372
    def test_create_standalone_working_tree(self):
373
        format = SampleBzrDirFormat()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
374
        # note this is deliberately readonly, as this failure should
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
375
        # occur before any writes.
376
        self.assertRaises(errors.NotLocalUrl,
377
                          bzrdir.BzrDir.create_standalone_workingtree,
378
                          self.get_readonly_url(), format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
379
        tree = bzrdir.BzrDir.create_standalone_workingtree('.',
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
380
                                                           format=format)
381
        self.assertEqual('A tree', tree)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
382
1534.6.10 by Robert Collins
Finish use of repositories support.
383
    def test_create_standalone_working_tree_under_shared_repo(self):
384
        # create standalone working tree always makes a repo.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
385
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
386
        self.make_repository('.', shared=True, format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
387
        # note this is deliberately readonly, as this failure should
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
388
        # occur before any writes.
389
        self.assertRaises(errors.NotLocalUrl,
390
                          bzrdir.BzrDir.create_standalone_workingtree,
391
                          self.get_readonly_url('child'), format=format)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
392
        tree = bzrdir.BzrDir.create_standalone_workingtree('child',
7143.15.2 by Jelmer Vernooij
Run autopep8.
393
                                                           format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
394
        tree.controldir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
395
396
    def test_create_branch_convenience(self):
1534.1.29 by Robert Collins
Add a test environment for InterRepository objects, and remove the fetch corner case tests from test_repository.
397
        # outside a repo the default convenience output is a repo+branch_tree
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
398
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
399
        branch = bzrdir.BzrDir.create_branch_convenience('.', format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
400
        branch.controldir.open_workingtree()
401
        branch.controldir.open_repository()
1534.6.10 by Robert Collins
Finish use of repositories support.
402
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
403
    def test_create_branch_convenience_possible_transports(self):
404
        """Check that the optional 'possible_transports' is recognized"""
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
405
        format = controldir.format_registry.make_controldir('knit')
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
406
        t = self.get_transport()
407
        branch = bzrdir.BzrDir.create_branch_convenience(
408
            '.', format=format, possible_transports=[t])
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
409
        branch.controldir.open_workingtree()
410
        branch.controldir.open_repository()
2476.3.10 by Vincent Ladeuil
Add a test for create_branch_convenience. Mark some places to test for multiple connections.
411
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
412
    def test_create_branch_convenience_root(self):
413
        """Creating a branch at the root of a fs should work."""
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
414
        self.vfs_transport_factory = memory.MemoryServer
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
415
        # outside a repo the default convenience output is a repo+branch_tree
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
416
        format = controldir.format_registry.make_controldir('knit')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
417
        branch = bzrdir.BzrDir.create_branch_convenience(self.get_url(),
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
418
                                                         format=format)
419
        self.assertRaises(errors.NoWorkingTree,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
420
                          branch.controldir.open_workingtree)
421
        branch.controldir.open_repository()
1725.2.5 by Robert Collins
Bugfix create_branch_convenience at the root of a file system to not loop
422
1534.6.10 by Robert Collins
Finish use of repositories support.
423
    def test_create_branch_convenience_under_shared_repo(self):
424
        # inside a repo the default convenience output is a branch+ follow the
425
        # repo tree policy
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
426
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
427
        self.make_repository('.', shared=True, format=format)
428
        branch = bzrdir.BzrDir.create_branch_convenience('child',
7143.15.2 by Jelmer Vernooij
Run autopep8.
429
                                                         format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
430
        branch.controldir.open_workingtree()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
431
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
432
                          branch.controldir.open_repository)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
433
1534.6.10 by Robert Collins
Finish use of repositories support.
434
    def test_create_branch_convenience_under_shared_repo_force_no_tree(self):
435
        # inside a repo the default convenience output is a branch+ follow the
436
        # repo tree policy but we can override that
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
437
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
438
        self.make_repository('.', shared=True, format=format)
439
        branch = bzrdir.BzrDir.create_branch_convenience('child',
7143.15.2 by Jelmer Vernooij
Run autopep8.
440
                                                         force_new_tree=False, format=format)
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
441
        self.assertRaises(errors.NoWorkingTree,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
442
                          branch.controldir.open_workingtree)
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
443
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
444
                          branch.controldir.open_repository)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
445
1534.6.10 by Robert Collins
Finish use of repositories support.
446
    def test_create_branch_convenience_under_shared_repo_no_tree_policy(self):
447
        # inside a repo the default convenience output is a branch+ follow the
448
        # repo tree policy
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
449
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
450
        repo = self.make_repository('.', shared=True, format=format)
451
        repo.set_make_working_trees(False)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
452
        branch = bzrdir.BzrDir.create_branch_convenience('child',
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
453
                                                         format=format)
454
        self.assertRaises(errors.NoWorkingTree,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
455
                          branch.controldir.open_workingtree)
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
456
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
457
                          branch.controldir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
458
459
    def test_create_branch_convenience_under_shared_repo_no_tree_policy_force_tree(self):
460
        # inside a repo the default convenience output is a branch+ follow the
461
        # repo tree policy but we can override that
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
462
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
463
        repo = self.make_repository('.', shared=True, format=format)
464
        repo.set_make_working_trees(False)
465
        branch = bzrdir.BzrDir.create_branch_convenience('child',
7143.15.2 by Jelmer Vernooij
Run autopep8.
466
                                                         force_new_tree=True, format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
467
        branch.controldir.open_workingtree()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
468
        self.assertRaises(errors.NoRepositoryPresent,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
469
                          branch.controldir.open_repository)
1534.6.10 by Robert Collins
Finish use of repositories support.
470
471
    def test_create_branch_convenience_under_shared_repo_force_new_repo(self):
472
        # inside a repo the default convenience output is overridable to give
473
        # repo+branch+tree
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
474
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
475
        self.make_repository('.', shared=True, format=format)
476
        branch = bzrdir.BzrDir.create_branch_convenience('child',
7143.15.2 by Jelmer Vernooij
Run autopep8.
477
                                                         force_new_repo=True, format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
478
        branch.controldir.open_repository()
479
        branch.controldir.open_workingtree()
1534.6.10 by Robert Collins
Finish use of repositories support.
480
3242.2.14 by Aaron Bentley
Update from review comments
481
482
class TestRepositoryAcquisitionPolicy(TestCaseWithTransport):
483
3242.2.10 by Aaron Bentley
Rename RepositoryPolicy.apply to acquire_repository
484
    def test_acquire_repository_standalone(self):
3242.2.14 by Aaron Bentley
Update from review comments
485
        """The default acquisition policy should create a standalone branch."""
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
486
        my_bzrdir = self.make_controldir('.')
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
487
        repo_policy = my_bzrdir.determine_repository_policy()
4070.9.2 by Andrew Bennetts
Rough prototype of allowing a SearchResult to be passed to fetch, and using that to improve network conversations.
488
        repo, is_new = repo_policy.acquire_repository()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
489
        self.assertEqual(repo.controldir.root_transport.base,
3242.2.1 by Aaron Bentley
Abstract policy decisions into determine_repository_policy
490
                         my_bzrdir.root_transport.base)
3242.2.14 by Aaron Bentley
Update from review comments
491
        self.assertFalse(repo.is_shared())
492
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
493
    def test_determine_stacking_policy(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
494
        parent_bzrdir = self.make_controldir('.')
495
        child_bzrdir = self.make_controldir('child')
3242.3.11 by Aaron Bentley
Clean up BzrDirConfig usage
496
        parent_bzrdir.get_config().set_default_stack_on('http://example.org')
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
497
        repo_policy = child_bzrdir.determine_repository_policy()
498
        self.assertEqual('http://example.org', repo_policy._stack_on)
499
3242.3.27 by Aaron Bentley
Interpret default stacking paths relative to config bzrdir
500
    def test_determine_stacking_policy_relative(self):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
501
        parent_bzrdir = self.make_controldir('.')
502
        child_bzrdir = self.make_controldir('child')
3242.3.27 by Aaron Bentley
Interpret default stacking paths relative to config bzrdir
503
        parent_bzrdir.get_config().set_default_stack_on('child2')
504
        repo_policy = child_bzrdir.determine_repository_policy()
3242.3.32 by Aaron Bentley
Defer handling relative stacking URLs as late as possible.
505
        self.assertEqual('child2', repo_policy._stack_on)
506
        self.assertEqual(parent_bzrdir.root_transport.base,
507
                         repo_policy._stack_on_pwd)
3242.3.27 by Aaron Bentley
Interpret default stacking paths relative to config bzrdir
508
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
509
    def prepare_default_stacking(self, child_format='1.6'):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
510
        parent_bzrdir = self.make_controldir('.')
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
511
        child_branch = self.make_branch('child', format=child_format)
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
512
        parent_bzrdir.get_config().set_default_stack_on(child_branch.base)
3242.3.5 by Aaron Bentley
Implement stacking for clone_on_transport
513
        new_child_transport = parent_bzrdir.transport.clone('child2')
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
514
        return child_branch, new_child_transport
515
516
    def test_clone_on_transport_obeys_stacking_policy(self):
517
        child_branch, new_child_transport = self.prepare_default_stacking()
7143.15.2 by Jelmer Vernooij
Run autopep8.
518
        new_child = child_branch.controldir.clone_on_transport(
519
            new_child_transport)
3242.5.1 by Jonathan Lange
Allow stacked-on branch locations to be stored as relative URLs.
520
        self.assertEqual(child_branch.base,
3537.3.5 by Martin Pool
merge trunk including stacking policy
521
                         new_child.open_branch().get_stacked_on_url())
3242.3.5 by Aaron Bentley
Implement stacking for clone_on_transport
522
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
523
    def test_default_stacking_with_stackable_branch_unstackable_repo(self):
524
        # Make stackable source branch with an unstackable repo format.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
525
        source_bzrdir = self.make_controldir('source')
5757.1.6 by Jelmer Vernooij
Fix another import.
526
        knitpack_repo.RepositoryFormatKnitPack1().initialize(source_bzrdir)
6670.4.1 by Jelmer Vernooij
Update imports.
527
        source_branch = breezy.bzr.branch.BzrBranchFormat7().initialize(
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
528
            source_bzrdir)
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
529
        # Make a directory with a default stacking policy
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
530
        parent_bzrdir = self.make_controldir('parent')
4126.1.1 by Andrew Bennetts
Fix bug when pushing stackable branch in unstackable repo to default-stacking target.
531
        stacked_on = self.make_branch('parent/stacked-on', format='pack-0.92')
532
        parent_bzrdir.get_config().set_default_stack_on(stacked_on.base)
533
        # Clone source into directory
534
        target = source_bzrdir.clone(self.get_url('parent/target'))
535
6164.2.8 by Jelmer Vernooij
Move ex_stacked_on
536
    def test_format_initialize_on_transport_ex_stacked_on(self):
537
        # trunk is a stackable format.  Note that its in the same server area
538
        # which is what launchpad does, but not sufficient to exercise the
539
        # general case.
540
        trunk = self.make_branch('trunk', format='1.9')
541
        t = self.get_transport('stacked')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
542
        old_fmt = controldir.format_registry.make_controldir('pack-0.92')
6164.2.8 by Jelmer Vernooij
Move ex_stacked_on
543
        repo_name = old_fmt.repository_format.network_name()
544
        # Should end up with a 1.9 format (stackable)
545
        repo, control, require_stacking, repo_policy = \
546
            old_fmt.initialize_on_transport_ex(t,
7143.15.2 by Jelmer Vernooij
Run autopep8.
547
                                               repo_format_name=repo_name, stacked_on='../trunk',
548
                                               stack_on_pwd=t.base)
6164.2.8 by Jelmer Vernooij
Move ex_stacked_on
549
        if repo is not None:
550
            # Repositories are open write-locked
551
            self.assertTrue(repo.is_write_locked())
552
            self.addCleanup(repo.unlock)
553
        else:
554
            repo = control.open_repository()
555
        self.assertIsInstance(control, bzrdir.BzrDir)
556
        opened = bzrdir.BzrDir.open(t.base)
557
        if not isinstance(old_fmt, remote.RemoteBzrDirFormat):
558
            self.assertEqual(control._format.network_name(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
559
                             old_fmt.network_name())
6164.2.8 by Jelmer Vernooij
Move ex_stacked_on
560
            self.assertEqual(control._format.network_name(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
561
                             opened._format.network_name())
6164.2.8 by Jelmer Vernooij
Move ex_stacked_on
562
        self.assertEqual(control.__class__, opened.__class__)
563
        self.assertLength(1, repo._fallback_repositories)
564
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
565
    def test_sprout_obeys_stacking_policy(self):
566
        child_branch, new_child_transport = self.prepare_default_stacking()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
567
        new_child = child_branch.controldir.sprout(new_child_transport.base)
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
568
        self.assertEqual(child_branch.base,
3537.3.5 by Martin Pool
merge trunk including stacking policy
569
                         new_child.open_branch().get_stacked_on_url())
3242.3.28 by Aaron Bentley
Use repository acquisition policy for sprouting
570
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
571
    def test_clone_ignores_policy_for_unsupported_formats(self):
572
        child_branch, new_child_transport = self.prepare_default_stacking(
573
            child_format='pack-0.92')
7143.15.2 by Jelmer Vernooij
Run autopep8.
574
        new_child = child_branch.controldir.clone_on_transport(
575
            new_child_transport)
6734.1.11 by Jelmer Vernooij
Move UnstackableBranchFormat.
576
        self.assertRaises(branch.UnstackableBranchFormat,
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
577
                          new_child.open_branch().get_stacked_on_url)
578
579
    def test_sprout_ignores_policy_for_unsupported_formats(self):
580
        child_branch, new_child_transport = self.prepare_default_stacking(
581
            child_format='pack-0.92')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
582
        new_child = child_branch.controldir.sprout(new_child_transport.base)
6734.1.11 by Jelmer Vernooij
Move UnstackableBranchFormat.
583
        self.assertRaises(branch.UnstackableBranchFormat,
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
584
                          new_child.open_branch().get_stacked_on_url)
585
586
    def test_sprout_upgrades_format_if_stacked_specified(self):
587
        child_branch, new_child_transport = self.prepare_default_stacking(
588
            child_format='pack-0.92')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
589
        new_child = child_branch.controldir.sprout(new_child_transport.base,
7143.15.2 by Jelmer Vernooij
Run autopep8.
590
                                                   stacked=True)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
591
        self.assertEqual(child_branch.controldir.root_transport.base,
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
592
                         new_child.open_branch().get_stacked_on_url())
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
593
        repo = new_child.open_repository()
594
        self.assertTrue(repo._format.supports_external_lookups)
595
        self.assertFalse(repo.supports_rich_root())
596
3650.5.1 by Aaron Bentley
Fix push to use clone all the time.
597
    def test_clone_on_transport_upgrades_format_if_stacked_on_specified(self):
598
        child_branch, new_child_transport = self.prepare_default_stacking(
599
            child_format='pack-0.92')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
600
        new_child = child_branch.controldir.clone_on_transport(new_child_transport,
7143.15.2 by Jelmer Vernooij
Run autopep8.
601
                                                               stacked_on=child_branch.controldir.root_transport.base)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
602
        self.assertEqual(child_branch.controldir.root_transport.base,
3650.5.1 by Aaron Bentley
Fix push to use clone all the time.
603
                         new_child.open_branch().get_stacked_on_url())
604
        repo = new_child.open_repository()
605
        self.assertTrue(repo._format.supports_external_lookups)
606
        self.assertFalse(repo.supports_rich_root())
607
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
608
    def test_sprout_upgrades_to_rich_root_format_if_needed(self):
609
        child_branch, new_child_transport = self.prepare_default_stacking(
610
            child_format='rich-root-pack')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
611
        new_child = child_branch.controldir.sprout(new_child_transport.base,
7143.15.2 by Jelmer Vernooij
Run autopep8.
612
                                                   stacked=True)
3650.3.10 by Aaron Bentley
Ensure that sprout chooses a rich-root format as needed
613
        repo = new_child.open_repository()
614
        self.assertTrue(repo._format.supports_external_lookups)
615
        self.assertTrue(repo.supports_rich_root())
3650.3.1 by Aaron Bentley
Ensure stacking policy does not cause format upgrades
616
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
617
    def test_add_fallback_repo_handles_absolute_urls(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
618
        stack_on = self.make_branch('stack_on', format='1.6')
619
        repo = self.make_repository('repo', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
620
        policy = bzrdir.UseExistingRepository(repo, stack_on.base)
621
        policy._add_fallback(repo)
622
623
    def test_add_fallback_repo_handles_relative_urls(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
624
        stack_on = self.make_branch('stack_on', format='1.6')
625
        repo = self.make_repository('repo', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
626
        policy = bzrdir.UseExistingRepository(repo, '.', stack_on.base)
627
        policy._add_fallback(repo)
628
629
    def test_configure_relative_branch_stacking_url(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
630
        stack_on = self.make_branch('stack_on', format='1.6')
631
        stacked = self.make_branch('stack_on/stacked', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
632
        policy = bzrdir.UseExistingRepository(stacked.repository,
7143.15.2 by Jelmer Vernooij
Run autopep8.
633
                                              '.', stack_on.base)
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
634
        policy.configure_branch(stacked)
3537.3.5 by Martin Pool
merge trunk including stacking policy
635
        self.assertEqual('..', stacked.get_stacked_on_url())
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
636
637
    def test_relative_branch_stacking_to_absolute(self):
3735.1.2 by Robert Collins
Remove 1.5 series dev formats and document development2 a little better.
638
        stack_on = self.make_branch('stack_on', format='1.6')
639
        stacked = self.make_branch('stack_on/stacked', format='1.6')
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
640
        policy = bzrdir.UseExistingRepository(stacked.repository,
7143.15.2 by Jelmer Vernooij
Run autopep8.
641
                                              '.', self.get_readonly_url('stack_on'))
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
642
        policy.configure_branch(stacked)
643
        self.assertEqual(self.get_readonly_url('stack_on'),
3537.3.5 by Martin Pool
merge trunk including stacking policy
644
                         stacked.get_stacked_on_url())
3242.3.33 by Aaron Bentley
Handle relative URL stacking cleanly
645
3242.3.4 by Aaron Bentley
Initial determination of stacking policy
646
1534.4.39 by Robert Collins
Basic BzrDir support.
647
class ChrootedTests(TestCaseWithTransport):
648
    """A support class that provides readonly urls outside the local namespace.
649
650
    This is done by checking if self.transport_server is a MemoryServer. if it
651
    is then we are chrooted already, if it is not then an HttpServer is used
652
    for readonly urls.
653
    """
654
655
    def setUp(self):
656
        super(ChrootedTests, self).setUp()
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
657
        if not self.vfs_transport_factory == memory.MemoryServer:
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
658
            self.transport_readonly_server = http_server.HttpServer
1534.4.39 by Robert Collins
Basic BzrDir support.
659
3015.3.45 by Daniel Watkins
Extract common method.
660
    def local_branch_path(self, branch):
7143.15.2 by Jelmer Vernooij
Run autopep8.
661
        return os.path.realpath(urlutils.local_path_from_url(branch.base))
3015.3.45 by Daniel Watkins
Extract common method.
662
1534.4.39 by Robert Collins
Basic BzrDir support.
663
    def test_open_containing(self):
664
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
665
                          self.get_readonly_url(''))
666
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_containing,
667
                          self.get_readonly_url('g/p/q'))
668
        control = bzrdir.BzrDir.create(self.get_url())
7143.15.2 by Jelmer Vernooij
Run autopep8.
669
        branch, relpath = bzrdir.BzrDir.open_containing(
670
            self.get_readonly_url(''))
1534.4.39 by Robert Collins
Basic BzrDir support.
671
        self.assertEqual('', relpath)
7143.15.2 by Jelmer Vernooij
Run autopep8.
672
        branch, relpath = bzrdir.BzrDir.open_containing(
673
            self.get_readonly_url('g/p/q'))
1534.4.39 by Robert Collins
Basic BzrDir support.
674
        self.assertEqual('g/p/q', relpath)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
675
3015.3.46 by Daniel Watkins
Made tests more granular.
676
    def test_open_containing_tree_branch_or_repository_empty(self):
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
677
        self.assertRaises(errors.NotBranchError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
678
                          bzrdir.BzrDir.open_containing_tree_branch_or_repository,
679
                          self.get_readonly_url(''))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
680
3015.3.46 by Daniel Watkins
Made tests more granular.
681
    def test_open_containing_tree_branch_or_repository_all(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
682
        self.make_branch_and_tree('topdir')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
683
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
684
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
685
                'topdir/foo')
686
        self.assertEqual(os.path.realpath('topdir'),
687
                         os.path.realpath(tree.basedir))
688
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
689
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
690
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
691
            osutils.realpath(os.path.join('topdir', '.bzr', 'repository')),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
692
            repo.controldir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
693
        self.assertEqual(relpath, 'foo')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
694
3015.3.46 by Daniel Watkins
Made tests more granular.
695
    def test_open_containing_tree_branch_or_repository_no_tree(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
696
        self.make_branch('branch')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
697
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
698
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
699
                'branch/foo')
700
        self.assertEqual(tree, None)
701
        self.assertEqual(os.path.realpath('branch'),
3015.3.45 by Daniel Watkins
Extract common method.
702
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
703
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
704
            osutils.realpath(os.path.join('branch', '.bzr', 'repository')),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
705
            repo.controldir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
706
        self.assertEqual(relpath, 'foo')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
707
3015.3.46 by Daniel Watkins
Made tests more granular.
708
    def test_open_containing_tree_branch_or_repository_repo(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
709
        self.make_repository('repo')
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
710
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
711
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
712
                'repo')
713
        self.assertEqual(tree, None)
714
        self.assertEqual(branch, None)
715
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
716
            osutils.realpath(os.path.join('repo', '.bzr', 'repository')),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
717
            repo.controldir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
718
        self.assertEqual(relpath, '')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
719
3015.3.46 by Daniel Watkins
Made tests more granular.
720
    def test_open_containing_tree_branch_or_repository_shared_repo(self):
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
721
        self.make_repository('shared', shared=True)
722
        bzrdir.BzrDir.create_branch_convenience('shared/branch',
723
                                                force_new_tree=False)
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
724
        tree, branch, repo, relpath = \
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
725
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
726
                'shared/branch')
727
        self.assertEqual(tree, None)
728
        self.assertEqual(os.path.realpath('shared/branch'),
3015.3.45 by Daniel Watkins
Extract common method.
729
                         self.local_branch_path(branch))
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
730
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
731
            osutils.realpath(os.path.join('shared', '.bzr', 'repository')),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
732
            repo.controldir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
733
        self.assertEqual(relpath, '')
3015.3.38 by Daniel Watkins
Added bzrlib.tests.test_bzrdir.test_open_containing_tree_branch_or_repository.
734
3015.3.48 by Daniel Watkins
Further granulated tests.
735
    def test_open_containing_tree_branch_or_repository_branch_subdir(self):
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
736
        self.make_branch_and_tree('foo')
3015.3.52 by Daniel Watkins
Replaced use of os functions with use of test suite functions.
737
        self.build_tree(['foo/bar/'])
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
738
        tree, branch, repo, relpath = \
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
739
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
740
                'foo/bar')
741
        self.assertEqual(os.path.realpath('foo'),
742
                         os.path.realpath(tree.basedir))
743
        self.assertEqual(os.path.realpath('foo'),
3015.3.45 by Daniel Watkins
Extract common method.
744
                         self.local_branch_path(branch))
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
745
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
746
            osutils.realpath(os.path.join('foo', '.bzr', 'repository')),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
747
            repo.controldir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
748
        self.assertEqual(relpath, 'bar')
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
749
3015.3.48 by Daniel Watkins
Further granulated tests.
750
    def test_open_containing_tree_branch_or_repository_repo_subdir(self):
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
751
        self.make_repository('bar')
3015.3.52 by Daniel Watkins
Replaced use of os functions with use of test suite functions.
752
        self.build_tree(['bar/baz/'])
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
753
        tree, branch, repo, relpath = \
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
754
            bzrdir.BzrDir.open_containing_tree_branch_or_repository(
755
                'bar/baz')
756
        self.assertEqual(tree, None)
757
        self.assertEqual(branch, None)
758
        self.assertEqual(
3616.2.12 by Mark Hammond
use osutils.realpath instead of os.path.realpath so we get fwd slashes.
759
            osutils.realpath(os.path.join('bar', '.bzr', 'repository')),
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
760
            repo.controldir.transport.local_abspath('repository'))
3015.3.57 by Daniel Watkins
Made changes to BzrDir.open_containing_tree_branch_or_repository suggested on list.
761
        self.assertEqual(relpath, 'baz')
3015.3.42 by Daniel Watkins
Added test to ensure that BzrDir.open_containing_tree_branch_or_repository will open containing versioned directories of unversioned subdirectories.
762
1534.6.11 by Robert Collins
Review feedback.
763
    def test_open_containing_from_transport(self):
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
764
        self.assertRaises(NotBranchError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
765
                          bzrdir.BzrDir.open_containing_from_transport,
766
                          _mod_transport.get_transport_from_url(self.get_readonly_url('')))
5609.9.1 by Martin
Blindly change all users of get_transport to address the function via the transport module
767
        self.assertRaises(NotBranchError,
7143.15.2 by Jelmer Vernooij
Run autopep8.
768
                          bzrdir.BzrDir.open_containing_from_transport,
769
                          _mod_transport.get_transport_from_url(
770
                              self.get_readonly_url('g/p/q')))
1534.6.3 by Robert Collins
find_repository sufficiently robust.
771
        control = bzrdir.BzrDir.create(self.get_url())
1534.6.11 by Robert Collins
Review feedback.
772
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
773
            _mod_transport.get_transport_from_url(
774
                self.get_readonly_url('')))
1534.6.3 by Robert Collins
find_repository sufficiently robust.
775
        self.assertEqual('', relpath)
1534.6.11 by Robert Collins
Review feedback.
776
        branch, relpath = bzrdir.BzrDir.open_containing_from_transport(
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
777
            _mod_transport.get_transport_from_url(
778
                self.get_readonly_url('g/p/q')))
1534.6.3 by Robert Collins
find_repository sufficiently robust.
779
        self.assertEqual('g/p/q', relpath)
780
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
781
    def test_open_containing_tree_or_branch(self):
782
        self.make_branch_and_tree('topdir')
783
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
784
            'topdir/foo')
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
785
        self.assertEqual(os.path.realpath('topdir'),
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
786
                         os.path.realpath(tree.basedir))
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
787
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
788
                         self.local_branch_path(branch))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
789
        self.assertIs(tree.controldir, branch.controldir)
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
790
        self.assertEqual('foo', relpath)
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
791
        # opening from non-local should not return the tree
792
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
793
            self.get_readonly_url('topdir/foo'))
794
        self.assertEqual(None, tree)
795
        self.assertEqual('foo', relpath)
796
        # without a tree:
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
797
        self.make_branch('topdir/foo')
798
        tree, branch, relpath = bzrdir.BzrDir.open_containing_tree_or_branch(
799
            'topdir/foo')
800
        self.assertIs(tree, None)
2215.3.7 by Aaron Bentley
Remove (new) trailing whitespace
801
        self.assertEqual(os.path.realpath('topdir/foo'),
3015.3.45 by Daniel Watkins
Extract common method.
802
                         self.local_branch_path(branch))
2215.3.2 by Aaron Bentley
Add open_containing_tree_or_branch
803
        self.assertEqual('', relpath)
804
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
805
    def test_open_tree_or_branch(self):
806
        self.make_branch_and_tree('topdir')
807
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir')
808
        self.assertEqual(os.path.realpath('topdir'),
809
                         os.path.realpath(tree.basedir))
810
        self.assertEqual(os.path.realpath('topdir'),
3015.3.45 by Daniel Watkins
Extract common method.
811
                         self.local_branch_path(branch))
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
812
        self.assertIs(tree.controldir, branch.controldir)
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
813
        # opening from non-local should not return the tree
3123.5.15 by Aaron Bentley
Fix open_tree_or_branch tests
814
        tree, branch = bzrdir.BzrDir.open_tree_or_branch(
815
            self.get_readonly_url('topdir'))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
816
        self.assertEqual(None, tree)
817
        # without a tree:
818
        self.make_branch('topdir/foo')
3123.5.15 by Aaron Bentley
Fix open_tree_or_branch tests
819
        tree, branch = bzrdir.BzrDir.open_tree_or_branch('topdir/foo')
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
820
        self.assertIs(tree, None)
821
        self.assertEqual(os.path.realpath('topdir/foo'),
3015.3.45 by Daniel Watkins
Extract common method.
822
                         self.local_branch_path(branch))
3123.5.11 by Aaron Bentley
Accelerate branching from a lightweight checkout
823
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
824
    def test_open_from_transport(self):
825
        # transport pointing at bzrdir should give a bzrdir with root transport
826
        # set to the given transport
827
        control = bzrdir.BzrDir.create(self.get_url())
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
828
        t = self.get_transport()
829
        opened_bzrdir = bzrdir.BzrDir.open_from_transport(t)
830
        self.assertEqual(t.base, opened_bzrdir.root_transport.base)
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
831
        self.assertIsInstance(opened_bzrdir, bzrdir.BzrDir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
832
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
833
    def test_open_from_transport_no_bzrdir(self):
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
834
        t = self.get_transport()
835
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
836
837
    def test_open_from_transport_bzrdir_in_parent(self):
838
        control = bzrdir.BzrDir.create(self.get_url())
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
839
        t = self.get_transport()
840
        t.mkdir('subdir')
841
        t = t.clone('subdir')
842
        self.assertRaises(NotBranchError, bzrdir.BzrDir.open_from_transport, t)
1910.11.5 by Andrew Bennetts
Add tests for BzrDir.open_from_transport.
843
2100.3.28 by Aaron Bentley
Make sprout recursive
844
    def test_sprout_recursive(self):
7447.3.1 by Jelmer Vernooij
Move tree reference info functions to workingtree.
845
        tree = self.make_branch_and_tree('tree1')
846
        sub_tree = self.make_branch_and_tree('tree1/subtree')
6855.4.1 by Jelmer Vernooij
Yet more bees.
847
        sub_tree.set_root_id(b'subtree-root')
2100.3.28 by Aaron Bentley
Make sprout recursive
848
        tree.add_reference(sub_tree)
7447.3.4 by Jelmer Vernooij
Fix tests.
849
        tree.set_reference_info('subtree', sub_tree.branch.user_url)
2100.3.28 by Aaron Bentley
Make sprout recursive
850
        self.build_tree(['tree1/subtree/file'])
851
        sub_tree.add('file')
852
        tree.commit('Initial commit')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
853
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
4100.2.4 by Aaron Bentley
More support for not autodetecting tree refs
854
        tree2.lock_read()
855
        self.addCleanup(tree2.unlock)
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
856
        self.assertPathExists('tree2/subtree/file')
7141.7.1 by Jelmer Vernooij
Get rid of file_ids in most of Tree.
857
        self.assertEqual('tree-reference', tree2.kind('subtree'))
2100.3.28 by Aaron Bentley
Make sprout recursive
858
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
859
    def test_cloning_metadir(self):
860
        """Ensure that cloning metadir is suitable"""
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
861
        bzrdir = self.make_controldir('bzrdir')
2100.3.34 by Aaron Bentley
Fix BzrDir.cloning_metadir with no format
862
        bzrdir.cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
863
        branch = self.make_branch('branch', format='knit')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
864
        format = branch.controldir.cloning_metadir()
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
865
        self.assertIsInstance(format.workingtree_format,
7143.15.2 by Jelmer Vernooij
Run autopep8.
866
                              workingtree_4.WorkingTreeFormat6)
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
867
868
    def test_sprout_recursive_treeless(self):
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
869
        tree = self.make_branch_and_tree('tree1',
7143.15.2 by Jelmer Vernooij
Run autopep8.
870
                                         format='development-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
871
        sub_tree = self.make_branch_and_tree('tree1/subtree',
7143.15.2 by Jelmer Vernooij
Run autopep8.
872
                                             format='development-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
873
        tree.add_reference(sub_tree)
7447.3.4 by Jelmer Vernooij
Fix tests.
874
        tree.set_reference_info('subtree', sub_tree.branch.user_url)
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
875
        self.build_tree(['tree1/subtree/file'])
876
        sub_tree.add('file')
877
        tree.commit('Initial commit')
5409.1.20 by Vincent Ladeuil
Revert to 'conflict' being the default orphaning policy and fix fallouts.
878
        # The following line force the orhaning to reveal bug #634470
7447.4.2 by Jelmer Vernooij
Merge tree reference fixes.
879
        tree.branch.get_config_stack().set('transform.orphan_policy', 'move')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
880
        tree.controldir.destroy_workingtree()
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
881
        # FIXME: subtree/.bzr is left here which allows the test to pass (or
882
        # fail :-( ) -- vila 20100909
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
883
        repo = self.make_repository('repo', shared=True,
7143.15.2 by Jelmer Vernooij
Run autopep8.
884
                                    format='development-subtree')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
885
        repo.set_make_working_trees(False)
5409.1.7 by Vincent Ladeuil
First orphaning implementation (some tests lacking).
886
        # FIXME: we just deleted the workingtree and now we want to use it ????
887
        # At a minimum, we should use tree.branch below (but this fails too
888
        # currently) or stop calling this test 'treeless'. Specifically, I've
889
        # turn the line below into an assertRaises when 'subtree/.bzr' is
890
        # orphaned and sprout tries to access the branch there (which is left
891
        # by bzrdir.BzrDirMeta1.destroy_workingtree when it ignores the
5409.7.2 by Vincent Ladeuil
Add NEWS entry, a missing test and some cleanup.
892
        # [DeletingParent('Not deleting', u'subtree', None)] conflict). See bug
893
        # #634470.  -- vila 20100909
7404.3.1 by Jelmer Vernooij
Add follow_tree_references argument to Tree.iter_entries_by_dir.
894
        tree.controldir.sprout('repo/tree2')
895
        self.assertPathExists('repo/tree2/subtree')
896
        self.assertPathDoesNotExist('repo/tree2/subtree/file')
2100.3.32 by Aaron Bentley
fix tree format, basis_tree call, in sprout
897
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
898
    def make_foo_bar_baz(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
899
        foo = bzrdir.BzrDir.create_branch_convenience('foo').controldir
900
        bar = self.make_branch('foo/bar').controldir
901
        baz = self.make_branch('baz').controldir
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
902
        return foo, bar, baz
903
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
904
    def test_find_controldirs(self):
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
905
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
906
        t = self.get_transport()
7143.15.2 by Jelmer Vernooij
Run autopep8.
907
        self.assertEqualBzrdirs(
908
            [baz, foo, bar], bzrdir.BzrDir.find_controldirs(t))
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
909
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
910
    def make_fake_permission_denied_transport(self, transport, paths):
5215.3.9 by Marius Kruger
* Tried to improve code docs and NEWS as per review
911
        """Create a transport that raises PermissionDenied for some paths."""
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
912
        def filter(path):
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
913
            if path in paths:
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
914
                raise errors.PermissionDenied(path)
915
            return path
916
        path_filter_server = pathfilter.PathFilteringServer(transport, filter)
917
        path_filter_server.start_server()
5215.3.9 by Marius Kruger
* Tried to improve code docs and NEWS as per review
918
        self.addCleanup(path_filter_server.stop_server)
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
919
        path_filter_transport = pathfilter.PathFilteringTransport(
920
            path_filter_server, '.')
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
921
        return (path_filter_server, path_filter_transport)
922
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
923
    def assertBranchUrlsEndWith(self, expect_url_suffix, actual_bzrdirs):
924
        """Check that each branch url ends with the given suffix."""
925
        for actual_bzrdir in actual_bzrdirs:
5215.3.5 by Marius Kruger
factor out _assert_branch_urls
926
            self.assertEndsWith(actual_bzrdir.user_url, expect_url_suffix)
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
927
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
928
    def test_find_controldirs_permission_denied(self):
5215.3.4 by Marius Kruger
extract make_fake_permission_denied_transport and standardise the assert urls a little
929
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
930
        t = self.get_transport()
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
931
        path_filter_server, path_filter_transport = \
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
932
            self.make_fake_permission_denied_transport(t, ['foo'])
5215.3.5 by Marius Kruger
factor out _assert_branch_urls
933
        # local transport
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
934
        self.assertBranchUrlsEndWith('/baz/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
935
                                     bzrdir.BzrDir.find_controldirs(path_filter_transport))
5215.3.2 by Marius Kruger
* Move TestCaseWithMemoryTransport.make_smart_server => TestCaseWithTransport
936
        # smart server
937
        smart_transport = self.make_smart_server('.',
7143.15.2 by Jelmer Vernooij
Run autopep8.
938
                                                 backing_server=path_filter_server)
5215.3.10 by Robert Collins
Merge trunk, adjusting NEWS and fixing up the permission denied test to be clearer and more focused.
939
        self.assertBranchUrlsEndWith('/baz/',
7143.15.2 by Jelmer Vernooij
Run autopep8.
940
                                     bzrdir.BzrDir.find_controldirs(smart_transport))
5215.4.1 by Marius Kruger
BzrDir.find_branches should not fall over when encountering branches with missing repos
941
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
942
    def test_find_controldirs_list_current(self):
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
943
        def list_current(transport):
944
            return [s for s in transport.list_dir('') if s != 'baz']
945
946
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
947
        t = self.get_transport()
948
        self.assertEqualBzrdirs(
949
            [foo, bar],
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
950
            bzrdir.BzrDir.find_controldirs(t, list_current=list_current))
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
951
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
952
    def test_find_controldirs_evaluate(self):
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
953
        def evaluate(bzrdir):
954
            try:
955
                repo = bzrdir.open_repository()
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
956
            except errors.NoRepositoryPresent:
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
957
                return True, bzrdir.root_transport.base
958
            else:
959
                return False, bzrdir.root_transport.base
960
961
        foo, bar, baz = self.make_foo_bar_baz()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
962
        t = self.get_transport()
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
963
        self.assertEqual([baz.root_transport.base, foo.root_transport.base],
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
964
                         list(bzrdir.BzrDir.find_controldirs(t, evaluate=evaluate)))
3140.1.1 by Aaron Bentley
Implement find_bzrdir functionality
965
966
    def assertEqualBzrdirs(self, first, second):
967
        first = list(first)
968
        second = list(second)
969
        self.assertEqual(len(first), len(second))
970
        for x, y in zip(first, second):
971
            self.assertEqual(x.root_transport.base, y.root_transport.base)
972
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
973
    def test_find_branches(self):
974
        root = self.make_repository('', shared=True)
975
        foo, bar, baz = self.make_foo_bar_baz()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
976
        qux = self.make_controldir('foo/qux')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
977
        t = self.get_transport()
978
        branches = bzrdir.BzrDir.find_branches(t)
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
979
        self.assertEqual(baz.root_transport.base, branches[0].base)
980
        self.assertEqual(foo.root_transport.base, branches[1].base)
981
        self.assertEqual(bar.root_transport.base, branches[2].base)
982
983
        # ensure this works without a top-level repo
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
984
        branches = bzrdir.BzrDir.find_branches(t.clone('foo'))
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
985
        self.assertEqual(foo.root_transport.base, branches[0].base)
986
        self.assertEqual(bar.root_transport.base, branches[1].base)
987
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
988
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
989
class TestMissingRepoBranchesSkipped(TestCaseWithMemoryTransport):
990
6681.2.3 by Jelmer Vernooij
Rename find_bzrdir.
991
    def test_find_controldirs_missing_repo(self):
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
992
        t = self.get_transport()
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
993
        arepo = self.make_repository('arepo', shared=True)
994
        abranch_url = arepo.user_url + '/abranch'
995
        abranch = bzrdir.BzrDir.create(abranch_url).create_branch()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
996
        t.delete_tree('arepo/.bzr')
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
997
        self.assertRaises(errors.NoRepositoryPresent,
7143.15.2 by Jelmer Vernooij
Run autopep8.
998
                          branch.Branch.open, abranch_url)
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
999
        self.make_branch('baz')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1000
        for actual_bzrdir in bzrdir.BzrDir.find_branches(t):
5215.4.4 by Robert Collins
Merge prerequisite branch and tweak test to be more compact and faster.
1001
            self.assertEndsWith(actual_bzrdir.user_url, '/baz/')
1002
1003
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1004
class TestMeta1DirFormat(TestCaseWithTransport):
1005
    """Tests specific to the meta1 dir format."""
1006
1007
    def test_right_base_dirs(self):
1008
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
1009
        t = dir.transport
1010
        branch_base = t.clone('branch').base
1011
        self.assertEqual(branch_base, dir.get_branch_transport(None).base)
1012
        self.assertEqual(branch_base,
6517.1.6 by Jelmer Vernooij
Fix remaining tests.
1013
                         dir.get_branch_transport(BzrBranchFormat5()).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1014
        repository_base = t.clone('repository').base
7143.15.2 by Jelmer Vernooij
Run autopep8.
1015
        self.assertEqual(
1016
            repository_base, dir.get_repository_transport(None).base)
5669.1.2 by Jelmer Vernooij
Review comments from Vincent.
1017
        repository_format = repository.format_registry.get_default()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1018
        self.assertEqual(repository_base,
5669.1.1 by Jelmer Vernooij
Remove some dependencies on weave formats from bt.test_bzrdir.
1019
                         dir.get_repository_transport(repository_format).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1020
        checkout_base = t.clone('checkout').base
7143.15.2 by Jelmer Vernooij
Run autopep8.
1021
        self.assertEqual(
1022
            checkout_base, dir.get_workingtree_transport(None).base)
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1023
        self.assertEqual(checkout_base,
5816.5.4 by Jelmer Vernooij
Merge bzr.dev.
1024
                         dir.get_workingtree_transport(workingtree_3.WorkingTreeFormat3()).base)
1534.5.3 by Robert Collins
Make format 4/5/6 branches share a single LockableFiles instance across wt/branch/repository.
1025
1553.5.69 by Martin Pool
BzrDirFormat subclasses can now control what kind of overall lock is used.
1026
    def test_meta1dir_uses_lockdir(self):
1027
        """Meta1 format uses a LockDir to guard the whole directory, not a file."""
1028
        dir = bzrdir.BzrDirMetaFormat1().initialize(self.get_url())
1029
        t = dir.transport
1030
        self.assertIsDirectory('branch-lock', t)
1031
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1032
    def test_comparison(self):
1033
        """Equality and inequality behave properly.
1034
1035
        Metadirs should compare equal iff they have the same repo, branch and
1036
        tree formats.
1037
        """
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1038
        mydir = controldir.format_registry.make_controldir('knit')
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1039
        self.assertEqual(mydir, mydir)
1040
        self.assertFalse(mydir != mydir)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1041
        otherdir = controldir.format_registry.make_controldir('knit')
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1042
        self.assertEqual(otherdir, mydir)
1043
        self.assertFalse(otherdir != mydir)
7143.15.2 by Jelmer Vernooij
Run autopep8.
1044
        otherdir2 = controldir.format_registry.make_controldir(
1045
            'development-subtree')
2100.3.35 by Aaron Bentley
equality operations on bzrdir
1046
        self.assertNotEqual(otherdir2, mydir)
1047
        self.assertFalse(otherdir2 == mydir)
1048
6213.1.8 by Jelmer Vernooij
Support loading directories with featurs.
1049
    def test_with_features(self):
1050
        tree = self.make_branch_and_tree('tree', format='2a')
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1051
        tree.controldir.update_feature_flags({b"bar": b"required"})
6731.1.3 by Jelmer Vernooij
Move MissingFeature error to breezy.bzr.bzrdir.
1052
        self.assertRaises(bzrdir.MissingFeature, bzrdir.BzrDir.open, 'tree')
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1053
        bzrdir.BzrDirMetaFormat1.register_feature(b'bar')
1054
        self.addCleanup(bzrdir.BzrDirMetaFormat1.unregister_feature, b'bar')
6213.1.8 by Jelmer Vernooij
Support loading directories with featurs.
1055
        dir = bzrdir.BzrDir.open('tree')
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1056
        self.assertEqual(b"required", dir._format.features.get(b"bar"))
1057
        tree.controldir.update_feature_flags({
1058
            b"bar": None,
1059
            b"nonexistant": None})
6213.1.56 by Jelmer Vernooij
Add BzrDir.update_feature_flags.
1060
        dir = bzrdir.BzrDir.open('tree')
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1061
        self.assertEqual({}, dir._format.features)
6213.1.8 by Jelmer Vernooij
Support loading directories with featurs.
1062
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1063
    def test_needs_conversion_different_working_tree(self):
1064
        # meta1dirs need an conversion if any element is not the default.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1065
        new_format = controldir.format_registry.make_controldir('dirstate')
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1066
        tree = self.make_branch_and_tree('tree', format='knit')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1067
        self.assertTrue(tree.controldir.needs_format_conversion(
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1068
            new_format))
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1069
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
1070
    def test_initialize_on_format_uses_smart_transport(self):
1071
        self.setup_smart_server_with_call_log()
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1072
        new_format = controldir.format_registry.make_controldir('dirstate')
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
1073
        transport = self.get_transport('target')
1074
        transport.ensure_base()
1075
        self.reset_smart_call_log()
1076
        instance = new_format.initialize_on_transport(transport)
1077
        self.assertIsInstance(instance, remote.RemoteBzrDir)
1078
        rpc_count = len(self.hpss_calls)
1079
        # This figure represent the amount of work to perform this use case. It
1080
        # is entirely ok to reduce this number if a test fails due to rpc_count
1081
        # being too low. If rpc_count increases, more network roundtrips have
1082
        # become necessary for this use case. Please do not adjust this number
1083
        # upwards without agreement from bzr's network support maintainers.
4017.2.2 by Robert Collins
Perform creation of BzrDirMetaFormat1 control directories using an RPC where possible. (Robert Collins)
1084
        self.assertEqual(2, rpc_count)
4017.2.1 by Robert Collins
Add BzrDirFormatMeta1 test for the amount of rpc calls made initializing over the network.
1085
2255.12.1 by Robert Collins
Implement upgrade for working trees.
1086
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
1087
class NonLocalTests(TestCaseWithTransport):
1088
    """Tests for bzrdir static behaviour on non local paths."""
1089
1090
    def setUp(self):
1091
        super(NonLocalTests, self).setUp()
5017.3.45 by Vincent Ladeuil
Move MemoryServer back into bzrlib.transport.memory as it's needed as soon as a MemoryTransport is used. Add a NEWS entry.
1092
        self.vfs_transport_factory = memory.MemoryServer
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1093
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
1094
    def test_create_branch_convenience(self):
1095
        # outside a repo the default convenience output is a repo+branch_tree
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1096
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1097
        branch = bzrdir.BzrDir.create_branch_convenience(
1098
            self.get_url('foo'), format=format)
1099
        self.assertRaises(errors.NoWorkingTree,
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1100
                          branch.controldir.open_workingtree)
1101
        branch.controldir.open_repository()
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
1102
1103
    def test_create_branch_convenience_force_tree_not_local_fails(self):
1104
        # outside a repo the default convenience output is a repo+branch_tree
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1105
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1106
        self.assertRaises(errors.NotLocalUrl,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1107
                          bzrdir.BzrDir.create_branch_convenience,
1108
                          self.get_url('foo'),
1109
                          force_new_tree=True,
1110
                          format=format)
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1111
        t = self.get_transport()
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1112
        self.assertFalse(t.has('foo'))
1563.1.6 by Robert Collins
Add tests for sftp push, and NonLocalTets for BzrDir.create_branch_convenience, before fixing the failure of it to work on non-local urls.
1113
1563.2.38 by Robert Collins
make push preserve tree formats.
1114
    def test_clone(self):
1115
        # clone into a nonlocal path works
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
1116
        format = controldir.format_registry.make_controldir('knit')
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1117
        branch = bzrdir.BzrDir.create_branch_convenience('local',
1118
                                                         format=format)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1119
        branch.controldir.open_workingtree()
1120
        result = branch.controldir.clone(self.get_url('remote'))
1563.2.38 by Robert Collins
make push preserve tree formats.
1121
        self.assertRaises(errors.NoWorkingTree,
1122
                          result.open_workingtree)
1123
        result.open_branch()
1124
        result.open_repository()
1125
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
1126
    def test_checkout_metadir(self):
1127
        # checkout_metadir has reasonable working tree format even when no
1128
        # working tree is present
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
1129
        self.make_branch('branch-knit2', format='dirstate-with-subtree')
2100.3.21 by Aaron Bentley
Work on checking out by-reference trees
1130
        my_bzrdir = bzrdir.BzrDir.open(self.get_url('branch-knit2'))
1131
        checkout_format = my_bzrdir.checkout_metadir()
1132
        self.assertIsInstance(checkout_format.workingtree_format,
5816.5.7 by Jelmer Vernooij
Fix more imports.
1133
                              workingtree_4.WorkingTreeFormat4)
2100.3.22 by Aaron Bentley
merge from bzr.dev
1134
2215.3.5 by Aaron Bentley
Add support for remote ls
1135
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1136
class TestHTTPRedirectionsBase(object):
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1137
    """Test redirection between two http servers.
2164.2.16 by Vincent Ladeuil
Add tests.
1138
1139
    This MUST be used by daughter classes that also inherit from
1140
    TestCaseWithTwoWebservers.
1141
1142
    We can't inherit directly from TestCaseWithTwoWebservers or the
1143
    test framework will try to create an instance which cannot
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1144
    run, its implementation being incomplete.
2164.2.16 by Vincent Ladeuil
Add tests.
1145
    """
1146
1147
    def create_transport_readonly_server(self):
5273.1.4 by Vincent Ladeuil
The default http protocol version wasn't properly defined and as such not respected by some parametrized tests.
1148
        # We don't set the http protocol version, relying on the default
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1149
        return http_utils.HTTPServerRedirecting()
2164.2.16 by Vincent Ladeuil
Add tests.
1150
1151
    def create_transport_secondary_server(self):
5273.1.4 by Vincent Ladeuil
The default http protocol version wasn't properly defined and as such not respected by some parametrized tests.
1152
        # We don't set the http protocol version, relying on the default
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1153
        return http_utils.HTTPServerRedirecting()
2164.2.16 by Vincent Ladeuil
Add tests.
1154
1155
    def setUp(self):
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1156
        super(TestHTTPRedirectionsBase, self).setUp()
2164.2.16 by Vincent Ladeuil
Add tests.
1157
        # The redirections will point to the new server
1158
        self.new_server = self.get_readonly_server()
1159
        # The requests to the old server will be redirected
1160
        self.old_server = self.get_secondary_server()
1161
        # Configure the redirections
1162
        self.old_server.redirect_to(self.new_server.host, self.new_server.port)
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1163
1164
    def test_loop(self):
1165
        # Both servers redirect to each other creating a loop
2164.2.16 by Vincent Ladeuil
Add tests.
1166
        self.new_server.redirect_to(self.old_server.host, self.old_server.port)
1167
        # Starting from either server should loop
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1168
        old_url = self._qualified_url(self.old_server.host,
2164.2.16 by Vincent Ladeuil
Add tests.
1169
                                      self.old_server.port)
1170
        oldt = self._transport(old_url)
1171
        self.assertRaises(errors.NotBranchError,
1172
                          bzrdir.BzrDir.open_from_transport, oldt)
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1173
        new_url = self._qualified_url(self.new_server.host,
2164.2.16 by Vincent Ladeuil
Add tests.
1174
                                      self.new_server.port)
1175
        newt = self._transport(new_url)
1176
        self.assertRaises(errors.NotBranchError,
1177
                          bzrdir.BzrDir.open_from_transport, newt)
1178
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1179
    def test_qualifier_preserved(self):
1180
        wt = self.make_branch_and_tree('branch')
1181
        old_url = self._qualified_url(self.old_server.host,
1182
                                      self.old_server.port)
1183
        start = self._transport(old_url).clone('branch')
1184
        bdir = bzrdir.BzrDir.open_from_transport(start)
1185
        # Redirection should preserve the qualifier, hence the transport class
1186
        # itself.
1187
        self.assertIsInstance(bdir.root_transport, type(start))
1188
1189
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1190
class TestHTTPRedirections(TestHTTPRedirectionsBase,
1191
                           http_utils.TestCaseWithTwoWebservers):
2164.2.16 by Vincent Ladeuil
Add tests.
1192
    """Tests redirections for urllib implementation"""
1193
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1194
    _transport = HttpTransport
2164.2.16 by Vincent Ladeuil
Add tests.
1195
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1196
    def _qualified_url(self, host, port):
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1197
        result = 'http://%s:%s' % (host, port)
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1198
        self.permit_url(result)
1199
        return result
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1200
2164.2.16 by Vincent Ladeuil
Add tests.
1201
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1202
class TestHTTPRedirections_nosmart(TestHTTPRedirectionsBase,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1203
                                   http_utils.TestCaseWithTwoWebservers):
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1204
    """Tests redirections for the nosmart decorator"""
1205
1206
    _transport = NoSmartTransportDecorator
1207
1208
    def _qualified_url(self, host, port):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1209
        result = 'nosmart+http://%s:%s' % (host, port)
1210
        self.permit_url(result)
1211
        return result
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1212
1213
6929.11.2 by Jelmer Vernooij
Integrate the urllib HTTP implementation into HttpTransport.
1214
class TestHTTPRedirections_readonly(TestHTTPRedirectionsBase,
3878.4.1 by Vincent Ladeuil
Fix bug #245964 by preserving decorators during redirections (when
1215
                                    http_utils.TestCaseWithTwoWebservers):
1216
    """Tests redirections for readonly decoratror"""
1217
1218
    _transport = ReadonlyTransportDecorator
1219
1220
    def _qualified_url(self, host, port):
4691.2.1 by Robert Collins
Add stronger test isolation by interception BzrDir.open and checking the thing being opened is known to the test suite.
1221
        result = 'readonly+http://%s:%s' % (host, port)
1222
        self.permit_url(result)
1223
        return result
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1224
1225
1226
class TestDotBzrHidden(TestCaseWithTransport):
1227
3023.1.3 by Alexander Belchenko
John's review
1228
    ls = ['ls']
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1229
    if sys.platform == 'win32':
3023.1.3 by Alexander Belchenko
John's review
1230
        ls = [os.environ['COMSPEC'], '/C', 'dir', '/B']
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1231
1232
    def get_ls(self):
3023.1.3 by Alexander Belchenko
John's review
1233
        f = subprocess.Popen(self.ls, stdout=subprocess.PIPE,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1234
                             stderr=subprocess.PIPE)
3023.1.3 by Alexander Belchenko
John's review
1235
        out, err = f.communicate()
1236
        self.assertEqual(0, f.returncode, 'Calling %s failed: %s'
1237
                         % (self.ls, err))
1238
        return out.splitlines()
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1239
1240
    def test_dot_bzr_hidden(self):
1241
        b = bzrdir.BzrDir.create('.')
3044.1.1 by Martin Pool
Fix up calls to TestCase.build_tree passing a string rather than a list
1242
        self.build_tree(['a'])
7058.4.13 by Jelmer Vernooij
Fix test_bzrdir tests.
1243
        self.assertEqual([b'a'], self.get_ls())
3023.1.1 by Alexander Belchenko
Mark .bzr directories as "hidden" on Windows (#71147)
1244
1245
    def test_dot_bzr_hidden_with_url(self):
1246
        b = bzrdir.BzrDir.create(urlutils.local_path_to_url('.'))
3044.1.1 by Martin Pool
Fix up calls to TestCase.build_tree passing a string rather than a list
1247
        self.build_tree(['a'])
7058.4.13 by Jelmer Vernooij
Fix test_bzrdir tests.
1248
        self.assertEqual([b'a'], self.get_ls())
3583.1.2 by Andrew Bennetts
Add test for fix.
1249
1250
1251
class _TestBzrDirFormat(bzrdir.BzrDirMetaFormat1):
1252
    """Test BzrDirFormat implementation for TestBzrDirSprout."""
1253
1254
    def _open(self, transport):
1255
        return _TestBzrDir(transport, self)
1256
1257
1258
class _TestBzrDir(bzrdir.BzrDirMeta1):
1259
    """Test BzrDir implementation for TestBzrDirSprout.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1260
3583.1.2 by Andrew Bennetts
Add test for fix.
1261
    When created a _TestBzrDir already has repository and a branch.  The branch
1262
    is a test double as well.
1263
    """
1264
1265
    def __init__(self, *args, **kwargs):
1266
        super(_TestBzrDir, self).__init__(*args, **kwargs)
6015.15.7 by John Arbash Meinel
Fix the 11 tests that still failed.
1267
        self.test_branch = _TestBranch(self.transport)
3583.1.2 by Andrew Bennetts
Add test for fix.
1268
        self.test_branch.repository = self.create_repository()
1269
6305.3.4 by Jelmer Vernooij
Add possible_transports in a couple more places.
1270
    def open_branch(self, unsupported=False, possible_transports=None):
3583.1.2 by Andrew Bennetts
Add test for fix.
1271
        return self.test_branch
1272
3650.3.13 by Aaron Bentley
Make cloning_metadir handle stacking requirements
1273
    def cloning_metadir(self, require_stacking=False):
3583.1.2 by Andrew Bennetts
Add test for fix.
1274
        return _TestBzrDirFormat()
1275
1276
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1277
class _TestBranchFormat(breezy.branch.BranchFormat):
4086.1.3 by Andrew Bennetts
Fix bzrlib.tests.test_bzrdir.
1278
    """Test Branch format for TestBzrDirSprout."""
1279
1280
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
1281
class _TestBranch(breezy.branch.Branch):
3583.1.2 by Andrew Bennetts
Add test for fix.
1282
    """Test Branch implementation for TestBzrDirSprout."""
1283
6015.15.7 by John Arbash Meinel
Fix the 11 tests that still failed.
1284
    def __init__(self, transport, *args, **kwargs):
4086.1.3 by Andrew Bennetts
Fix bzrlib.tests.test_bzrdir.
1285
        self._format = _TestBranchFormat()
6015.15.7 by John Arbash Meinel
Fix the 11 tests that still failed.
1286
        self._transport = transport
1287
        self.base = transport.base
3583.1.2 by Andrew Bennetts
Add test for fix.
1288
        super(_TestBranch, self).__init__(*args, **kwargs)
1289
        self.calls = []
3650.3.7 by Aaron Bentley
Fix test
1290
        self._parent = None
1291
3583.1.2 by Andrew Bennetts
Add test for fix.
1292
    def sprout(self, *args, **kwargs):
1293
        self.calls.append('sprout')
6015.15.7 by John Arbash Meinel
Fix the 11 tests that still failed.
1294
        return _TestBranch(self._transport)
3583.1.2 by Andrew Bennetts
Add test for fix.
1295
3650.3.4 by Aaron Bentley
Update test to permit calling copy_content_into
1296
    def copy_content_into(self, destination, revision_id=None):
1297
        self.calls.append('copy_content_into')
1298
5535.4.15 by Andrew Bennetts
Fix a test failure.
1299
    def last_revision(self):
1300
        return _mod_revision.NULL_REVISION
1301
3650.3.7 by Aaron Bentley
Fix test
1302
    def get_parent(self):
1303
        return self._parent
1304
6015.15.7 by John Arbash Meinel
Fix the 11 tests that still failed.
1305
    def _get_config(self):
1306
        return config.TransportConfig(self._transport, 'branch.conf')
1307
6404.1.2 by Vincent Ladeuil
Fix failing test
1308
    def _get_config_store(self):
1309
        return config.BranchStore(self)
1310
3650.3.7 by Aaron Bentley
Fix test
1311
    def set_parent(self, parent):
1312
        self._parent = parent
1313
5535.3.9 by Andrew Bennetts
Fix test failures.
1314
    def lock_read(self):
1315
        return lock.LogicalLockResult(self.unlock)
1316
1317
    def unlock(self):
1318
        return
1319
3583.1.2 by Andrew Bennetts
Add test for fix.
1320
1321
class TestBzrDirSprout(TestCaseWithMemoryTransport):
1322
1323
    def test_sprout_uses_branch_sprout(self):
1324
        """BzrDir.sprout calls Branch.sprout.
1325
1326
        Usually, BzrDir.sprout should delegate to the branch's sprout method
1327
        for part of the work.  This allows the source branch to control the
1328
        choice of format for the new branch.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1329
3583.1.2 by Andrew Bennetts
Add test for fix.
1330
        There are exceptions, but this tests avoids them:
1331
          - if there's no branch in the source bzrdir,
1332
          - or if the stacking has been requested and the format needs to be
1333
            overridden to satisfy that.
1334
        """
1335
        # Make an instrumented bzrdir.
1336
        t = self.get_transport('source')
1337
        t.ensure_base()
1338
        source_bzrdir = _TestBzrDirFormat().initialize_on_transport(t)
1339
        # The instrumented bzrdir has a test_branch attribute that logs calls
1340
        # made to the branch contained in that bzrdir.  Initially the test
1341
        # branch exists but no calls have been made to it.
1342
        self.assertEqual([], source_bzrdir.test_branch.calls)
1343
1344
        # Sprout the bzrdir
1345
        target_url = self.get_url('target')
1346
        result = source_bzrdir.sprout(target_url, recurse='no')
1347
1348
        # The bzrdir called the branch's sprout method.
3650.3.4 by Aaron Bentley
Update test to permit calling copy_content_into
1349
        self.assertSubset(['sprout'], source_bzrdir.test_branch.calls)
3650.3.5 by Aaron Bentley
Fix parent location when copying content
1350
1351
    def test_sprout_parent(self):
1352
        grandparent_tree = self.make_branch('grandparent')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1353
        parent = grandparent_tree.controldir.sprout('parent').open_branch()
1354
        branch_tree = parent.controldir.sprout('branch').open_branch()
3650.3.5 by Aaron Bentley
Fix parent location when copying content
1355
        self.assertContainsRe(branch_tree.get_parent(), '/parent/$')
4160.1.1 by Robert Collins
Add a BzrDir.pre_open hook for use by the smart server gaol.
1356
1357
1358
class TestBzrDirHooks(TestCaseWithMemoryTransport):
1359
1360
    def test_pre_open_called(self):
1361
        calls = []
1362
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', calls.append, None)
1363
        transport = self.get_transport('foo')
1364
        url = transport.base
1365
        self.assertRaises(errors.NotBranchError, bzrdir.BzrDir.open, url)
1366
        self.assertEqual([transport.base], [t.base for t in calls])
1367
1368
    def test_pre_open_actual_exceptions_raised(self):
1369
        count = [0]
7143.15.2 by Jelmer Vernooij
Run autopep8.
1370
4160.1.1 by Robert Collins
Add a BzrDir.pre_open hook for use by the smart server gaol.
1371
        def fail_once(transport):
1372
            count[0] += 1
1373
            if count[0] == 1:
1374
                raise errors.BzrError("fail")
1375
        bzrdir.BzrDir.hooks.install_named_hook('pre_open', fail_once, None)
1376
        transport = self.get_transport('foo')
1377
        url = transport.base
1378
        err = self.assertRaises(errors.BzrError, bzrdir.BzrDir.open, url)
1379
        self.assertEqual('fail', err._preformatted_string)
4797.94.2 by Jelmer Vernooij
Add tests.
1380
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
1381
    def test_post_repo_init(self):
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
1382
        from ..controldir import RepoInitHookParams
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
1383
        calls = []
5107.3.4 by Marco Pantaleoni
Applied suggestions from merge reviewer (John A Meinel):
1384
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1385
                                               calls.append, None)
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
1386
        self.make_repository('foo')
1387
        self.assertLength(1, calls)
1388
        params = calls[0]
1389
        self.assertIsInstance(params, RepoInitHookParams)
6653.6.3 by Jelmer Vernooij
Fix last tests.
1390
        self.assertTrue(hasattr(params, 'controldir'))
5107.3.1 by Marco Pantaleoni
Added the new hooks 'post_branch', 'post_switch' and 'post_repo_init',
1391
        self.assertTrue(hasattr(params, 'repository'))
5050.21.3 by Andrew Bennetts
Add a test for RepoInitHookParams.__repr__ too.
1392
1393
    def test_post_repo_init_hook_repr(self):
1394
        param_reprs = []
1395
        bzrdir.BzrDir.hooks.install_named_hook('post_repo_init',
7143.15.2 by Jelmer Vernooij
Run autopep8.
1396
                                               lambda params: param_reprs.append(repr(params)), None)
5050.21.3 by Andrew Bennetts
Add a test for RepoInitHookParams.__repr__ too.
1397
        self.make_repository('foo')
1398
        self.assertLength(1, param_reprs)
1399
        param_repr = param_reprs[0]
1400
        self.assertStartsWith(param_repr, '<RepoInitHookParams for ')
1401
4797.94.2 by Jelmer Vernooij
Add tests.
1402
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1403
class TestGenerateBackupName(TestCaseWithMemoryTransport):
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1404
    # FIXME: This may need to be unified with test_osutils.TestBackupNames or
1405
    # moved to per_bzrdir or per_transport for better coverage ?
1406
    # -- vila 20100909
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1407
1408
    def setUp(self):
1409
        super(TestGenerateBackupName, self).setUp()
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1410
        self._transport = self.get_transport()
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1411
        bzrdir.BzrDir.create(self.get_url(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1412
                             possible_transports=[self._transport])
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1413
        self._bzrdir = bzrdir.BzrDir.open_from_transport(self._transport)
1414
1415
    def test_new(self):
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1416
        self.assertEqual("a.~1~", self._bzrdir._available_backup_name("a"))
5340.8.4 by Marius Kruger
* gen_backup_name => generate_backup_name
1417
1418
    def test_exiting(self):
7058.4.13 by Jelmer Vernooij
Fix test_bzrdir tests.
1419
        self._transport.put_bytes("a.~1~", b"some content")
5409.5.4 by Vincent Ladeuil
Deprecate BzrDir.generate_backup_name and use osutils.available_backup_name.
1420
        self.assertEqual("a.~2~", self._bzrdir._available_backup_name("a"))
5669.3.8 by Jelmer Vernooij
Refactor, move to bzrlib.controldir.
1421
6083.2.11 by Jelmer Vernooij
Add development-colo format.
1422
1423
class TestMeta1DirColoFormat(TestCaseWithTransport):
1424
    """Tests specific to the meta1 dir with colocated branches format."""
1425
1426
    def test_supports_colo(self):
1427
        format = bzrdir.BzrDirMetaFormat1Colo()
1428
        self.assertTrue(format.colocated_branches)
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
1429
1430
    def test_upgrade_from_2a(self):
1431
        tree = self.make_branch_and_tree('.', format='2a')
1432
        format = bzrdir.BzrDirMetaFormat1Colo()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1433
        self.assertTrue(tree.controldir.needs_format_conversion(format))
1434
        converter = tree.controldir._format.get_converter(format)
1435
        result = converter.convert(tree.controldir, None)
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
1436
        self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1Colo)
1437
        self.assertFalse(result.needs_format_conversion(format))
1438
1439
    def test_downgrade_to_2a(self):
1440
        tree = self.make_branch_and_tree('.', format='development-colo')
1441
        format = bzrdir.BzrDirMetaFormat1()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1442
        self.assertTrue(tree.controldir.needs_format_conversion(format))
1443
        converter = tree.controldir._format.get_converter(format)
1444
        result = converter.convert(tree.controldir, None)
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
1445
        self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
1446
        self.assertFalse(result.needs_format_conversion(format))
1447
1448
    def test_downgrade_to_2a_too_many_branches(self):
1449
        tree = self.make_branch_and_tree('.', format='development-colo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1450
        tree.controldir.create_branch(name="another-colocated-branch")
1451
        converter = tree.controldir._format.get_converter(
6207.1.1 by Jelmer Vernooij
Support upgrading between 2a and development-colo.
1452
            bzrdir.BzrDirMetaFormat1())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1453
        result = converter.convert(tree.controldir, bzrdir.BzrDirMetaFormat1())
6437.21.3 by Jelmer Vernooij
Fix test.
1454
        self.assertIsInstance(result._format, bzrdir.BzrDirMetaFormat1)
6239.1.1 by Jelmer Vernooij
Create lock directories in .bzr/, not .
1455
6437.18.2 by Jelmer Vernooij
Check for slashes in branch names.
1456
    def test_nested(self):
1457
        tree = self.make_branch_and_tree('.', format='development-colo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1458
        tree.controldir.create_branch(name='foo')
1459
        tree.controldir.create_branch(name='fool/bla')
6437.18.2 by Jelmer Vernooij
Check for slashes in branch names.
1460
        self.assertRaises(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1461
            errors.ParentBranchExists, tree.controldir.create_branch,
6437.18.2 by Jelmer Vernooij
Check for slashes in branch names.
1462
            name='foo/bar')
1463
6437.18.4 by Jelmer Vernooij
Cope with child branches, too.
1464
    def test_parent(self):
1465
        tree = self.make_branch_and_tree('.', format='development-colo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1466
        tree.controldir.create_branch(name='fool/bla')
1467
        tree.controldir.create_branch(name='foo/bar')
6437.18.4 by Jelmer Vernooij
Cope with child branches, too.
1468
        self.assertRaises(
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
1469
            errors.AlreadyBranchError, tree.controldir.create_branch,
6437.18.4 by Jelmer Vernooij
Cope with child branches, too.
1470
            name='foo')
1471
7236.1.4 by Jelmer Vernooij
Verify that loading relative paths still works.
1472
    def test_supports_relative_reference(self):
1473
        tree = self.make_branch_and_tree('.', format='development-colo')
1474
        target1 = tree.controldir.create_branch(name='target1')
1475
        target2 = tree.controldir.create_branch(name='target2')
1476
        source = tree.controldir.set_branch_reference(target1, name='source')
1477
        self.assertEqual(
1478
            target1.user_url, tree.controldir.open_branch('source').user_url)
1479
        source.controldir.get_branch_transport(None, 'source').put_bytes(
1480
            'location', b'file:,branch=target2')
1481
        self.assertEqual(
1482
            target2.user_url, tree.controldir.open_branch('source').user_url)
1483
6213.1.5 by Jelmer Vernooij
Add feature flags object.
1484
6213.1.33 by Jelmer Vernooij
Fix some tests.
1485
class SampleBzrFormat(bzrdir.BzrFormat):
1486
1487
    @classmethod
1488
    def get_format_string(cls):
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1489
        return b"First line\n"
6213.1.33 by Jelmer Vernooij
Fix some tests.
1490
1491
6213.1.31 by Jelmer Vernooij
Fix more tests.
1492
class TestBzrFormat(TestCase):
1493
    """Tests for BzrFormat."""
6213.1.5 by Jelmer Vernooij
Add feature flags object.
1494
1495
    def test_as_string(self):
6213.1.33 by Jelmer Vernooij
Fix some tests.
1496
        format = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1497
        format.features = {b"foo": b"required"}
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1498
        self.assertEqual(format.as_string(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1499
                         b"First line\n"
1500
                         b"required foo\n")
7058.4.13 by Jelmer Vernooij
Fix test_bzrdir tests.
1501
        format.features[b"another"] = b"optional"
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1502
        self.assertEqual(format.as_string(),
7143.15.2 by Jelmer Vernooij
Run autopep8.
1503
                         b"First line\n"
1504
                         b"optional another\n"
1505
                         b"required foo\n")
6213.1.5 by Jelmer Vernooij
Add feature flags object.
1506
6213.1.43 by Jelmer Vernooij
Cope with features already existing.
1507
    def test_network_name(self):
6213.1.37 by Jelmer Vernooij
Moar tests.
1508
        # The network string should include the feature info
1509
        format = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1510
        format.features = {b"foo": b"required"}
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1511
        self.assertEqual(
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1512
            b"First line\nrequired foo\n",
6213.1.43 by Jelmer Vernooij
Cope with features already existing.
1513
            format.network_name())
6213.1.37 by Jelmer Vernooij
Moar tests.
1514
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1515
    def test_from_string_no_features(self):
6213.1.51 by Jelmer Vernooij
Add some comments.
1516
        # No features
1517
        format = SampleBzrFormat.from_string(
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1518
            b"First line\n")
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1519
        self.assertEqual({}, format.features)
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1520
1521
    def test_from_string_with_feature(self):
6213.1.51 by Jelmer Vernooij
Add some comments.
1522
        # Proper feature
6213.1.33 by Jelmer Vernooij
Fix some tests.
1523
        format = SampleBzrFormat.from_string(
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1524
            b"First line\nrequired foo\n")
1525
        self.assertEqual(b"required", format.features.get(b"foo"))
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1526
1527
    def test_from_string_format_string_mismatch(self):
6213.1.51 by Jelmer Vernooij
Add some comments.
1528
        # The first line has to match the format string
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1529
        self.assertRaises(AssertionError, SampleBzrFormat.from_string,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1530
                          b"Second line\nrequired foo\n")
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1531
1532
    def test_from_string_missing_space(self):
6213.1.51 by Jelmer Vernooij
Add some comments.
1533
        # At least one space is required in the feature lines
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1534
        self.assertRaises(errors.ParseFormatError, SampleBzrFormat.from_string,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1535
                          b"First line\nfoo\n")
6213.1.53 by Jelmer Vernooij
Add ParseFormatError.
1536
1537
    def test_from_string_with_spaces(self):
6213.1.51 by Jelmer Vernooij
Add some comments.
1538
        # Feature with spaces (in case we add stuff like this in the future)
6213.1.45 by Jelmer Vernooij
Ignore optional non-feature lines in bzr formats.
1539
        format = SampleBzrFormat.from_string(
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1540
            b"First line\nrequired foo with spaces\n")
1541
        self.assertEqual(b"required", format.features.get(b"foo with spaces"))
6213.1.6 by Jelmer Vernooij
Add FeatureFlags.__eq__.
1542
1543
    def test_eq(self):
6213.1.33 by Jelmer Vernooij
Fix some tests.
1544
        format1 = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1545
        format1.features = {b"nested-trees": b"optional"}
6213.1.33 by Jelmer Vernooij
Fix some tests.
1546
        format2 = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1547
        format2.features = {b"nested-trees": b"optional"}
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1548
        self.assertEqual(format1, format1)
1549
        self.assertEqual(format1, format2)
6213.1.33 by Jelmer Vernooij
Fix some tests.
1550
        format3 = SampleBzrFormat()
6614.1.2 by Vincent Ladeuil
Fix assertNotEquals being deprecated by using assertNotEqual.
1551
        self.assertNotEqual(format1, format3)
6213.1.29 by Jelmer Vernooij
Update docs, fix tests.
1552
1553
    def test_check_support_status_optional(self):
1554
        # Optional, so silently ignore
6213.1.33 by Jelmer Vernooij
Fix some tests.
1555
        format = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1556
        format.features = {b"nested-trees": b"optional"}
6213.1.33 by Jelmer Vernooij
Fix some tests.
1557
        format.check_support_status(True)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1558
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1559
        SampleBzrFormat.register_feature(b"nested-trees")
6213.1.33 by Jelmer Vernooij
Fix some tests.
1560
        format.check_support_status(True)
6213.1.29 by Jelmer Vernooij
Update docs, fix tests.
1561
1562
    def test_check_support_status_required(self):
1563
        # Optional, so trigger an exception
6213.1.33 by Jelmer Vernooij
Fix some tests.
1564
        format = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1565
        format.features = {b"nested-trees": b"required"}
6731.1.3 by Jelmer Vernooij
Move MissingFeature error to breezy.bzr.bzrdir.
1566
        self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1567
                          True)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1568
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1569
        SampleBzrFormat.register_feature(b"nested-trees")
6213.1.33 by Jelmer Vernooij
Fix some tests.
1570
        format.check_support_status(True)
6213.1.29 by Jelmer Vernooij
Update docs, fix tests.
1571
1572
    def test_check_support_status_unknown(self):
1573
        # treat unknown necessity as required
6213.1.33 by Jelmer Vernooij
Fix some tests.
1574
        format = SampleBzrFormat()
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1575
        format.features = {b"nested-trees": b"unknown"}
6731.1.3 by Jelmer Vernooij
Move MissingFeature error to breezy.bzr.bzrdir.
1576
        self.assertRaises(bzrdir.MissingFeature, format.check_support_status,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1577
                          True)
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1578
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1579
        SampleBzrFormat.register_feature(b"nested-trees")
6213.1.33 by Jelmer Vernooij
Fix some tests.
1580
        format.check_support_status(True)
6213.1.43 by Jelmer Vernooij
Cope with features already existing.
1581
1582
    def test_feature_already_registered(self):
6213.1.48 by Jelmer Vernooij
Drop feature bit, don't allow spaces.
1583
        # a feature can only be registered once
6855.2.2 by Jelmer Vernooij
Format strings are bytes.
1584
        self.addCleanup(SampleBzrFormat.unregister_feature, b"nested-trees")
1585
        SampleBzrFormat.register_feature(b"nested-trees")
6734.1.8 by Jelmer Vernooij
Move FeatureAlreadyRegistered.
1586
        self.assertRaises(bzrdir.FeatureAlreadyRegistered,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1587
                          SampleBzrFormat.register_feature, b"nested-trees")
6213.1.48 by Jelmer Vernooij
Drop feature bit, don't allow spaces.
1588
1589
    def test_feature_with_space(self):
1590
        # spaces are not allowed in feature names
1591
        self.assertRaises(ValueError, SampleBzrFormat.register_feature,
7143.15.2 by Jelmer Vernooij
Run autopep8.
1592
                          b"nested trees")