~bzr-pqm/bzr/bzr.dev

5557.1.7 by John Arbash Meinel
Merge in the bzr.dev 5582
1
# Copyright (C) 2006-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
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.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
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
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
17
"""Tests for control directory implementations - tests a controldir format."""
18
19
from itertools import izip
20
21
import bzrlib.branch
22
from bzrlib import (
23
    bzrdir,
24
    check,
25
    controldir,
26
    errors,
27
    gpg,
28
    osutils,
29
    transport,
30
    ui,
31
    urlutils,
32
    workingtree,
33
    )
34
import bzrlib.revision
35
from bzrlib.tests import (
36
    fixtures,
37
    ChrootedTestCase,
38
    TestNotApplicable,
39
    TestSkipped,
40
    )
41
from bzrlib.tests.per_controldir import TestCaseWithControlDir
42
from bzrlib.transport.local import LocalTransport
43
from bzrlib.ui import (
44
    CannedInputUIFactory,
45
    )
46
from bzrlib.remote import (
47
    RemoteBzrDir,
48
    RemoteBzrDirFormat,
49
    RemoteRepository,
50
    )
51
52
53
class TestControlDir(TestCaseWithControlDir):
54
55
    def skipIfNoWorkingTree(self, a_bzrdir):
56
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
57
58
        If the bzrdir does have a workingtree, this is a no-op.
59
        """
60
        try:
61
            a_bzrdir.open_workingtree()
62
        except (errors.NotLocalUrl, errors.NoWorkingTree):
63
            raise TestSkipped("bzrdir on transport %r has no working tree"
64
                              % a_bzrdir.transport)
65
66
    def openWorkingTreeIfLocal(self, a_bzrdir):
67
        """If a_bzrdir is on a local transport, call open_workingtree() on it.
68
        """
69
        if not isinstance(a_bzrdir.root_transport, LocalTransport):
70
            # it's not local, but that's ok
71
            return
72
        a_bzrdir.open_workingtree()
73
74
    def createWorkingTreeOrSkip(self, a_bzrdir):
75
        """Create a working tree on a_bzrdir, or raise TestSkipped.
76
77
        A simple wrapper for create_workingtree that translates NotLocalUrl into
78
        TestSkipped.  Returns the newly created working tree.
79
        """
80
        try:
81
            return a_bzrdir.create_workingtree()
82
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
83
            raise TestSkipped("cannot make working tree with transport %r"
84
                              % a_bzrdir.transport)
85
86
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
87
                     force_new_repo=False, accelerator_tree=None,
88
                     create_tree_if_local=True):
89
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
90
91
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
92
        TestSkipped.  Returns the newly sprouted bzrdir.
93
        """
94
        to_transport = transport.get_transport(to_url)
95
        if not isinstance(to_transport, LocalTransport):
96
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
97
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
98
                                    force_new_repo=force_new_repo,
99
                                    possible_transports=[to_transport],
100
                                    accelerator_tree=accelerator_tree,
101
                                    create_tree_if_local=create_tree_if_local)
102
        return target
103
6162.3.6 by Jelmer Vernooij
Add test for uninitializable formats.
104
    def test_uninitializable(self):
105
        if self.bzrdir_format.is_initializable():
106
            raise TestNotApplicable("format is initializable")
107
        t = self.get_transport()
108
        self.assertRaises(errors.UninitializableFormat,
109
            self.bzrdir_format.initialize, t.base)
110
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
111
    def test_create_null_workingtree(self):
112
        dir = self.make_bzrdir('dir1')
113
        dir.create_repository()
114
        dir.create_branch()
115
        try:
116
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
117
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
118
            raise TestSkipped("cannot make working tree with transport %r"
119
                              % dir.transport)
120
        self.assertEqual([], wt.get_parent_ids())
121
122
    def test_destroy_workingtree(self):
123
        tree = self.make_branch_and_tree('tree')
124
        self.build_tree(['tree/file'])
125
        tree.add('file')
126
        tree.commit('first commit')
127
        bzrdir = tree.bzrdir
128
        try:
129
            bzrdir.destroy_workingtree()
130
        except errors.UnsupportedOperation:
131
            raise TestSkipped('Format does not support destroying tree')
132
        self.assertPathDoesNotExist('tree/file')
133
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
134
        bzrdir.create_workingtree()
135
        self.assertPathExists('tree/file')
136
        bzrdir.destroy_workingtree_metadata()
137
        self.assertPathExists('tree/file')
138
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
139
140
    def test_destroy_branch(self):
141
        branch = self.make_branch('branch')
142
        bzrdir = branch.bzrdir
143
        try:
144
            bzrdir.destroy_branch()
145
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
146
            raise TestNotApplicable('Format does not support destroying branch')
147
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
148
        bzrdir.create_branch()
149
        bzrdir.open_branch()
150
151
    def test_destroy_repository(self):
152
        repo = self.make_repository('repository')
153
        bzrdir = repo.bzrdir
154
        try:
155
            bzrdir.destroy_repository()
156
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
157
            raise TestNotApplicable('Format does not support destroying'
158
                                    ' repository')
6266.2.2 by Jelmer Vernooij
Fix tests.
159
        self.assertRaises(errors.NoRepositoryPresent,
160
            bzrdir.destroy_repository)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
161
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
162
        bzrdir.create_repository()
163
        bzrdir.open_repository()
164
165
    def test_open_workingtree_raises_no_working_tree(self):
166
        """ControlDir.open_workingtree() should raise NoWorkingTree (rather than
167
        e.g. NotLocalUrl) if there is no working tree.
168
        """
169
        dir = self.make_bzrdir('source')
170
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
171
        if vfs_dir.has_workingtree():
172
            # This ControlDir format doesn't support ControlDirs without
173
            # working trees, so this test is irrelevant.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
174
            raise TestNotApplicable("format does not support "
175
                "control directories without working tree")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
176
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
177
178
    def test_clone_bzrdir_repository_under_shared(self):
179
        tree = self.make_branch_and_tree('commit_tree')
180
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
181
        tree.add('foo')
182
        tree.commit('revision 1', rev_id='1')
183
        dir = self.make_bzrdir('source')
184
        repo = dir.create_repository()
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
185
        if not repo._format.supports_nesting_repositories:
186
            raise TestNotApplicable("repository format does not support "
187
                "nesting")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
188
        repo.fetch(tree.branch.repository)
189
        self.assertTrue(repo.has_revision('1'))
190
        try:
191
            self.make_repository('target', shared=True)
192
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
193
            raise TestNotApplicable("repository format does not support "
194
                "shared repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
195
        target = dir.clone(self.get_url('target/child'))
196
        self.assertNotEqual(dir.transport.base, target.transport.base)
197
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
198
199
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
200
        # Create a shared repository
201
        try:
202
            shared_repo = self.make_repository('shared', shared=True)
203
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
204
            raise TestNotApplicable("repository format does not support "
205
                "shared repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
206
        if not shared_repo._format.supports_nesting_repositories:
207
            raise TestNotApplicable("format does not support nesting "
208
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
209
        # Make a branch, 'commit_tree', and working tree outside of the shared
210
        # repository, and commit some revisions to it.
211
        tree = self.make_branch_and_tree('commit_tree')
212
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
213
        tree.add('foo')
214
        tree.commit('revision 1', rev_id='1')
215
        tree.bzrdir.open_branch().generate_revision_history(
216
            bzrlib.revision.NULL_REVISION)
217
        tree.set_parent_trees([])
218
        tree.commit('revision 2', rev_id='2')
219
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
220
        # repository into the shared repository.
221
        tree.branch.repository.copy_content_into(shared_repo)
222
        # Make a branch 'source' inside the shared repository.
223
        dir = self.make_bzrdir('shared/source')
224
        dir.create_branch()
225
        # Clone 'source' to 'target', also inside the shared repository.
226
        target = dir.clone(self.get_url('shared/target'))
227
        # 'source', 'target', and the shared repo all have distinct bzrdirs.
228
        self.assertNotEqual(dir.transport.base, target.transport.base)
229
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
230
        # The shared repository will contain revisions from the 'commit_tree'
231
        # repository, even revisions that are not part of the history of the
232
        # 'commit_tree' branch.
233
        self.assertTrue(shared_repo.has_revision('1'))
234
235
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
236
        try:
237
            shared_repo = self.make_repository('shared', shared=True)
238
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
239
            raise TestNotApplicable("repository format does not support "
240
                "shared repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
241
        if not shared_repo._format.supports_nesting_repositories:
242
            raise TestNotApplicable("format does not support nesting "
243
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
244
        tree = self.make_branch_and_tree('commit_tree')
245
        self.build_tree(['commit_tree/foo'])
246
        tree.add('foo')
247
        tree.commit('revision 1', rev_id='1')
248
        tree.branch.bzrdir.open_branch().generate_revision_history(
249
            bzrlib.revision.NULL_REVISION)
250
        tree.set_parent_trees([])
251
        tree.commit('revision 2', rev_id='2')
252
        tree.branch.repository.copy_content_into(shared_repo)
253
        if shared_repo.make_working_trees():
254
            shared_repo.set_make_working_trees(False)
255
            self.assertFalse(shared_repo.make_working_trees())
256
        self.assertTrue(shared_repo.has_revision('1'))
257
        dir = self.make_bzrdir('shared/source')
258
        dir.create_branch()
259
        target = dir.clone(self.get_url('target'))
260
        self.assertNotEqual(dir.transport.base, target.transport.base)
261
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
262
        branch = target.open_branch()
263
        self.assertTrue(branch.repository.has_revision('1'))
264
        self.assertFalse(branch.repository.make_working_trees())
265
        self.assertTrue(branch.repository.is_shared())
266
267
    def test_clone_bzrdir_repository_revision(self):
268
        # test for revision limiting, [smoke test, not corner case checks].
269
        # make a repository with some revisions,
270
        # and clone it with a revision limit.
271
        #
272
        tree = self.make_branch_and_tree('commit_tree')
273
        self.build_tree(['commit_tree/foo'])
274
        tree.add('foo')
275
        tree.commit('revision 1', rev_id='1')
276
        tree.branch.bzrdir.open_branch().generate_revision_history(
277
            bzrlib.revision.NULL_REVISION)
278
        tree.set_parent_trees([])
279
        tree.commit('revision 2', rev_id='2')
280
        source = self.make_repository('source')
281
        tree.branch.repository.copy_content_into(source)
282
        dir = source.bzrdir
283
        target = dir.clone(self.get_url('target'), revision_id='2')
284
        raise TestSkipped('revision limiting not strict yet')
285
286
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
287
        # Bug #430868 is about an email containing '.sig'
288
        self.overrideEnv('BZR_EMAIL', 'murphy@host.sighup.org')
289
        tree = self.make_branch_and_tree('commit_tree')
290
        self.build_tree(['commit_tree/foo'])
291
        tree.add('foo')
292
        rev1 = tree.commit('revision 1')
293
        tree_repo = tree.branch.repository
294
        tree_repo.lock_write()
295
        tree_repo.start_write_group()
296
        tree_repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
297
        tree_repo.commit_write_group()
298
        tree_repo.unlock()
299
        target = self.make_branch('target')
300
        tree.branch.repository.copy_content_into(target.repository)
301
        tree.branch.copy_content_into(target)
302
        self.assertTrue(target.repository.has_revision(rev1))
303
        self.assertEqual(
304
            tree_repo.get_signature_text(rev1),
305
            target.repository.get_signature_text(rev1))
306
307
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
308
        # by default cloning into a shared repo uses the shared repo.
309
        tree = self.make_branch_and_tree('commit_tree')
310
        self.build_tree(['commit_tree/foo'])
311
        tree.add('foo')
312
        tree.commit('revision 1')
313
        source = self.make_branch('source')
314
        tree.branch.repository.copy_content_into(source.repository)
315
        tree.branch.copy_content_into(source)
316
        try:
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
317
            shared_repo = self.make_repository('target', shared=True)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
318
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
319
            raise TestNotApplicable("repository format does not support "
320
                "shared repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
321
        if not shared_repo._format.supports_nesting_repositories:
322
            raise TestNotApplicable("format does not support nesting "
323
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
324
        dir = source.bzrdir
325
        target = dir.clone(self.get_url('target/child'))
326
        self.assertNotEqual(dir.transport.base, target.transport.base)
327
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
328
        self.assertEqual(source.last_revision(),
329
                         target.open_branch().last_revision())
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
330
331
    def test_clone_bzrdir_branch_revision(self):
332
        # test for revision limiting, [smoke test, not corner case checks].
333
        # make a branch with some revisions,
334
        # and clone it with a revision limit.
335
        #
336
        tree = self.make_branch_and_tree('commit_tree')
337
        self.build_tree(['commit_tree/foo'])
338
        tree.add('foo')
339
        tree.commit('revision 1', rev_id='1')
340
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
341
        source = self.make_branch('source')
342
        tree.branch.repository.copy_content_into(source.repository)
343
        tree.branch.copy_content_into(source)
344
        dir = source.bzrdir
345
        target = dir.clone(self.get_url('target'), revision_id='1')
346
        self.assertEqual('1', target.open_branch().last_revision())
347
348
    def test_clone_on_transport_preserves_repo_format(self):
349
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
350
            format = 'knit'
351
        else:
352
            format = None
353
        source_branch = self.make_branch('source', format=format)
354
        # Ensure no format data is cached
355
        a_dir = bzrlib.branch.Branch.open_from_transport(
356
            self.get_transport('source')).bzrdir
357
        target_transport = self.get_transport('target')
358
        target_bzrdir = a_dir.clone_on_transport(target_transport)
359
        target_repo = target_bzrdir.open_repository()
360
        source_branch = bzrlib.branch.Branch.open(
361
            self.get_vfs_only_url('source'))
362
        if isinstance(target_repo, RemoteRepository):
363
            target_repo._ensure_real()
364
            target_repo = target_repo._real_repository
365
        self.assertEqual(target_repo._format, source_branch.repository._format)
366
367
    def test_clone_bzrdir_tree_revision(self):
368
        # test for revision limiting, [smoke test, not corner case checks].
369
        # make a tree with a revision with a last-revision
370
        # and clone it with a revision limit.
371
        # This smoke test just checks the revision-id is right. Tree specific
372
        # tests will check corner cases.
373
        tree = self.make_branch_and_tree('source')
374
        self.build_tree(['source/foo'])
375
        tree.add('foo')
376
        tree.commit('revision 1', rev_id='1')
377
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
378
        dir = tree.bzrdir
379
        target = dir.clone(self.get_url('target'), revision_id='1')
380
        self.skipIfNoWorkingTree(target)
381
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
382
383
    def test_clone_bzrdir_into_notrees_repo(self):
384
        """Cloning into a no-trees repo should not create a working tree"""
385
        tree = self.make_branch_and_tree('source')
386
        self.build_tree(['source/foo'])
387
        tree.add('foo')
388
        tree.commit('revision 1')
389
390
        try:
391
            repo = self.make_repository('repo', shared=True)
392
        except errors.IncompatibleFormat:
393
            raise TestNotApplicable('must support shared repositories')
394
        if repo.make_working_trees():
395
            repo.set_make_working_trees(False)
396
            self.assertFalse(repo.make_working_trees())
397
6182.1.11 by Jelmer Vernooij
Simplify.
398
        a_dir = tree.bzrdir.clone(self.get_url('repo/a'))
6182.1.13 by Jelmer Vernooij
Cope with repository existing in different location.
399
        a_branch = a_dir.open_branch()
400
        # If the new control dir actually uses the repository, it should
401
        # not have a working tree.
402
        if not a_branch.repository.has_same_location(repo):
403
            raise TestNotApplicable('new control dir does not use repository')
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
404
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
405
406
    def test_clone_respects_stacked(self):
407
        branch = self.make_branch('parent')
408
        child_transport = self.get_transport('child')
6162.3.1 by Jelmer Vernooij
Skip a few tests for uninitializable formats.
409
        try:
410
            child = branch.bzrdir.clone_on_transport(child_transport,
411
                                                     stacked_on=branch.base)
412
        except (errors.UnstackableBranchFormat,
413
                errors.UnstackableRepositoryFormat):
6162.5.5 by Jelmer Vernooij
Review feedback from John.
414
            raise TestNotApplicable("branch or repository format does "
6162.3.1 by Jelmer Vernooij
Skip a few tests for uninitializable formats.
415
                "not support stacking")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
416
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
417
418
    def test_get_branch_reference_on_reference(self):
419
        """get_branch_reference should return the right url."""
420
        referenced_branch = self.make_branch('referenced')
421
        dir = self.make_bzrdir('source')
422
        try:
423
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
424
                target_branch=referenced_branch)
425
        except errors.IncompatibleFormat:
426
            # this is ok too, not all formats have to support references.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
427
            raise TestNotApplicable("control directory does not "
428
                "support branch references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
429
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
430
            dir.get_branch_reference())
431
432
    def test_get_branch_reference_on_non_reference(self):
433
        """get_branch_reference should return None for non-reference branches."""
434
        branch = self.make_branch('referenced')
435
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
436
437
    def test_get_branch_reference_no_branch(self):
438
        """get_branch_reference should not mask NotBranchErrors."""
439
        dir = self.make_bzrdir('source')
440
        if dir.has_branch():
441
            # this format does not support branchless bzrdirs.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
442
            raise TestNotApplicable("format does not support "
443
                "branchless control directories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
444
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
445
446
    def test_sprout_bzrdir_empty(self):
447
        dir = self.make_bzrdir('source')
448
        target = dir.sprout(self.get_url('target'))
6050.3.1 by Jelmer Vernooij
Use control_transport rather than transport.
449
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
450
        # creates a new repository branch and tree
451
        target.open_repository()
452
        target.open_branch()
453
        self.openWorkingTreeIfLocal(target)
454
455
    def test_sprout_bzrdir_empty_under_shared_repo(self):
456
        # sprouting an empty dir into a repo uses the repo
457
        dir = self.make_bzrdir('source')
458
        try:
459
            self.make_repository('target', shared=True)
460
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
461
            raise TestNotApplicable("format does not support shared "
462
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
463
        target = dir.sprout(self.get_url('target/child'))
464
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
465
        target.open_branch()
466
        try:
467
            target.open_workingtree()
468
        except errors.NoWorkingTree:
469
            # Some bzrdirs can never have working trees.
6162.5.2 by Jelmer Vernooij
Skip test that requires nesting repositories, check supports workingtrees.
470
            repo = target.find_repository()
471
            self.assertFalse(repo.bzrdir._format.supports_workingtrees)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
472
473
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
474
        # the force_new_repo parameter should force use of a new repo in an empty
475
        # bzrdir's sprout logic
476
        dir = self.make_bzrdir('source')
477
        try:
478
            self.make_repository('target', shared=True)
479
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
480
            raise TestNotApplicable("format does not support shared "
481
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
482
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
483
        target.open_repository()
484
        target.open_branch()
485
        self.openWorkingTreeIfLocal(target)
486
487
    def test_sprout_bzrdir_with_repository_to_shared(self):
488
        tree = self.make_branch_and_tree('commit_tree')
489
        self.build_tree(['commit_tree/foo'])
490
        tree.add('foo')
491
        tree.commit('revision 1', rev_id='1')
492
        tree.bzrdir.open_branch().generate_revision_history(
493
            bzrlib.revision.NULL_REVISION)
494
        tree.set_parent_trees([])
495
        tree.commit('revision 2', rev_id='2')
496
        source = self.make_repository('source')
497
        tree.branch.repository.copy_content_into(source)
498
        dir = source.bzrdir
499
        try:
500
            shared_repo = self.make_repository('target', shared=True)
501
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
502
            raise TestNotApplicable("format does not support "
503
                "shared repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
504
        target = dir.sprout(self.get_url('target/child'))
6127.1.4 by Jelmer Vernooij
Use user_transport.
505
        self.assertNotEqual(dir.user_transport.base, target.user_transport.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
506
        self.assertTrue(shared_repo.has_revision('1'))
507
508
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
509
        try:
510
            shared_repo = self.make_repository('shared', shared=True)
511
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
512
            raise TestNotApplicable("format does not support shared "
513
                "repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
514
        if not shared_repo._format.supports_nesting_repositories:
515
            raise TestNotApplicable("format does not support nesting "
516
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
517
        tree = self.make_branch_and_tree('commit_tree')
518
        self.build_tree(['commit_tree/foo'])
519
        tree.add('foo')
520
        tree.commit('revision 1', rev_id='1')
521
        tree.bzrdir.open_branch().generate_revision_history(
522
            bzrlib.revision.NULL_REVISION)
523
        tree.set_parent_trees([])
524
        tree.commit('revision 2', rev_id='2')
525
        tree.branch.repository.copy_content_into(shared_repo)
526
        dir = self.make_bzrdir('shared/source')
527
        dir.create_branch()
528
        target = dir.sprout(self.get_url('shared/target'))
529
        self.assertNotEqual(dir.transport.base, target.transport.base)
530
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
531
        self.assertTrue(shared_repo.has_revision('1'))
532
533
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
534
        try:
535
            shared_repo = self.make_repository('shared', shared=True)
536
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
537
            raise TestNotApplicable("format does not support shared "
538
                "repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
539
        if not shared_repo._format.supports_nesting_repositories:
540
            raise TestNotApplicable("format does not support nesting "
541
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
542
        tree = self.make_branch_and_tree('commit_tree')
543
        self.build_tree(['commit_tree/foo'])
544
        tree.add('foo')
545
        tree.commit('revision 1', rev_id='1')
546
        tree.bzrdir.open_branch().generate_revision_history(
547
            bzrlib.revision.NULL_REVISION)
548
        tree.set_parent_trees([])
549
        tree.commit('revision 2', rev_id='2')
550
        tree.branch.repository.copy_content_into(shared_repo)
551
        if shared_repo.make_working_trees():
552
            shared_repo.set_make_working_trees(False)
553
            self.assertFalse(shared_repo.make_working_trees())
554
        self.assertTrue(shared_repo.has_revision('1'))
555
        dir = self.make_bzrdir('shared/source')
556
        dir.create_branch()
557
        target = dir.sprout(self.get_url('target'))
558
        self.assertNotEqual(dir.transport.base, target.transport.base)
559
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
560
        branch = target.open_branch()
561
        # The sprouted bzrdir has a branch, so only revisions referenced by
562
        # that branch are copied, rather than the whole repository.  It's an
563
        # empty branch, so none are copied.
564
        self.assertEqual([], branch.repository.all_revision_ids())
565
        if branch.bzrdir._format.supports_workingtrees:
566
            self.assertTrue(branch.repository.make_working_trees())
567
        self.assertFalse(branch.repository.is_shared())
568
569
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
570
        tree = self.make_branch_and_tree('commit_tree')
571
        self.build_tree(['commit_tree/foo'])
572
        tree.add('foo')
573
        tree.commit('revision 1', rev_id='1')
574
        tree.bzrdir.open_branch().generate_revision_history(
575
            bzrlib.revision.NULL_REVISION)
576
        tree.set_parent_trees([])
577
        tree.commit('revision 2', rev_id='2')
578
        source = self.make_repository('source')
579
        tree.branch.repository.copy_content_into(source)
580
        dir = source.bzrdir
581
        try:
582
            shared_repo = self.make_repository('target', shared=True)
583
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
584
            raise TestNotApplicable("format does not support shared "
585
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
586
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
6150.2.1 by Jelmer Vernooij
Use user_transport rather than deprecated .transport.
587
        self.assertNotEqual(
588
            dir.control_transport.base,
589
            target.control_transport.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
590
        self.assertFalse(shared_repo.has_revision('1'))
591
592
    def test_sprout_bzrdir_repository_revision(self):
593
        # test for revision limiting, [smoke test, not corner case checks].
594
        # make a repository with some revisions,
595
        # and sprout it with a revision limit.
596
        #
597
        tree = self.make_branch_and_tree('commit_tree')
598
        self.build_tree(['commit_tree/foo'])
599
        tree.add('foo')
600
        tree.commit('revision 1', rev_id='1')
601
        br = tree.bzrdir.open_branch()
602
        br.set_last_revision_info(0, bzrlib.revision.NULL_REVISION)
603
        tree.set_parent_trees([])
604
        tree.commit('revision 2', rev_id='2')
605
        source = self.make_repository('source')
606
        tree.branch.repository.copy_content_into(source)
607
        dir = source.bzrdir
608
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
609
        raise TestSkipped('revision limiting not strict yet')
610
611
    def test_sprout_bzrdir_branch_and_repo_shared(self):
612
        # sprouting a branch with a repo into a shared repo uses the shared
613
        # repo
614
        tree = self.make_branch_and_tree('commit_tree')
615
        self.build_tree(['commit_tree/foo'])
616
        tree.add('foo')
617
        tree.commit('revision 1', rev_id='1')
618
        source = self.make_branch('source')
619
        tree.branch.repository.copy_content_into(source.repository)
620
        tree.bzrdir.open_branch().copy_content_into(source)
621
        dir = source.bzrdir
622
        try:
623
            shared_repo = self.make_repository('target', shared=True)
624
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
625
            raise TestNotApplicable("format does not support shared "
626
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
627
        target = dir.sprout(self.get_url('target/child'))
628
        self.assertTrue(shared_repo.has_revision('1'))
629
630
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
631
        # sprouting a branch with a repo into a shared repo uses the shared
632
        # repo
633
        tree = self.make_branch_and_tree('commit_tree')
634
        self.build_tree(['commit_tree/foo'])
635
        tree.add('foo')
636
        tree.commit('revision 1', rev_id='1')
637
        source = self.make_branch('source')
638
        tree.branch.repository.copy_content_into(source.repository)
639
        tree.bzrdir.open_branch().copy_content_into(source)
640
        dir = source.bzrdir
641
        try:
642
            shared_repo = self.make_repository('target', shared=True)
643
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
644
            raise TestNotApplicable("format does not support shared "
645
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
646
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
6127.1.4 by Jelmer Vernooij
Use user_transport.
647
        self.assertNotEqual(dir.control_transport.base, target.control_transport.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
648
        self.assertFalse(shared_repo.has_revision('1'))
649
650
    def test_sprout_bzrdir_branch_reference(self):
651
        # sprouting should create a repository if needed and a sprouted branch.
652
        referenced_branch = self.make_branch('referenced')
653
        dir = self.make_bzrdir('source')
654
        try:
655
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
656
                target_branch=referenced_branch)
657
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
658
            raise TestNotApplicable("format does not support branch "
659
                "references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
660
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
661
        target = dir.sprout(self.get_url('target'))
662
        self.assertNotEqual(dir.transport.base, target.transport.base)
663
        # we want target to have a branch that is in-place.
664
        self.assertEqual(target, target.open_branch().bzrdir)
665
        # and as we dont support repositories being detached yet, a repo in
666
        # place
667
        target.open_repository()
668
669
    def test_sprout_bzrdir_branch_reference_shared(self):
670
        # sprouting should create a repository if needed and a sprouted branch.
671
        referenced_tree = self.make_branch_and_tree('referenced')
672
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
673
        dir = self.make_bzrdir('source')
674
        try:
675
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
676
                target_branch=referenced_tree.branch)
677
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
678
            raise TestNotApplicable("format does not support branch "
679
                "references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
680
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
681
        try:
682
            shared_repo = self.make_repository('target', shared=True)
683
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
684
            raise TestNotApplicable("format does not support "
685
                "shared repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
686
        target = dir.sprout(self.get_url('target/child'))
687
        self.assertNotEqual(dir.transport.base, target.transport.base)
688
        # we want target to have a branch that is in-place.
689
        self.assertEqual(target, target.open_branch().bzrdir)
690
        # and we want no repository as the target is shared
691
        self.assertRaises(errors.NoRepositoryPresent,
692
                          target.open_repository)
693
        # and we want revision '1' in the shared repo
694
        self.assertTrue(shared_repo.has_revision('1'))
695
696
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
697
        # sprouting should create a repository if needed and a sprouted branch.
698
        referenced_tree = self.make_branch_and_tree('referenced')
699
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
700
        dir = self.make_bzrdir('source')
701
        try:
702
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
703
                target_branch=referenced_tree.branch)
704
        except errors.IncompatibleFormat:
705
            # this is ok too, not all formats have to support references.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
706
            raise TestNotApplicable("format does not support "
707
                "branch references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
708
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
709
        try:
710
            shared_repo = self.make_repository('target', shared=True)
711
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
712
            raise TestNotApplicable("format does not support shared "
713
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
714
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
715
        self.assertNotEqual(dir.transport.base, target.transport.base)
716
        # we want target to have a branch that is in-place.
717
        self.assertEqual(target, target.open_branch().bzrdir)
718
        # and we want revision '1' in the new repo
719
        self.assertTrue(target.open_repository().has_revision('1'))
720
        # but not the shared one
721
        self.assertFalse(shared_repo.has_revision('1'))
722
723
    def test_sprout_bzrdir_branch_revision(self):
724
        # test for revision limiting, [smoke test, not corner case checks].
725
        # make a repository with some revisions,
726
        # and sprout it with a revision limit.
727
        #
728
        tree = self.make_branch_and_tree('commit_tree')
729
        self.build_tree(['commit_tree/foo'])
730
        tree.add('foo')
731
        tree.commit('revision 1', rev_id='1')
732
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
733
        source = self.make_branch('source')
734
        tree.branch.repository.copy_content_into(source.repository)
735
        tree.bzrdir.open_branch().copy_content_into(source)
736
        dir = source.bzrdir
737
        target = dir.sprout(self.get_url('target'), revision_id='1')
738
        self.assertEqual('1', target.open_branch().last_revision())
739
740
    def test_sprout_bzrdir_branch_with_tags(self):
741
        # when sprouting a branch all revisions named in the tags are copied
742
        # too.
743
        builder = self.make_branch_builder('source')
744
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
745
        try:
746
            source.tags.set_tag('tag-a', 'rev-2')
747
        except errors.TagsNotSupported:
748
            raise TestNotApplicable('Branch format does not support tags.')
6404.1.1 by Vincent Ladeuil
Migrate branch.fetch_tags
749
        source.get_config_stack().set('branch.fetch_tags', True)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
750
        # Now source has a tag not in its ancestry.  Sprout its controldir.
751
        dir = source.bzrdir
752
        target = dir.sprout(self.get_url('target'))
753
        # The tag is present, and so is its revision.
754
        new_branch = target.open_branch()
755
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
756
        new_branch.repository.get_revision('rev-2')
757
758
    def test_sprout_bzrdir_branch_with_absent_tag(self):
759
        # tags referencing absent revisions are copied (and those absent
760
        # revisions do not prevent the sprout.)
761
        builder = self.make_branch_builder('source')
762
        builder.build_commit(message="Rev 1", rev_id='rev-1')
763
        source = builder.get_branch()
764
        try:
765
            source.tags.set_tag('tag-a', 'missing-rev')
6123.9.10 by Jelmer Vernooij
Improve tag handling.
766
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
767
            raise TestNotApplicable('Branch format does not support tags '
768
                'or tags referencing ghost revisions.')
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
769
        # Now source has a tag pointing to an absent revision.  Sprout its
770
        # controldir.
771
        dir = source.bzrdir
772
        target = dir.sprout(self.get_url('target'))
773
        # The tag is present in the target
774
        new_branch = target.open_branch()
775
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
776
777
    def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
778
        # tags referencing absent revisions are copied (and those absent
779
        # revisions do not prevent the sprout.)
780
        builder = self.make_branch_builder('source')
781
        builder.build_commit(message="Rev 1", rev_id='rev-1')
782
        source = builder.get_branch()
783
        try:
784
            source.tags.set_tag('tag-a', 'missing-rev')
6123.9.10 by Jelmer Vernooij
Improve tag handling.
785
        except (errors.TagsNotSupported, errors.GhostTagsNotSupported):
786
            raise TestNotApplicable('Branch format does not support tags '
787
                'or tags referencing missing revisions.')
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
788
        # Now source has a tag pointing to an absent revision.  Sprout its
789
        # controldir.
790
        dir = source.bzrdir
791
        target = dir.sprout(self.get_url('target'), source_branch=source)
792
        # The tag is present in the target
793
        new_branch = target.open_branch()
794
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
795
796
    def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
797
        # dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
798
        # the branch at that bzrdir, the ancestry of all of those, but no other
799
        # revs (not even the tip of the source branch).
800
        builder = self.make_branch_builder('source')
801
        builder.build_commit(message="Base", rev_id='base-rev')
802
        # Make three parallel lines of ancestry off this base.
803
        source = builder.get_branch()
804
        builder.build_commit(message="Rev A1", rev_id='rev-a1')
805
        builder.build_commit(message="Rev A2", rev_id='rev-a2')
806
        builder.build_commit(message="Rev A3", rev_id='rev-a3')
807
        source.set_last_revision_info(1, 'base-rev')
808
        builder.build_commit(message="Rev B1", rev_id='rev-b1')
809
        builder.build_commit(message="Rev B2", rev_id='rev-b2')
810
        builder.build_commit(message="Rev B3", rev_id='rev-b3')
811
        source.set_last_revision_info(1, 'base-rev')
812
        builder.build_commit(message="Rev C1", rev_id='rev-c1')
813
        builder.build_commit(message="Rev C2", rev_id='rev-c2')
814
        builder.build_commit(message="Rev C3", rev_id='rev-c3')
815
        # Set the branch tip to A2
816
        source.set_last_revision_info(3, 'rev-a2')
817
        try:
818
            # Create a tag for B2, and for an absent rev
819
            source.tags.set_tag('tag-non-ancestry', 'rev-b2')
6123.9.10 by Jelmer Vernooij
Improve tag handling.
820
        except errors.TagsNotSupported:
821
            raise TestNotApplicable('Branch format does not support tags ')
822
        try:
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
823
            source.tags.set_tag('tag-absent', 'absent-rev')
6123.9.10 by Jelmer Vernooij
Improve tag handling.
824
        except errors.GhostTagsNotSupported:
825
            has_ghost_tag = False
826
        else:
827
            has_ghost_tag = True
6404.1.1 by Vincent Ladeuil
Migrate branch.fetch_tags
828
        source.get_config_stack().set('branch.fetch_tags', True)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
829
        # And ask sprout for C2
830
        dir = source.bzrdir
831
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
832
        # The tags are present
833
        new_branch = target.open_branch()
6123.9.10 by Jelmer Vernooij
Improve tag handling.
834
        if has_ghost_tag:
835
            self.assertEqual(
836
                {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
837
                new_branch.tags.get_tag_dict())
838
        else:
839
            self.assertEqual(
840
                {'tag-non-ancestry': 'rev-b2'},
841
                new_branch.tags.get_tag_dict())
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
842
        # And the revs for A2, B2 and C2's ancestries are present, but no
843
        # others.
844
        self.assertEqual(
845
            ['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
846
            sorted(new_branch.repository.all_revision_ids()))
847
848
    def test_sprout_bzrdir_tree_branch_reference(self):
849
        # sprouting should create a repository if needed and a sprouted branch.
850
        # the tree state should not be copied.
851
        referenced_branch = self.make_branch('referencced')
852
        dir = self.make_bzrdir('source')
853
        try:
854
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
855
                target_branch=referenced_branch)
856
        except errors.IncompatibleFormat:
857
            # this is ok too, not all formats have to support references.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
858
            raise TestNotApplicable("format does not support "
859
                "branch references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
860
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
861
        tree = self.createWorkingTreeOrSkip(dir)
862
        self.build_tree(['source/subdir/'])
863
        tree.add('subdir')
864
        target = dir.sprout(self.get_url('target'))
865
        self.assertNotEqual(dir.transport.base, target.transport.base)
866
        # we want target to have a branch that is in-place.
867
        self.assertEqual(target, target.open_branch().bzrdir)
868
        # and as we dont support repositories being detached yet, a repo in
869
        # place
870
        target.open_repository()
871
        result_tree = target.open_workingtree()
872
        self.assertFalse(result_tree.has_filename('subdir'))
873
874
    def test_sprout_bzrdir_tree_branch_reference_revision(self):
875
        # sprouting should create a repository if needed and a sprouted branch.
876
        # the tree state should not be copied but the revision changed,
877
        # and the likewise the new branch should be truncated too
878
        referenced_branch = self.make_branch('referencced')
879
        dir = self.make_bzrdir('source')
880
        try:
881
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
882
                target_branch=referenced_branch)
883
        except errors.IncompatibleFormat:
884
            # this is ok too, not all formats have to support references.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
885
            raise TestNotApplicable("format does not support "
886
                "branch references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
887
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
888
        tree = self.createWorkingTreeOrSkip(dir)
889
        self.build_tree(['source/foo'])
890
        tree.add('foo')
891
        tree.commit('revision 1', rev_id='1')
892
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
893
        target = dir.sprout(self.get_url('target'), revision_id='1')
894
        self.skipIfNoWorkingTree(target)
895
        self.assertNotEqual(dir.transport.base, target.transport.base)
896
        # we want target to have a branch that is in-place.
897
        self.assertEqual(target, target.open_branch().bzrdir)
898
        # and as we dont support repositories being detached yet, a repo in
899
        # place
900
        target.open_repository()
901
        # we trust that the working tree sprouting works via the other tests.
902
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
903
        self.assertEqual('1', target.open_branch().last_revision())
904
905
    def test_sprout_bzrdir_tree_revision(self):
906
        # test for revision limiting, [smoke test, not corner case checks].
907
        # make a tree with a revision with a last-revision
908
        # and sprout it with a revision limit.
909
        # This smoke test just checks the revision-id is right. Tree specific
910
        # tests will check corner cases.
911
        tree = self.make_branch_and_tree('source')
912
        self.build_tree(['source/foo'])
913
        tree.add('foo')
914
        tree.commit('revision 1', rev_id='1')
915
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
916
        dir = tree.bzrdir
917
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
918
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
919
920
    def test_sprout_takes_accelerator(self):
921
        tree = self.make_branch_and_tree('source')
922
        self.build_tree(['source/foo'])
923
        tree.add('foo')
924
        tree.commit('revision 1', rev_id='1')
925
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
926
        dir = tree.bzrdir
927
        target = self.sproutOrSkip(dir, self.get_url('target'),
928
                                   accelerator_tree=tree)
929
        self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
930
931
    def test_sprout_branch_no_tree(self):
932
        tree = self.make_branch_and_tree('source')
933
        self.build_tree(['source/foo'])
934
        tree.add('foo')
935
        tree.commit('revision 1', rev_id='1')
936
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
937
        dir = tree.bzrdir
938
        try:
939
            target = dir.sprout(self.get_url('target'),
940
                create_tree_if_local=False)
941
        except errors.MustHaveWorkingTree:
942
            raise TestNotApplicable("control dir format requires working tree")
943
        self.assertPathDoesNotExist('target/foo')
944
        self.assertEqual(tree.branch.last_revision(),
945
                         target.open_branch().last_revision())
946
947
    def test_sprout_with_revision_id_uses_default_stack_on(self):
948
        # Make a branch with three commits to stack on.
949
        builder = self.make_branch_builder('stack-on')
950
        builder.start_series()
951
        builder.build_commit(message='Rev 1.', rev_id='rev-1')
952
        builder.build_commit(message='Rev 2.', rev_id='rev-2')
953
        builder.build_commit(message='Rev 3.', rev_id='rev-3')
954
        builder.finish_series()
955
        stack_on = builder.get_branch()
956
        # Make a bzrdir with a default stacking policy to stack on that branch.
957
        config = self.make_bzrdir('policy-dir').get_config()
958
        try:
959
            config.set_default_stack_on(self.get_url('stack-on'))
960
        except errors.BzrError:
961
            raise TestNotApplicable('Only relevant for stackable formats.')
962
        # Sprout the stacked-on branch into the bzrdir.
963
        sprouted = stack_on.bzrdir.sprout(
964
            self.get_url('policy-dir/sprouted'), revision_id='rev-3')
965
        # Not all revisions are copied into the sprouted repository.
966
        repo = sprouted.open_repository()
967
        self.addCleanup(repo.lock_read().unlock)
968
        self.assertEqual(None, repo.get_parent_map(['rev-1']).get('rev-1'))
969
970
    def test_format_initialize_find_open(self):
971
        # loopback test to check the current format initializes to itself.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
972
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
973
            # unsupported formats are not loopback testable
974
            # because the default open will not open them and
975
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
976
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
977
        # for remote formats, there must be no prior assumption about the
978
        # network name to use - it's possible that this may somehow have got
979
        # in through an unisolated test though - see
980
        # <https://bugs.launchpad.net/bzr/+bug/504102>
981
        self.assertEquals(getattr(self.bzrdir_format,
982
            '_network_name', None),
983
            None)
984
        # supported formats must be able to init and open
985
        t = self.get_transport()
986
        readonly_t = self.get_readonly_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
987
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
988
        self.assertIsInstance(made_control, controldir.ControlDir)
989
        if isinstance(self.bzrdir_format, RemoteBzrDirFormat):
990
            return
991
        self.assertEqual(self.bzrdir_format,
992
                         controldir.ControlDirFormat.find_format(readonly_t))
993
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
994
        opened_dir = bzrdir.BzrDir.open(t.base)
995
        self.assertEqual(made_control._format,
996
                         opened_dir._format)
997
        self.assertEqual(direct_opened_dir._format,
998
                         opened_dir._format)
999
        self.assertIsInstance(opened_dir, controldir.ControlDir)
1000
1001
    def test_format_initialize_on_transport_ex(self):
1002
        t = self.get_transport('dir')
1003
        self.assertInitializeEx(t)
1004
1005
    def test_format_initialize_on_transport_ex_use_existing_dir_True(self):
1006
        t = self.get_transport('dir')
1007
        t.ensure_base()
1008
        self.assertInitializeEx(t, use_existing_dir=True)
1009
1010
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1011
        if not self.bzrdir_format.is_initializable():
1012
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1013
        t = self.get_transport('dir')
1014
        t.ensure_base()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1015
        self.assertRaises(errors.FileExists,
1016
            self.bzrdir_format.initialize_on_transport_ex, t,
1017
            use_existing_dir=False)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1018
1019
    def test_format_initialize_on_transport_ex_create_prefix_True(self):
1020
        t = self.get_transport('missing/dir')
1021
        self.assertInitializeEx(t, create_prefix=True)
1022
1023
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1024
        if not self.bzrdir_format.is_initializable():
1025
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1026
        t = self.get_transport('missing/dir')
1027
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1028
            create_prefix=False)
1029
1030
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1031
        t = self.get_transport('repo')
1032
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1033
        repo_name = repo_fmt.repository_format.network_name()
1034
        repo = repo_fmt.initialize_on_transport_ex(t,
1035
            repo_format_name=repo_name, shared_repo=True)[0]
1036
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1037
            force_new_repo=True, repo_format_name=repo_name)
1038
        self.assertNotEqual(repo.bzrdir.root_transport.base,
1039
            made_repo.bzrdir.root_transport.base)
1040
1041
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1042
        t = self.get_transport('repo')
1043
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1044
        repo_name = repo_fmt.repository_format.network_name()
1045
        repo = repo_fmt.initialize_on_transport_ex(t,
1046
            repo_format_name=repo_name, shared_repo=True)[0]
1047
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1048
            force_new_repo=False, repo_format_name=repo_name)
1049
        if not control._format.fixed_components:
1050
            self.assertEqual(repo.bzrdir.root_transport.base,
1051
                made_repo.bzrdir.root_transport.base)
1052
1053
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1054
        t = self.get_transport('dir')
1055
        repo, control = self.assertInitializeEx(t)
1056
        self.assertEqual(None, repo)
1057
1058
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1059
        t = self.get_transport('dir')
1060
        # 1.6 is likely to never be default
1061
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
1062
        repo_name = fmt.repository_format.network_name()
1063
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1064
        if self.bzrdir_format.fixed_components:
1065
            # must stay with the all-in-one-format.
1066
            repo_name = self.bzrdir_format.network_name()
1067
        self.assertEqual(repo_name, repo._format.network_name())
1068
6164.2.5 by Jelmer Vernooij
Move some stacking tests specific to bzr formats to per_bzrdir.
1069
    def assertInitializeEx(self, t, **kwargs):
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1070
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1071
1072
        This involves checking that the disk objects were created, open with
1073
        the same format returned, and had the expected disk format.
1074
1075
        :param t: The transport to initialize on.
1076
        :param **kwargs: Additional arguments to pass to
1077
            initialize_on_transport_ex.
1078
        :return: the resulting repo, control dir tuple.
1079
        """
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1080
        if not self.bzrdir_format.is_initializable():
1081
            raise TestNotApplicable("control dir format is not "
1082
                "initializable")
1083
        repo, control, require_stacking, repo_policy = \
1084
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1085
        if repo is not None:
1086
            # Repositories are open write-locked
1087
            self.assertTrue(repo.is_write_locked())
1088
            self.addCleanup(repo.unlock)
1089
        self.assertIsInstance(control, controldir.ControlDir)
1090
        opened = bzrdir.BzrDir.open(t.base)
1091
        expected_format = self.bzrdir_format
1092
        if not isinstance(expected_format, RemoteBzrDirFormat):
1093
            self.assertEqual(control._format.network_name(),
1094
                expected_format.network_name())
1095
            self.assertEqual(control._format.network_name(),
1096
                opened._format.network_name())
1097
        self.assertEqual(control.__class__, opened.__class__)
1098
        return repo, control
1099
1100
    def test_format_network_name(self):
1101
        # All control formats must have a network name.
1102
        dir = self.make_bzrdir('.')
1103
        format = dir._format
1104
        # We want to test that the network_name matches the actual format on
1105
        # disk. For local control dirsthat means that using network_name as a
1106
        # key in the registry gives back the same format. For remote obects
1107
        # we check that the network_name of the RemoteBzrDirFormat we have
1108
        # locally matches the actual format present on disk.
1109
        if isinstance(format, RemoteBzrDirFormat):
1110
            dir._ensure_real()
1111
            real_dir = dir._real_bzrdir
1112
            network_name = format.network_name()
1113
            self.assertEqual(real_dir._format.network_name(), network_name)
1114
        else:
1115
            registry = controldir.network_format_registry
1116
            network_name = format.network_name()
1117
            looked_up_format = registry.get(network_name)
1118
            self.assertTrue(
1119
                issubclass(format.__class__, looked_up_format.__class__))
1120
        # The network name must be a byte string.
1121
        self.assertIsInstance(network_name, str)
1122
1123
    def test_open_not_bzrdir(self):
1124
        # test the formats specific behaviour for no-content or similar dirs.
1125
        self.assertRaises(errors.NotBranchError,
1126
                          self.bzrdir_format.open,
1127
                          transport.get_transport_from_url(self.get_readonly_url()))
1128
1129
    def test_create_branch(self):
1130
        # a bzrdir can construct a branch and repository for itself.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1131
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1132
            # unsupported formats are not loopback testable
1133
            # because the default open will not open them and
1134
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1135
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1136
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1137
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1138
        made_repo = made_control.create_repository()
1139
        made_branch = made_control.create_branch()
1140
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1141
        self.assertEqual(made_control, made_branch.bzrdir)
1142
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
1143
    def test_create_branch_append_revisions_only(self):
1144
        # a bzrdir can construct a branch and repository for itself.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1145
        if not self.bzrdir_format.is_initializable():
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
1146
            # unsupported formats are not loopback testable
1147
            # because the default open will not open them and
1148
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1149
            raise TestNotApplicable("format is not initializable")
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
1150
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1151
        made_control = self.bzrdir_format.initialize(t.base)
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
1152
        made_repo = made_control.create_repository()
1153
        try:
1154
            made_branch = made_control.create_branch(
1155
                append_revisions_only=True)
1156
        except errors.UpgradeRequired:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1157
            raise TestNotApplicable("format does not support "
1158
                "append_revisions_only setting")
6123.9.12 by Jelmer Vernooij
Add append_revisions_only argument to BranchFormat.initialize.
1159
        self.assertIsInstance(made_branch, bzrlib.branch.Branch)
1160
        self.assertEquals(True, made_branch.get_append_revisions_only())
1161
        self.assertEqual(made_control, made_branch.bzrdir)
1162
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1163
    def test_open_branch(self):
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1164
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1165
            # unsupported formats are not loopback testable
1166
            # because the default open will not open them and
1167
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1168
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1169
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1170
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1171
        made_repo = made_control.create_repository()
1172
        made_branch = made_control.create_branch()
1173
        opened_branch = made_control.open_branch()
1174
        self.assertEqual(made_control, opened_branch.bzrdir)
1175
        self.assertIsInstance(opened_branch, made_branch.__class__)
1176
        self.assertIsInstance(opened_branch._format, made_branch._format.__class__)
1177
1178
    def test_list_branches(self):
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1179
        if not self.bzrdir_format.is_initializable():
1180
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1181
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1182
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1183
        made_repo = made_control.create_repository()
1184
        made_branch = made_control.create_branch()
1185
        branches = made_control.list_branches()
6282.5.7 by Neil Martinsen-Burrell
undo left-over change
1186
        self.assertEquals(1, len(branches))
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1187
        self.assertEquals(made_branch.base, branches[0].base)
1188
        try:
1189
            made_control.destroy_branch()
1190
        except errors.UnsupportedOperation:
1191
            pass # Not all bzrdirs support destroying directories
1192
        else:
1193
            self.assertEquals([], made_control.list_branches())
1194
6282.5.4 by Neil Martinsen-Burrell
add get_branches method to return a dictionary of names and branches
1195
    def test_get_branches(self):
1196
        repo = self.make_repository('branch-1')
1197
        target_branch = repo.bzrdir.create_branch()
6436.1.1 by Jelmer Vernooij
Change default branch name to "".
1198
        self.assertEqual([""], repo.bzrdir.get_branches().keys())
6282.5.4 by Neil Martinsen-Burrell
add get_branches method to return a dictionary of names and branches
1199
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1200
    def test_create_repository(self):
1201
        # a bzrdir can construct a repository for itself.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1202
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1203
            # unsupported formats are not loopback testable
1204
            # because the default open will not open them and
1205
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1206
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1207
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1208
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1209
        made_repo = made_control.create_repository()
1210
        # Check that we have a repository object.
1211
        made_repo.has_revision('foo')
1212
        self.assertEqual(made_control, made_repo.bzrdir)
1213
1214
    def test_create_repository_shared(self):
1215
        # a bzrdir can create a shared repository or
1216
        # fail appropriately
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1217
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1218
            # unsupported formats are not loopback testable
1219
            # because the default open will not open them and
1220
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1221
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1222
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1223
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1224
        try:
1225
            made_repo = made_control.create_repository(shared=True)
1226
        except errors.IncompatibleFormat:
1227
            # Old bzrdir formats don't support shared repositories
1228
            # and should raise IncompatibleFormat
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1229
            raise TestNotApplicable("format does not support shared "
1230
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1231
        self.assertTrue(made_repo.is_shared())
1232
1233
    def test_create_repository_nonshared(self):
1234
        # a bzrdir can create a non-shared repository
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1235
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1236
            # unsupported formats are not loopback testable
1237
            # because the default open will not open them and
1238
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1239
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1240
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1241
        made_control = self.bzrdir_format.initialize(t.base)
6123.9.10 by Jelmer Vernooij
Improve tag handling.
1242
        try:
1243
            made_repo = made_control.create_repository(shared=False)
1244
        except errors.IncompatibleFormat:
1245
            # Some control dir formats don't support non-shared repositories
1246
            # and should raise IncompatibleFormat
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1247
            raise TestNotApplicable("format does not support shared "
1248
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1249
        self.assertFalse(made_repo.is_shared())
1250
1251
    def test_open_repository(self):
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1252
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1253
            # unsupported formats are not loopback testable
1254
            # because the default open will not open them and
1255
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1256
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1257
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1258
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1259
        made_repo = made_control.create_repository()
1260
        opened_repo = made_control.open_repository()
1261
        self.assertEqual(made_control, opened_repo.bzrdir)
1262
        self.assertIsInstance(opened_repo, made_repo.__class__)
1263
        self.assertIsInstance(opened_repo._format, made_repo._format.__class__)
1264
1265
    def test_create_workingtree(self):
1266
        # a bzrdir can construct a working tree for itself.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1267
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1268
            # unsupported formats are not loopback testable
1269
            # because the default open will not open them and
1270
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1271
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1272
        t = self.get_transport()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1273
        made_control = self.bzrdir_format.initialize(t.base)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1274
        made_repo = made_control.create_repository()
1275
        made_branch = made_control.create_branch()
1276
        made_tree = self.createWorkingTreeOrSkip(made_control)
1277
        self.assertIsInstance(made_tree, workingtree.WorkingTree)
1278
        self.assertEqual(made_control, made_tree.bzrdir)
1279
1280
    def test_create_workingtree_revision(self):
1281
        # a bzrdir can construct a working tree for itself @ a specific revision.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1282
        if not self.bzrdir_format.is_initializable():
1283
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1284
        t = self.get_transport()
1285
        source = self.make_branch_and_tree('source')
1286
        source.commit('a', rev_id='a', allow_pointless=True)
1287
        source.commit('b', rev_id='b', allow_pointless=True)
1288
        t.mkdir('new')
1289
        t_new = t.clone('new')
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1290
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1291
        source.branch.repository.clone(made_control)
1292
        source.branch.clone(made_control)
1293
        try:
1294
            made_tree = made_control.create_workingtree(revision_id='a')
1295
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1296
            raise TestSkipped("Can't make working tree on transport %r" % t)
1297
        self.assertEqual(['a'], made_tree.get_parent_ids())
1298
1299
    def test_open_workingtree(self):
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1300
        if not self.bzrdir_format.is_initializable():
1301
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1302
        # this has to be tested with local access as we still support creating
1303
        # format 6 bzrdirs
1304
        t = self.get_transport()
1305
        try:
1306
            made_control = self.bzrdir_format.initialize(t.base)
1307
            made_repo = made_control.create_repository()
1308
            made_branch = made_control.create_branch()
1309
            made_tree = made_control.create_workingtree()
1310
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1311
            raise TestSkipped("Can't initialize %r on transport %r"
1312
                              % (self.bzrdir_format, t))
1313
        opened_tree = made_control.open_workingtree()
1314
        self.assertEqual(made_control, opened_tree.bzrdir)
1315
        self.assertIsInstance(opened_tree, made_tree.__class__)
1316
        self.assertIsInstance(opened_tree._format, made_tree._format.__class__)
1317
1318
    def test_get_selected_branch(self):
1319
        # The segment parameters are accessible from the root transport
1320
        # if a URL with segment parameters is opened.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1321
        if not self.bzrdir_format.is_initializable():
1322
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1323
        t = self.get_transport()
1324
        try:
1325
            made_control = self.bzrdir_format.initialize(t.base)
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1326
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1327
            raise TestSkipped("Can't initialize %r on transport %r"
1328
                              % (self.bzrdir_format, t))
1329
        dir = bzrdir.BzrDir.open(t.base+",branch=foo")
1330
        self.assertEquals({"branch": "foo"},
1331
            dir.user_transport.get_segment_parameters())
1332
        self.assertEquals("foo", dir._get_selected_branch())
1333
1334
    def test_get_selected_branch_none_selected(self):
1335
        # _get_selected_branch defaults to None
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1336
        if not self.bzrdir_format.is_initializable():
1337
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1338
        t = self.get_transport()
1339
        try:
1340
            made_control = self.bzrdir_format.initialize(t.base)
1341
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1342
            raise TestSkipped("Can't initialize %r on transport %r"
1343
                              % (self.bzrdir_format, t))
1344
        dir = bzrdir.BzrDir.open(t.base)
6436.1.1 by Jelmer Vernooij
Change default branch name to "".
1345
        self.assertEqual(u"", dir._get_selected_branch())
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1346
1347
    def test_root_transport(self):
1348
        dir = self.make_bzrdir('.')
1349
        self.assertEqual(dir.root_transport.base,
1350
                         self.get_transport().base)
1351
1352
    def test_find_repository_no_repo_under_standalone_branch(self):
1353
        # finding a repo stops at standalone branches even if there is a
1354
        # higher repository available.
1355
        try:
1356
            repo = self.make_repository('.', shared=True)
1357
        except errors.IncompatibleFormat:
1358
            # need a shared repository to test this.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1359
            raise TestNotApplicable("requires shared repository support")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
1360
        if not repo._format.supports_nesting_repositories:
1361
            raise TestNotApplicable("requires nesting repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1362
        url = self.get_url('intermediate')
1363
        t = self.get_transport()
1364
        t.mkdir('intermediate')
1365
        t.mkdir('intermediate/child')
1366
        made_control = self.bzrdir_format.initialize(url)
1367
        made_control.create_repository()
1368
        innermost_control = self.bzrdir_format.initialize(
1369
            self.get_url('intermediate/child'))
1370
        try:
1371
            child_repo = innermost_control.open_repository()
1372
            # if there is a repository, then the format cannot ever hit this
1373
            # code path.
1374
            return
1375
        except errors.NoRepositoryPresent:
1376
            pass
1377
        self.assertRaises(errors.NoRepositoryPresent,
1378
                          innermost_control.find_repository)
1379
1380
    def test_find_repository_containing_shared_repository(self):
1381
        # find repo inside a shared repo with an empty control dir
1382
        # returns the shared repo.
1383
        try:
1384
            repo = self.make_repository('.', shared=True)
1385
        except errors.IncompatibleFormat:
1386
            # need a shared repository to test this.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1387
            raise TestNotApplicable("requires format with shared repository "
1388
                "support")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
1389
        if not repo._format.supports_nesting_repositories:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1390
            raise TestNotApplicable("requires support for nesting "
1391
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1392
        url = self.get_url('childbzrdir')
1393
        self.get_transport().mkdir('childbzrdir')
1394
        made_control = self.bzrdir_format.initialize(url)
1395
        try:
1396
            child_repo = made_control.open_repository()
1397
            # if there is a repository, then the format cannot ever hit this
1398
            # code path.
1399
            return
1400
        except errors.NoRepositoryPresent:
1401
            pass
1402
        found_repo = made_control.find_repository()
1403
        self.assertEqual(repo.bzrdir.root_transport.base,
1404
                         found_repo.bzrdir.root_transport.base)
1405
1406
    def test_find_repository_standalone_with_containing_shared_repository(self):
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
1407
        # find repo inside a standalone repo inside a shared repo finds the
1408
        # standalone repo
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1409
        try:
1410
            containing_repo = self.make_repository('.', shared=True)
1411
        except errors.IncompatibleFormat:
1412
            # need a shared repository to test this.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1413
            raise TestNotApplicable("requires support for shared "
1414
                "repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
1415
        if not containing_repo._format.supports_nesting_repositories:
1416
            raise TestNotApplicable("format does not support "
1417
                "nesting repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1418
        child_repo = self.make_repository('childrepo')
1419
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1420
        found_repo = opened_control.find_repository()
1421
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1422
                         found_repo.bzrdir.root_transport.base)
1423
1424
    def test_find_repository_shared_within_shared_repository(self):
1425
        # find repo at a shared repo inside a shared repo finds the inner repo
1426
        try:
1427
            containing_repo = self.make_repository('.', shared=True)
1428
        except errors.IncompatibleFormat:
1429
            # need a shared repository to test this.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1430
            raise TestNotApplicable("requires support for shared "
1431
                "repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
1432
        if not containing_repo._format.supports_nesting_repositories:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1433
            raise TestNotApplicable("requires support for nesting "
1434
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1435
        url = self.get_url('childrepo')
1436
        self.get_transport().mkdir('childrepo')
1437
        child_control = self.bzrdir_format.initialize(url)
1438
        child_repo = child_control.create_repository(shared=True)
1439
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1440
        found_repo = opened_control.find_repository()
1441
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1442
                         found_repo.bzrdir.root_transport.base)
1443
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1444
                            containing_repo.bzrdir.root_transport.base)
1445
1446
    def test_find_repository_with_nested_dirs_works(self):
1447
        # find repo inside a bzrdir inside a bzrdir inside a shared repo
1448
        # finds the outer shared repo.
1449
        try:
1450
            repo = self.make_repository('.', shared=True)
1451
        except errors.IncompatibleFormat:
1452
            # need a shared repository to test this.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1453
            raise TestNotApplicable("requires support for shared "
1454
                "repositories")
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
1455
        if not repo._format.supports_nesting_repositories:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1456
            raise TestNotApplicable("requires support for nesting "
1457
                "repositories")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1458
        url = self.get_url('intermediate')
1459
        t = self.get_transport()
1460
        t.mkdir('intermediate')
1461
        t.mkdir('intermediate/child')
1462
        made_control = self.bzrdir_format.initialize(url)
1463
        try:
1464
            child_repo = made_control.open_repository()
1465
            # if there is a repository, then the format cannot ever hit this
1466
            # code path.
1467
            return
1468
        except errors.NoRepositoryPresent:
1469
            pass
1470
        innermost_control = self.bzrdir_format.initialize(
1471
            self.get_url('intermediate/child'))
1472
        try:
1473
            child_repo = innermost_control.open_repository()
1474
            # if there is a repository, then the format cannot ever hit this
1475
            # code path.
1476
            return
1477
        except errors.NoRepositoryPresent:
1478
            pass
1479
        found_repo = innermost_control.find_repository()
1480
        self.assertEqual(repo.bzrdir.root_transport.base,
1481
                         found_repo.bzrdir.root_transport.base)
1482
1483
    def test_can_and_needs_format_conversion(self):
1484
        # check that we can ask an instance if its upgradable
1485
        dir = self.make_bzrdir('.')
1486
        if dir.can_convert_format():
1487
            # if its default updatable there must be an updater
1488
            # (we force the latest known format as downgrades may not be
1489
            # available
1490
            self.assertTrue(isinstance(dir._format.get_converter(
1491
                format=dir._format), controldir.Converter))
1492
        dir.needs_format_conversion(
1493
            controldir.ControlDirFormat.get_default_format())
1494
1495
    def test_backup_copies_existing(self):
1496
        tree = self.make_branch_and_tree('test')
1497
        self.build_tree(['test/a'])
1498
        tree.add(['a'], ['a-id'])
1499
        tree.commit('some data to be copied.')
1500
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1501
        old_path = urlutils.local_path_from_url(old_url)
1502
        new_path = urlutils.local_path_from_url(new_url)
1503
        self.assertPathExists(old_path)
1504
        self.assertPathExists(new_path)
1505
        for (((dir_relpath1, _), entries1),
1506
             ((dir_relpath2, _), entries2)) in izip(
1507
                osutils.walkdirs(old_path),
1508
                osutils.walkdirs(new_path)):
1509
            self.assertEquals(dir_relpath1, dir_relpath2)
1510
            for f1, f2 in zip(entries1, entries2):
1511
                self.assertEquals(f1[0], f2[0])
1512
                self.assertEquals(f1[2], f2[2])
1513
                if f1[2] == "file":
1514
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1515
1516
    def test_upgrade_new_instance(self):
1517
        """Does an available updater work?"""
1518
        dir = self.make_bzrdir('.')
1519
        # for now, upgrade is not ready for partial bzrdirs.
1520
        dir.create_repository()
1521
        dir.create_branch()
1522
        self.createWorkingTreeOrSkip(dir)
1523
        if dir.can_convert_format():
1524
            # if its default updatable there must be an updater
1525
            # (we force the latest known format as downgrades may not be
1526
            # available
1527
            pb = ui.ui_factory.nested_progress_bar()
1528
            try:
1529
                dir._format.get_converter(format=dir._format).convert(dir, pb)
1530
            finally:
1531
                pb.finished()
1532
            # and it should pass 'check' now.
1533
            check.check_dwim(self.get_url('.'), False, True, True)
1534
1535
    def test_format_description(self):
1536
        dir = self.make_bzrdir('.')
1537
        text = dir._format.get_format_description()
1538
        self.assertTrue(len(text))
1539
1540
1541
class TestBreakLock(TestCaseWithControlDir):
1542
1543
    def test_break_lock_empty(self):
1544
        # break lock on an empty bzrdir should work silently.
1545
        dir = self.make_bzrdir('.')
1546
        try:
1547
            dir.break_lock()
1548
        except NotImplementedError:
1549
            pass
1550
1551
    def test_break_lock_repository(self):
1552
        # break lock with just a repo should unlock the repo.
1553
        repo = self.make_repository('.')
1554
        repo.lock_write()
1555
        lock_repo = repo.bzrdir.open_repository()
1556
        if not lock_repo.get_physical_lock_status():
1557
            # This bzrdir's default repository does not physically lock things
1558
            # and thus this interaction cannot be tested at the interface
1559
            # level.
1560
            repo.unlock()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1561
            raise TestNotApplicable("format does not physically lock")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1562
        # only one yes needed here: it should only be unlocking
1563
        # the repo
1564
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1565
        try:
1566
            repo.bzrdir.break_lock()
1567
        except NotImplementedError:
1568
            # this bzrdir does not implement break_lock - so we cant test it.
1569
            repo.unlock()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1570
            raise TestNotApplicable("format does not support breaking locks")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1571
        lock_repo.lock_write()
1572
        lock_repo.unlock()
1573
        self.assertRaises(errors.LockBroken, repo.unlock)
1574
1575
    def test_break_lock_branch(self):
1576
        # break lock with just a repo should unlock the branch.
1577
        # and not directly try the repository.
1578
        # we test this by making a branch reference to a branch
1579
        # and repository in another bzrdir
1580
        # for pre-metadir formats this will fail, thats ok.
1581
        master = self.make_branch('branch')
1582
        thisdir = self.make_bzrdir('this')
1583
        try:
1584
            bzrlib.branch.BranchReferenceFormat().initialize(
1585
                thisdir, target_branch=master)
1586
        except errors.IncompatibleFormat:
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1587
            raise TestNotApplicable("format does not support "
1588
                "branch references")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1589
        unused_repo = thisdir.create_repository()
1590
        master.lock_write()
1591
        unused_repo.lock_write()
1592
        try:
1593
            # two yes's : branch and repository. If the repo in this
1594
            # dir is inappropriately accessed, 3 will be needed, and
1595
            # we'll see that because the stream will be fully consumed
1596
            bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1597
            # determine if the repository will have been locked;
1598
            this_repo_locked = \
1599
                thisdir.open_repository().get_physical_lock_status()
1600
            master.bzrdir.break_lock()
1601
            if this_repo_locked:
1602
                # only two ys should have been read
1603
                self.assertEqual([True],
1604
                    bzrlib.ui.ui_factory.responses)
1605
            else:
1606
                # only one y should have been read
1607
                self.assertEqual([True, True],
1608
                    bzrlib.ui.ui_factory.responses)
1609
            # we should be able to lock a newly opened branch now
1610
            branch = master.bzrdir.open_branch()
1611
            branch.lock_write()
1612
            branch.unlock()
1613
            if this_repo_locked:
1614
                # we should not be able to lock the repository in thisdir as
1615
                # its still held by the explicit lock we took, and the break
1616
                # lock should not have touched it.
1617
                repo = thisdir.open_repository()
1618
                self.assertRaises(errors.LockContention, repo.lock_write)
1619
        finally:
1620
            unused_repo.unlock()
1621
        self.assertRaises(errors.LockBroken, master.unlock)
1622
1623
    def test_break_lock_tree(self):
1624
        # break lock with a tree should unlock the tree but not try the
1625
        # branch explicitly. However this is very hard to test for as we
1626
        # dont have a tree reference class, nor is one needed;
1627
        # the worst case if this code unlocks twice is an extra question
1628
        # being asked.
1629
        tree = self.make_branch_and_tree('.')
1630
        tree.lock_write()
1631
        # three yes's : tree, branch and repository.
1632
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1633
        try:
1634
            tree.bzrdir.break_lock()
1635
        except (NotImplementedError, errors.LockActive):
1636
            # bzrdir does not support break_lock
1637
            # or one of the locked objects (currently only tree does this)
1638
            # raised a LockActive because we do still have a live locked
1639
            # object.
1640
            tree.unlock()
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1641
            raise TestNotApplicable("format does not support breaking locks")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1642
        self.assertEqual([True],
1643
                bzrlib.ui.ui_factory.responses)
1644
        lock_tree = tree.bzrdir.open_workingtree()
1645
        lock_tree.lock_write()
1646
        lock_tree.unlock()
1647
        self.assertRaises(errors.LockBroken, tree.unlock)
1648
1649
1650
class TestTransportConfig(TestCaseWithControlDir):
1651
1652
    def test_get_config(self):
1653
        my_dir = self.make_bzrdir('.')
1654
        config = my_dir.get_config()
1655
        try:
1656
            config.set_default_stack_on('http://example.com')
1657
        except errors.BzrError, e:
1658
            if 'Cannot set config' in str(e):
1659
                self.assertFalse(
1660
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1661
                    "%r should support configs" % my_dir)
1662
                raise TestNotApplicable(
1663
                    'This BzrDir format does not support configs.')
1664
            else:
1665
                raise
1666
        self.assertEqual('http://example.com', config.get_default_stack_on())
1667
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
1668
        config2 = my_dir2.get_config()
1669
        self.assertEqual('http://example.com', config2.get_default_stack_on())
1670
1671
1672
class ChrootedControlDirTests(ChrootedTestCase):
1673
1674
    def test_find_repository_no_repository(self):
1675
        # loopback test to check the current format fails to find a
1676
        # share repository correctly.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1677
        if not self.bzrdir_format.is_initializable():
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1678
            # unsupported formats are not loopback testable
1679
            # because the default open will not open them and
1680
            # they may not be initializable.
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1681
            raise TestNotApplicable("format is not initializable")
6083.1.2 by Jelmer Vernooij
Revert unnecessary changes.
1682
        # supported formats must be able to init and open
1683
        # - do the vfs initialisation over the basic vfs transport
1684
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1685
        url = self.get_vfs_only_url('subdir')
1686
        transport.get_transport_from_url(self.get_vfs_only_url()).mkdir('subdir')
6162.3.4 by Jelmer Vernooij
Use TestNotApplicable rather than returning directly.
1687
        made_control = self.bzrdir_format.initialize(self.get_url('subdir'))
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.
1688
        try:
1689
            repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1690
            # if there is a repository, then the format cannot ever hit this
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.
1691
            # code path.
1692
            return
1693
        except errors.NoRepositoryPresent:
1694
            pass
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1695
        made_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
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.
1696
        self.assertRaises(errors.NoRepositoryPresent,
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1697
                          made_control.find_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.
1698
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
1699
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
1700
class TestControlDirControlComponent(TestCaseWithControlDir):
1701
    """ControlDir implementations adequately implement ControlComponent."""
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1702
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
1703
    def test_urls(self):
1704
        bd = self.make_bzrdir('bd')
1705
        self.assertIsInstance(bd.user_url, str)
1706
        self.assertEqual(bd.user_url, bd.user_transport.base)
1707
        # for all current bzrdir implementations the user dir must be 
1708
        # above the control dir but we might need to relax that?
1709
        self.assertEqual(bd.control_url.find(bd.user_url), 0)
1710
        self.assertEqual(bd.control_url, bd.control_transport.base)