/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
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
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
12
#
1534.4.39 by Robert Collins
Basic BzrDir support.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.39 by Robert Collins
Basic BzrDir support.
16
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
17
"""Tests for control directory implementations - tests a controldir format."""
1534.4.39 by Robert Collins
Basic BzrDir support.
18
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
19
from itertools import izip
1534.4.39 by Robert Collins
Basic BzrDir support.
20
1508.1.25 by Robert Collins
Update per review comments.
21
import bzrlib.branch
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
22
from bzrlib import (
23
    bzrdir,
4332.3.36 by Robert Collins
Silence a warning in test_bzrdir.
24
    check,
5363.2.3 by Jelmer Vernooij
Add ControlDirFormat.
25
    controldir,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
26
    errors,
4695.2.2 by Vincent Ladeuil
There is no good reason for not writing a test.
27
    gpg,
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
28
    osutils,
5671.3.1 by Jelmer Vernooij
Use stub format for tests in bzrlib.tests.per_controldir.test_controldir..
29
    repository,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
30
    transport,
31
    ui,
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
32
    urlutils,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
33
    workingtree,
34
    )
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
35
import bzrlib.revision
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.
36
from bzrlib.tests import (
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
37
    fixtures,
5582.9.6 by Jelmer Vernooij
More cleanups, remove more dependencies on specific formats.
38
    ChrootedTestCase,
39
    TestNotApplicable,
40
    TestSkipped,
41
    )
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
42
from bzrlib.tests.per_controldir import TestCaseWithControlDir
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
43
from bzrlib.transport.local import LocalTransport
4449.3.25 by Martin Pool
Move CannedInputUIFactory to bzrlib.ui for reuse
44
from bzrlib.ui import (
45
    CannedInputUIFactory,
46
    )
5582.9.6 by Jelmer Vernooij
More cleanups, remove more dependencies on specific formats.
47
from bzrlib.remote import (
48
    RemoteBzrDir,
49
    RemoteRepository,
50
    )
5671.3.1 by Jelmer Vernooij
Use stub format for tests in bzrlib.tests.per_controldir.test_controldir..
51
52
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
53
class TestControlDir(TestCaseWithControlDir):
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
54
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
55
    def skipIfNoWorkingTree(self, a_bzrdir):
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
56
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
57
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
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
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
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
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
74
    def createWorkingTreeOrSkip(self, a_bzrdir):
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
75
        """Create a working tree on a_bzrdir, or raise TestSkipped.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
76
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
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()
5418.3.1 by Jelmer Vernooij
Cope with control directories that are local but can't have working trees.
82
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
83
            raise TestSkipped("cannot make working tree with transport %r"
84
                              % a_bzrdir.transport)
85
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
86
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
87
                     force_new_repo=False, accelerator_tree=None,
3983.1.7 by Daniel Watkins
Review comments from jam.
88
                     create_tree_if_local=True):
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
89
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
90
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
91
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
92
        TestSkipped.  Returns the newly sprouted bzrdir.
93
        """
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
94
        to_transport = transport.get_transport(to_url)
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
95
        if not isinstance(to_transport, LocalTransport):
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
96
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
97
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
98
                                    force_new_repo=force_new_repo,
3123.5.8 by Aaron Bentley
Work around double-opening lock issue
99
                                    possible_transports=[to_transport],
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
100
                                    accelerator_tree=accelerator_tree,
3983.1.7 by Daniel Watkins
Review comments from jam.
101
                                    create_tree_if_local=create_tree_if_local)
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
102
        return target
103
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
104
    def test_create_null_workingtree(self):
105
        dir = self.make_bzrdir('dir1')
106
        dir.create_repository()
107
        dir.create_branch()
1752.2.87 by Andrew Bennetts
Make tests pass.
108
        try:
109
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
5418.3.1 by Jelmer Vernooij
Cope with control directories that are local but can't have working trees.
110
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1752.2.87 by Andrew Bennetts
Make tests pass.
111
            raise TestSkipped("cannot make working tree with transport %r"
112
                              % dir.transport)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
113
        self.assertEqual([], wt.get_parent_ids())
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
114
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
115
    def test_destroy_workingtree(self):
116
        tree = self.make_branch_and_tree('tree')
117
        self.build_tree(['tree/file'])
118
        tree.add('file')
119
        tree.commit('first commit')
120
        bzrdir = tree.bzrdir
121
        try:
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
122
            bzrdir.destroy_workingtree()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
123
        except errors.UnsupportedOperation:
124
            raise TestSkipped('Format does not support destroying tree')
125
        self.failIfExists('tree/file')
126
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
127
        bzrdir.create_workingtree()
128
        self.failUnlessExists('tree/file')
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
129
        bzrdir.destroy_workingtree_metadata()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
130
        self.failUnlessExists('tree/file')
131
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
132
2796.2.6 by Aaron Bentley
Implement destroy_branch
133
    def test_destroy_branch(self):
134
        branch = self.make_branch('branch')
135
        bzrdir = branch.bzrdir
136
        try:
137
            bzrdir.destroy_branch()
138
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
5051.3.7 by Jelmer Vernooij
Review comments from Vincent.
139
            raise TestNotApplicable('Format does not support destroying branch')
2796.2.6 by Aaron Bentley
Implement destroy_branch
140
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
141
        bzrdir.create_branch()
142
        bzrdir.open_branch()
143
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
144
    def test_destroy_repository(self):
145
        repo = self.make_repository('repository')
146
        bzrdir = repo.bzrdir
147
        try:
148
            bzrdir.destroy_repository()
149
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
150
            raise TestNotApplicable('Format does not support destroying'
151
                                    ' repository')
152
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
153
        bzrdir.create_repository()
154
        bzrdir.open_repository()
155
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
156
    def test_open_workingtree_raises_no_working_tree(self):
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
157
        """ControlDir.open_workingtree() should raise NoWorkingTree (rather than
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
158
        e.g. NotLocalUrl) if there is no working tree.
159
        """
160
        dir = self.make_bzrdir('source')
161
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
162
        if vfs_dir.has_workingtree():
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
163
            # This ControlDir format doesn't support ControlDirs without
164
            # working trees, so this test is irrelevant.
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
165
            return
166
        self.assertRaises(errors.NoWorkingTree, dir.open_workingtree)
2475.3.1 by John Arbash Meinel
Fix bug #75721. Update the BzrDir api to add clone_on_transport()
167
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.
168
    def test_clone_bzrdir_repository_under_shared(self):
1534.1.33 by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations.
169
        tree = self.make_branch_and_tree('commit_tree')
170
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
171
        tree.add('foo')
172
        tree.commit('revision 1', rev_id='1')
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.
173
        dir = self.make_bzrdir('source')
174
        repo = dir.create_repository()
1534.1.33 by Robert Collins
Move copy_content_into into InterRepository and InterWeaveRepo, and disable the default codepath test as we have optimised paths for all current combinations.
175
        repo.fetch(tree.branch.repository)
176
        self.assertTrue(repo.has_revision('1'))
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.
177
        try:
178
            self.make_repository('target', shared=True)
179
        except errors.IncompatibleFormat:
180
            return
181
        target = dir.clone(self.get_url('target/child'))
182
        self.assertNotEqual(dir.transport.base, target.transport.base)
183
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
184
185
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
186
        # Create a shared repository
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
187
        try:
188
            shared_repo = self.make_repository('shared', shared=True)
189
        except errors.IncompatibleFormat:
190
            return
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
191
        # Make a branch, 'commit_tree', and working tree outside of the shared
192
        # repository, and commit some revisions to it.
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
193
        tree = self.make_branch_and_tree('commit_tree')
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
194
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
195
        tree.add('foo')
196
        tree.commit('revision 1', rev_id='1')
197
        tree.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
198
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
199
        tree.commit('revision 2', rev_id='2')
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
200
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
201
        # repository into the shared repository.
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
202
        tree.branch.repository.copy_content_into(shared_repo)
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
203
        # Make a branch 'source' inside the shared repository.
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
204
        dir = self.make_bzrdir('shared/source')
205
        dir.create_branch()
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
206
        # Clone 'source' to 'target', also inside the shared repository.
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
207
        target = dir.clone(self.get_url('shared/target'))
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
208
        # 'source', 'target', and the shared repo all have distinct bzrdirs.
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
209
        self.assertNotEqual(dir.transport.base, target.transport.base)
210
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
211
        # The shared repository will contain revisions from the 'commit_tree'
212
        # repository, even revisions that are not part of the history of the
213
        # 'commit_tree' branch.
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
214
        self.assertTrue(shared_repo.has_revision('1'))
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
215
216
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
217
        try:
218
            shared_repo = self.make_repository('shared', shared=True)
219
        except errors.IncompatibleFormat:
220
            return
221
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
222
        self.build_tree(['commit_tree/foo'])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
223
        tree.add('foo')
224
        tree.commit('revision 1', rev_id='1')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
225
        tree.branch.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
226
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
227
        tree.commit('revision 2', rev_id='2')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
228
        tree.branch.repository.copy_content_into(shared_repo)
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
229
        if shared_repo.make_working_trees():
230
            shared_repo.set_make_working_trees(False)
231
            self.assertFalse(shared_repo.make_working_trees())
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
232
        self.assertTrue(shared_repo.has_revision('1'))
233
        dir = self.make_bzrdir('shared/source')
234
        dir.create_branch()
235
        target = dir.clone(self.get_url('target'))
236
        self.assertNotEqual(dir.transport.base, target.transport.base)
237
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
238
        branch = target.open_branch()
239
        self.assertTrue(branch.repository.has_revision('1'))
240
        self.assertFalse(branch.repository.make_working_trees())
241
        self.assertTrue(branch.repository.is_shared())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
242
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
243
    def test_clone_bzrdir_repository_revision(self):
244
        # test for revision limiting, [smoke test, not corner case checks].
245
        # make a repository with some revisions,
246
        # and clone it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
247
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
248
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
249
        self.build_tree(['commit_tree/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
250
        tree.add('foo')
251
        tree.commit('revision 1', rev_id='1')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
252
        tree.branch.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
253
        tree.set_parent_trees([])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
254
        tree.commit('revision 2', rev_id='2')
255
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
256
        tree.branch.repository.copy_content_into(source)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
257
        dir = source.bzrdir
258
        target = dir.clone(self.get_url('target'), revision_id='2')
259
        raise TestSkipped('revision limiting not strict yet')
260
4695.2.2 by Vincent Ladeuil
There is no good reason for not writing a test.
261
    def test_clone_bzrdir_branch_and_repo_fixed_user_id(self):
262
        # Bug #430868 is about an email containing '.sig'
5570.3.9 by Vincent Ladeuil
More use cases for overrideEnv, _cleanEnvironment *may* contain too much variables now.
263
        self.overrideEnv('BZR_EMAIL', 'murphy@host.sighup.org')
4695.2.2 by Vincent Ladeuil
There is no good reason for not writing a test.
264
        tree = self.make_branch_and_tree('commit_tree')
265
        self.build_tree(['commit_tree/foo'])
266
        tree.add('foo')
267
        rev1 = tree.commit('revision 1')
268
        tree_repo = tree.branch.repository
269
        tree_repo.lock_write()
270
        tree_repo.start_write_group()
271
        tree_repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
272
        tree_repo.commit_write_group()
273
        tree_repo.unlock()
274
        target = self.make_branch('target')
275
        tree.branch.repository.copy_content_into(target.repository)
276
        tree.branch.copy_content_into(target)
277
        self.assertTrue(target.repository.has_revision(rev1))
278
        self.assertEqual(
279
            tree_repo.get_signature_text(rev1),
280
            target.repository.get_signature_text(rev1))
281
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.
282
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
283
        # by default cloning into a shared repo uses the shared repo.
284
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
285
        self.build_tree(['commit_tree/foo'])
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.
286
        tree.add('foo')
287
        tree.commit('revision 1')
288
        source = self.make_branch('source')
2018.5.108 by Andrew Bennetts
Fix some tests in bzrdir_implementations that assumed make_branch_and_tree returns a tree with the same bzrdir as the branch.
289
        tree.branch.repository.copy_content_into(source.repository)
290
        tree.branch.copy_content_into(source)
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.
291
        try:
292
            self.make_repository('target', shared=True)
293
        except errors.IncompatibleFormat:
294
            return
295
        dir = source.bzrdir
296
        target = dir.clone(self.get_url('target/child'))
297
        self.assertNotEqual(dir.transport.base, target.transport.base)
298
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
299
        self.assertEqual(source.revision_history(),
300
                         target.open_branch().revision_history())
301
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
302
    def test_clone_bzrdir_branch_revision(self):
303
        # test for revision limiting, [smoke test, not corner case checks].
304
        # make a branch with some revisions,
305
        # and clone it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
306
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
307
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
308
        self.build_tree(['commit_tree/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
309
        tree.add('foo')
310
        tree.commit('revision 1', rev_id='1')
311
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
312
        source = self.make_branch('source')
2018.5.108 by Andrew Bennetts
Fix some tests in bzrdir_implementations that assumed make_branch_and_tree returns a tree with the same bzrdir as the branch.
313
        tree.branch.repository.copy_content_into(source.repository)
314
        tree.branch.copy_content_into(source)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
315
        dir = source.bzrdir
316
        target = dir.clone(self.get_url('target'), revision_id='1')
317
        self.assertEqual('1', target.open_branch().last_revision())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
318
3242.2.14 by Aaron Bentley
Update from review comments
319
    def test_clone_on_transport_preserves_repo_format(self):
320
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
321
            format = 'knit'
322
        else:
323
            format = None
324
        source_branch = self.make_branch('source', format=format)
325
        # Ensure no format data is cached
326
        a_dir = bzrlib.branch.Branch.open_from_transport(
327
            self.get_transport('source')).bzrdir
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
328
        target_transport = self.get_transport('target')
3242.2.14 by Aaron Bentley
Update from review comments
329
        target_bzrdir = a_dir.clone_on_transport(target_transport)
330
        target_repo = target_bzrdir.open_repository()
3242.3.29 by Aaron Bentley
Fix failing test
331
        source_branch = bzrlib.branch.Branch.open(
332
            self.get_vfs_only_url('source'))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
333
        if isinstance(target_repo, RemoteRepository):
334
            target_repo._ensure_real()
335
            target_repo = target_repo._real_repository
3242.2.14 by Aaron Bentley
Update from review comments
336
        self.assertEqual(target_repo._format, source_branch.repository._format)
337
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
338
    def test_clone_bzrdir_tree_revision(self):
339
        # test for revision limiting, [smoke test, not corner case checks].
340
        # make a tree with a revision with a last-revision
341
        # and clone it with a revision limit.
342
        # This smoke test just checks the revision-id is right. Tree specific
343
        # tests will check corner cases.
344
        tree = self.make_branch_and_tree('source')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
345
        self.build_tree(['source/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
346
        tree.add('foo')
347
        tree.commit('revision 1', rev_id='1')
348
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
349
        dir = tree.bzrdir
350
        target = dir.clone(self.get_url('target'), revision_id='1')
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
351
        self.skipIfNoWorkingTree(target)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
352
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
353
2991.1.1 by Daniel Watkins
Added (failing) test to ensure that bzrdir.clone won't create a working tree in a no-trees repository.
354
    def test_clone_bzrdir_into_notrees_repo(self):
355
        """Cloning into a no-trees repo should not create a working tree"""
356
        tree = self.make_branch_and_tree('source')
357
        self.build_tree(['source/foo'])
358
        tree.add('foo')
359
        tree.commit('revision 1')
360
361
        try:
362
            repo = self.make_repository('repo', shared=True)
363
        except errors.IncompatibleFormat:
2991.1.4 by Daniel Watkins
Modified tests as per comments on-list.
364
            raise TestNotApplicable('must support shared repositories')
2991.1.1 by Daniel Watkins
Added (failing) test to ensure that bzrdir.clone won't create a working tree in a no-trees repository.
365
        if repo.make_working_trees():
366
            repo.set_make_working_trees(False)
367
            self.assertFalse(repo.make_working_trees())
368
369
        dir = tree.bzrdir
370
        a_dir = dir.clone(self.get_url('repo/a'))
371
        a_dir.open_branch()
2991.1.4 by Daniel Watkins
Modified tests as per comments on-list.
372
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
2991.1.1 by Daniel Watkins
Added (failing) test to ensure that bzrdir.clone won't create a working tree in a no-trees repository.
373
3650.5.3 by Aaron Bentley
Add failing test of BzrDir.clone
374
    def test_clone_respects_stacked(self):
375
        branch = self.make_branch('parent')
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
376
        child_transport = self.get_transport('child')
3650.5.3 by Aaron Bentley
Add failing test of BzrDir.clone
377
        child = branch.bzrdir.clone_on_transport(child_transport,
378
                                                 stacked_on=branch.base)
379
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
380
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
381
    def test_get_branch_reference_on_reference(self):
382
        """get_branch_reference should return the right url."""
383
        referenced_branch = self.make_branch('referenced')
384
        dir = self.make_bzrdir('source')
385
        try:
386
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
387
                target_branch=referenced_branch)
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
388
        except errors.IncompatibleFormat:
389
            # this is ok too, not all formats have to support references.
390
            return
391
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
392
            dir.get_branch_reference())
393
394
    def test_get_branch_reference_on_non_reference(self):
395
        """get_branch_reference should return None for non-reference branches."""
396
        branch = self.make_branch('referenced')
397
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
398
399
    def test_get_branch_reference_no_branch(self):
400
        """get_branch_reference should not mask NotBranchErrors."""
401
        dir = self.make_bzrdir('source')
402
        if dir.has_branch():
403
            # this format does not support branchless bzrdirs.
404
            return
405
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
406
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
407
    def test_sprout_bzrdir_empty(self):
408
        dir = self.make_bzrdir('source')
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
409
        target = dir.sprout(self.get_url('target'))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
410
        self.assertNotEqual(dir.transport.base, target.transport.base)
411
        # creates a new repository branch and tree
412
        target.open_repository()
413
        target.open_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
414
        self.openWorkingTreeIfLocal(target)
1534.6.9 by Robert Collins
sprouting into shared repositories
415
416
    def test_sprout_bzrdir_empty_under_shared_repo(self):
417
        # sprouting an empty dir into a repo uses the repo
418
        dir = self.make_bzrdir('source')
419
        try:
420
            self.make_repository('target', shared=True)
421
        except errors.IncompatibleFormat:
422
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
423
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
424
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
425
        target.open_branch()
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
426
        try:
427
            target.open_workingtree()
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
428
        except errors.NoWorkingTree:
5393.4.1 by Jelmer Vernooij
Add ControlDirFormat.supports_workingtrees.
429
            # Some bzrdirs can never have working trees.
430
            self.assertFalse(target._format.supports_workingtrees)
1534.6.9 by Robert Collins
sprouting into shared repositories
431
1910.4.10 by Andrew Bennetts
Skip various test_sprout* tests when sprouting to non-local bzrdirs that can't have working trees; plus fix a test method naming clash and the bug it revealed in bzrdir.sprout.
432
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
433
        # the force_new_repo parameter should force use of a new repo in an empty
434
        # bzrdir's sprout logic
435
        dir = self.make_bzrdir('source')
436
        try:
437
            self.make_repository('target', shared=True)
438
        except errors.IncompatibleFormat:
439
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
440
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
441
        target.open_repository()
442
        target.open_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
443
        self.openWorkingTreeIfLocal(target)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
444
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
445
    def test_sprout_bzrdir_with_repository_to_shared(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
446
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
447
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
448
        tree.add('foo')
449
        tree.commit('revision 1', rev_id='1')
450
        tree.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
451
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
452
        tree.commit('revision 2', rev_id='2')
453
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
454
        tree.branch.repository.copy_content_into(source)
1534.6.9 by Robert Collins
sprouting into shared repositories
455
        dir = source.bzrdir
456
        try:
457
            shared_repo = self.make_repository('target', shared=True)
458
        except errors.IncompatibleFormat:
459
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
460
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
461
        self.assertNotEqual(dir.transport.base, target.transport.base)
462
        self.assertTrue(shared_repo.has_revision('1'))
463
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
464
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
465
        try:
466
            shared_repo = self.make_repository('shared', shared=True)
467
        except errors.IncompatibleFormat:
468
            return
469
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
470
        self.build_tree(['commit_tree/foo'])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
471
        tree.add('foo')
472
        tree.commit('revision 1', rev_id='1')
473
        tree.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
474
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
475
        tree.commit('revision 2', rev_id='2')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
476
        tree.branch.repository.copy_content_into(shared_repo)
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
477
        dir = self.make_bzrdir('shared/source')
478
        dir.create_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
479
        target = dir.sprout(self.get_url('shared/target'))
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
480
        self.assertNotEqual(dir.transport.base, target.transport.base)
481
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
482
        self.assertTrue(shared_repo.has_revision('1'))
483
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
484
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
485
        try:
486
            shared_repo = self.make_repository('shared', shared=True)
487
        except errors.IncompatibleFormat:
488
            return
489
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
490
        self.build_tree(['commit_tree/foo'])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
491
        tree.add('foo')
492
        tree.commit('revision 1', rev_id='1')
493
        tree.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
494
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
495
        tree.commit('revision 2', rev_id='2')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
496
        tree.branch.repository.copy_content_into(shared_repo)
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
497
        if shared_repo.make_working_trees():
498
            shared_repo.set_make_working_trees(False)
499
            self.assertFalse(shared_repo.make_working_trees())
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
500
        self.assertTrue(shared_repo.has_revision('1'))
501
        dir = self.make_bzrdir('shared/source')
502
        dir.create_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
503
        target = dir.sprout(self.get_url('target'))
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
504
        self.assertNotEqual(dir.transport.base, target.transport.base)
505
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
506
        branch = target.open_branch()
5535.4.17 by Andrew Bennetts
Adjust failing assertion for new, more sensible behaviour.
507
        # The sprouted bzrdir has a branch, so only revisions referenced by
508
        # that branch are copied, rather than the whole repository.  It's an
509
        # empty branch, so none are copied.
510
        self.assertEqual([], branch.repository.all_revision_ids())
5393.4.1 by Jelmer Vernooij
Add ControlDirFormat.supports_workingtrees.
511
        if branch.bzrdir._format.supports_workingtrees:
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
512
            self.assertTrue(branch.repository.make_working_trees())
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
513
        self.assertFalse(branch.repository.is_shared())
514
1534.6.9 by Robert Collins
sprouting into shared repositories
515
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
516
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
517
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
518
        tree.add('foo')
519
        tree.commit('revision 1', rev_id='1')
520
        tree.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
521
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
522
        tree.commit('revision 2', rev_id='2')
523
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
524
        tree.branch.repository.copy_content_into(source)
1534.6.9 by Robert Collins
sprouting into shared repositories
525
        dir = source.bzrdir
526
        try:
527
            shared_repo = self.make_repository('target', shared=True)
528
        except errors.IncompatibleFormat:
529
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
530
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
531
        self.assertNotEqual(dir.transport.base, target.transport.base)
532
        self.assertFalse(shared_repo.has_revision('1'))
533
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
534
    def test_sprout_bzrdir_repository_revision(self):
535
        # test for revision limiting, [smoke test, not corner case checks].
536
        # make a repository with some revisions,
537
        # and sprout it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
538
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
539
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
540
        self.build_tree(['commit_tree/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
541
        tree.add('foo')
542
        tree.commit('revision 1', rev_id='1')
543
        tree.bzrdir.open_branch().set_revision_history([])
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
544
        tree.set_parent_trees([])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
545
        tree.commit('revision 2', rev_id='2')
546
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
547
        tree.branch.repository.copy_content_into(source)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
548
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
549
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='2')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
550
        raise TestSkipped('revision limiting not strict yet')
551
1534.6.9 by Robert Collins
sprouting into shared repositories
552
    def test_sprout_bzrdir_branch_and_repo_shared(self):
553
        # sprouting a branch with a repo into a shared repo uses the shared
554
        # repo
555
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
556
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
557
        tree.add('foo')
558
        tree.commit('revision 1', rev_id='1')
559
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
560
        tree.branch.repository.copy_content_into(source.repository)
1534.6.9 by Robert Collins
sprouting into shared repositories
561
        tree.bzrdir.open_branch().copy_content_into(source)
562
        dir = source.bzrdir
563
        try:
564
            shared_repo = self.make_repository('target', shared=True)
565
        except errors.IncompatibleFormat:
566
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
567
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
568
        self.assertTrue(shared_repo.has_revision('1'))
569
570
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
571
        # sprouting a branch with a repo into a shared repo uses the shared
572
        # repo
573
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
574
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
575
        tree.add('foo')
576
        tree.commit('revision 1', rev_id='1')
577
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
578
        tree.branch.repository.copy_content_into(source.repository)
1534.6.9 by Robert Collins
sprouting into shared repositories
579
        tree.bzrdir.open_branch().copy_content_into(source)
580
        dir = source.bzrdir
581
        try:
582
            shared_repo = self.make_repository('target', shared=True)
583
        except errors.IncompatibleFormat:
584
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
585
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
586
        self.assertNotEqual(dir.transport.base, target.transport.base)
587
        self.assertFalse(shared_repo.has_revision('1'))
588
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
589
    def test_sprout_bzrdir_branch_reference(self):
590
        # sprouting should create a repository if needed and a sprouted branch.
4070.7.3 by Andrew Bennetts
Make the sprout_bzrdir_branch_reference tests pass by returning an error from the cloning_metadir RPC which triggers a VFS fallback on the client.
591
        referenced_branch = self.make_branch('referenced')
592
        dir = self.make_bzrdir('source')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
593
        try:
1508.1.25 by Robert Collins
Update per review comments.
594
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
595
                target_branch=referenced_branch)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
596
        except errors.IncompatibleFormat:
597
            # this is ok too, not all formats have to support references.
598
            return
599
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
600
        target = dir.sprout(self.get_url('target'))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
601
        self.assertNotEqual(dir.transport.base, target.transport.base)
602
        # we want target to have a branch that is in-place.
603
        self.assertEqual(target, target.open_branch().bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
604
        # and as we dont support repositories being detached yet, a repo in
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
605
        # place
606
        target.open_repository()
607
1534.6.9 by Robert Collins
sprouting into shared repositories
608
    def test_sprout_bzrdir_branch_reference_shared(self):
609
        # sprouting should create a repository if needed and a sprouted branch.
610
        referenced_tree = self.make_branch_and_tree('referenced')
611
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
4070.7.3 by Andrew Bennetts
Make the sprout_bzrdir_branch_reference tests pass by returning an error from the cloning_metadir RPC which triggers a VFS fallback on the client.
612
        dir = self.make_bzrdir('source')
1534.6.9 by Robert Collins
sprouting into shared repositories
613
        try:
614
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
615
                target_branch=referenced_tree.branch)
1534.6.9 by Robert Collins
sprouting into shared repositories
616
        except errors.IncompatibleFormat:
617
            # this is ok too, not all formats have to support references.
618
            return
619
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
620
        try:
621
            shared_repo = self.make_repository('target', shared=True)
622
        except errors.IncompatibleFormat:
623
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
624
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
625
        self.assertNotEqual(dir.transport.base, target.transport.base)
626
        # we want target to have a branch that is in-place.
627
        self.assertEqual(target, target.open_branch().bzrdir)
628
        # and we want no repository as the target is shared
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
629
        self.assertRaises(errors.NoRepositoryPresent,
1534.6.9 by Robert Collins
sprouting into shared repositories
630
                          target.open_repository)
631
        # and we want revision '1' in the shared repo
632
        self.assertTrue(shared_repo.has_revision('1'))
633
634
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
635
        # sprouting should create a repository if needed and a sprouted branch.
636
        referenced_tree = self.make_branch_and_tree('referenced')
637
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
4070.7.3 by Andrew Bennetts
Make the sprout_bzrdir_branch_reference tests pass by returning an error from the cloning_metadir RPC which triggers a VFS fallback on the client.
638
        dir = self.make_bzrdir('source')
1534.6.9 by Robert Collins
sprouting into shared repositories
639
        try:
640
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
641
                target_branch=referenced_tree.branch)
1534.6.9 by Robert Collins
sprouting into shared repositories
642
        except errors.IncompatibleFormat:
643
            # this is ok too, not all formats have to support references.
644
            return
645
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
646
        try:
647
            shared_repo = self.make_repository('target', shared=True)
648
        except errors.IncompatibleFormat:
649
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
650
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
651
        self.assertNotEqual(dir.transport.base, target.transport.base)
652
        # we want target to have a branch that is in-place.
653
        self.assertEqual(target, target.open_branch().bzrdir)
654
        # and we want revision '1' in the new repo
655
        self.assertTrue(target.open_repository().has_revision('1'))
656
        # but not the shared one
657
        self.assertFalse(shared_repo.has_revision('1'))
658
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
659
    def test_sprout_bzrdir_branch_revision(self):
660
        # test for revision limiting, [smoke test, not corner case checks].
661
        # make a repository with some revisions,
662
        # and sprout it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
663
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
664
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
665
        self.build_tree(['commit_tree/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
666
        tree.add('foo')
667
        tree.commit('revision 1', rev_id='1')
668
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
669
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
670
        tree.branch.repository.copy_content_into(source.repository)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
671
        tree.bzrdir.open_branch().copy_content_into(source)
672
        dir = source.bzrdir
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
673
        target = dir.sprout(self.get_url('target'), revision_id='1')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
674
        self.assertEqual('1', target.open_branch().last_revision())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
675
5535.3.26 by Andrew Bennetts
Add per_controldir test for sprout copying all tags.
676
    def test_sprout_bzrdir_branch_with_tags(self):
677
        # when sprouting a branch all revisions named in the tags are copied
678
        # too.
679
        builder = self.make_branch_builder('source')
5651.5.3 by Andrew Bennetts
Use new fixture in more tests.
680
        source = fixtures.build_branch_with_non_ancestral_rev(builder)
5535.3.26 by Andrew Bennetts
Add per_controldir test for sprout copying all tags.
681
        try:
682
            source.tags.set_tag('tag-a', 'rev-2')
683
        except errors.TagsNotSupported:
684
            raise TestNotApplicable('Branch format does not support tags.')
685
        # Now source has a tag not in its ancestry.  Sprout its controldir.
686
        dir = source.bzrdir
687
        target = dir.sprout(self.get_url('target'))
688
        # The tag is present, and so is its revision.
689
        new_branch = target.open_branch()
690
        self.assertEqual('rev-2', new_branch.tags.lookup_tag('tag-a'))
691
        new_branch.repository.get_revision('rev-2')
692
5535.4.1 by Andrew Bennetts
Add another test.
693
    def test_sprout_bzrdir_branch_with_absent_tag(self):
694
        # tags referencing absent revisions are copied (and those absent
695
        # revisions do not prevent the sprout.)
696
        builder = self.make_branch_builder('source')
697
        builder.build_commit(message="Rev 1", rev_id='rev-1')
698
        source = builder.get_branch()
699
        try:
700
            source.tags.set_tag('tag-a', 'missing-rev')
701
        except errors.TagsNotSupported:
702
            raise TestNotApplicable('Branch format does not support tags.')
703
        # Now source has a tag pointing to an absent revision.  Sprout its
704
        # controldir.
705
        dir = source.bzrdir
706
        target = dir.sprout(self.get_url('target'))
707
        # The tag is present in the target
708
        new_branch = target.open_branch()
709
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
710
5535.3.38 by Andrew Bennetts
Remove XXX, add some test coverage to prove it works.
711
    def test_sprout_bzrdir_passing_source_branch_with_absent_tag(self):
712
        # tags referencing absent revisions are copied (and those absent
713
        # revisions do not prevent the sprout.)
714
        builder = self.make_branch_builder('source')
715
        builder.build_commit(message="Rev 1", rev_id='rev-1')
716
        source = builder.get_branch()
717
        try:
718
            source.tags.set_tag('tag-a', 'missing-rev')
719
        except errors.TagsNotSupported:
720
            raise TestNotApplicable('Branch format does not support tags.')
721
        # Now source has a tag pointing to an absent revision.  Sprout its
722
        # controldir.
723
        dir = source.bzrdir
724
        target = dir.sprout(self.get_url('target'), source_branch=source)
725
        # The tag is present in the target
726
        new_branch = target.open_branch()
727
        self.assertEqual('missing-rev', new_branch.tags.lookup_tag('tag-a'))
728
5535.4.10 by Andrew Bennetts
Add a test, fix a bug and XXX it covers.
729
    def test_sprout_bzrdir_passing_rev_not_source_branch_copies_tags(self):
5535.4.12 by Andrew Bennetts
Adjust test and code to behave more intuitively -- make bzrdir.sprout(..., revision_id=R) stop fetching the branch history at R, as that will be the new branch's tip.
730
        # dir.sprout(..., revision_id='rev1') copies rev1, and all the tags of
731
        # the branch at that bzrdir, the ancestry of all of those, but no other
732
        # revs (not even the tip of the source branch).
5535.4.10 by Andrew Bennetts
Add a test, fix a bug and XXX it covers.
733
        builder = self.make_branch_builder('source')
734
        builder.build_commit(message="Base", rev_id='base-rev')
735
        # Make three parallel lines of ancestry off this base.
736
        source = builder.get_branch()
737
        builder.build_commit(message="Rev A1", rev_id='rev-a1')
738
        builder.build_commit(message="Rev A2", rev_id='rev-a2')
739
        builder.build_commit(message="Rev A3", rev_id='rev-a3')
740
        source.set_last_revision_info(1, 'base-rev')
741
        builder.build_commit(message="Rev B1", rev_id='rev-b1')
742
        builder.build_commit(message="Rev B2", rev_id='rev-b2')
743
        builder.build_commit(message="Rev B3", rev_id='rev-b3')
744
        source.set_last_revision_info(1, 'base-rev')
745
        builder.build_commit(message="Rev C1", rev_id='rev-c1')
746
        builder.build_commit(message="Rev C2", rev_id='rev-c2')
747
        builder.build_commit(message="Rev C3", rev_id='rev-c3')
748
        # Set the branch tip to A2
749
        source.set_last_revision_info(3, 'rev-a2')
750
        try:
751
            # Create a tag for B2, and for an absent rev
752
            source.tags.set_tag('tag-non-ancestry', 'rev-b2')
753
            source.tags.set_tag('tag-absent', 'absent-rev')
754
        except errors.TagsNotSupported:
755
            raise TestNotApplicable('Branch format does not support tags.')
756
        # And ask sprout for C2
757
        dir = source.bzrdir
758
        target = dir.sprout(self.get_url('target'), revision_id='rev-c2')
759
        # The tags are present
760
        new_branch = target.open_branch()
761
        self.assertEqual(
762
            {'tag-absent': 'absent-rev', 'tag-non-ancestry': 'rev-b2'},
763
            new_branch.tags.get_tag_dict())
764
        # And the revs for A2, B2 and C2's ancestries are present, but no
765
        # others.
766
        self.assertEqual(
5535.4.12 by Andrew Bennetts
Adjust test and code to behave more intuitively -- make bzrdir.sprout(..., revision_id=R) stop fetching the branch history at R, as that will be the new branch's tip.
767
            ['base-rev', 'rev-b1', 'rev-b2', 'rev-c1', 'rev-c2'],
768
            sorted(new_branch.repository.all_revision_ids()))
5535.4.10 by Andrew Bennetts
Add a test, fix a bug and XXX it covers.
769
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
770
    def test_sprout_bzrdir_tree_branch_reference(self):
771
        # sprouting should create a repository if needed and a sprouted branch.
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
772
        # the tree state should not be copied.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
773
        referenced_branch = self.make_branch('referencced')
774
        dir = self.make_bzrdir('source')
775
        try:
1508.1.25 by Robert Collins
Update per review comments.
776
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
777
                target_branch=referenced_branch)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
778
        except errors.IncompatibleFormat:
779
            # this is ok too, not all formats have to support references.
780
            return
781
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
782
        tree = self.createWorkingTreeOrSkip(dir)
2381.1.3 by Robert Collins
Review feedback.
783
        self.build_tree(['source/subdir/'])
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
784
        tree.add('subdir')
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
785
        target = dir.sprout(self.get_url('target'))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
786
        self.assertNotEqual(dir.transport.base, target.transport.base)
787
        # we want target to have a branch that is in-place.
788
        self.assertEqual(target, target.open_branch().bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
789
        # and as we dont support repositories being detached yet, a repo in
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
790
        # place
791
        target.open_repository()
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
792
        result_tree = target.open_workingtree()
793
        self.assertFalse(result_tree.has_filename('subdir'))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
794
795
    def test_sprout_bzrdir_tree_branch_reference_revision(self):
796
        # sprouting should create a repository if needed and a sprouted branch.
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
797
        # the tree state should not be copied but the revision changed,
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
798
        # and the likewise the new branch should be truncated too
799
        referenced_branch = self.make_branch('referencced')
800
        dir = self.make_bzrdir('source')
801
        try:
1508.1.25 by Robert Collins
Update per review comments.
802
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
803
                target_branch=referenced_branch)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
804
        except errors.IncompatibleFormat:
805
            # this is ok too, not all formats have to support references.
806
            return
807
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
808
        tree = self.createWorkingTreeOrSkip(dir)
2381.1.3 by Robert Collins
Review feedback.
809
        self.build_tree(['source/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
810
        tree.add('foo')
811
        tree.commit('revision 1', rev_id='1')
812
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
813
        target = dir.sprout(self.get_url('target'), revision_id='1')
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
814
        self.skipIfNoWorkingTree(target)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
815
        self.assertNotEqual(dir.transport.base, target.transport.base)
816
        # we want target to have a branch that is in-place.
817
        self.assertEqual(target, target.open_branch().bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
818
        # and as we dont support repositories being detached yet, a repo in
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
819
        # place
820
        target.open_repository()
821
        # we trust that the working tree sprouting works via the other tests.
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
822
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
823
        self.assertEqual('1', target.open_branch().last_revision())
824
825
    def test_sprout_bzrdir_tree_revision(self):
826
        # test for revision limiting, [smoke test, not corner case checks].
827
        # make a tree with a revision with a last-revision
828
        # and sprout it with a revision limit.
829
        # This smoke test just checks the revision-id is right. Tree specific
830
        # tests will check corner cases.
831
        tree = self.make_branch_and_tree('source')
2381.1.3 by Robert Collins
Review feedback.
832
        self.build_tree(['source/foo'])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
833
        tree.add('foo')
834
        tree.commit('revision 1', rev_id='1')
835
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
836
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
837
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
838
        self.assertEqual(['1'], target.open_workingtree().get_parent_ids())
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
839
3123.5.8 by Aaron Bentley
Work around double-opening lock issue
840
    def test_sprout_takes_accelerator(self):
841
        tree = self.make_branch_and_tree('source')
842
        self.build_tree(['source/foo'])
843
        tree.add('foo')
844
        tree.commit('revision 1', rev_id='1')
845
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
846
        dir = tree.bzrdir
847
        target = self.sproutOrSkip(dir, self.get_url('target'),
848
                                   accelerator_tree=tree)
849
        self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
850
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
851
    def test_sprout_branch_no_tree(self):
852
        tree = self.make_branch_and_tree('source')
853
        self.build_tree(['source/foo'])
854
        tree.add('foo')
855
        tree.commit('revision 1', rev_id='1')
856
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
857
        dir = tree.bzrdir
5582.9.6 by Jelmer Vernooij
More cleanups, remove more dependencies on specific formats.
858
        try:
859
            target = dir.sprout(self.get_url('target'),
860
                create_tree_if_local=False)
861
        except errors.MustHaveWorkingTree:
862
            raise TestNotApplicable("control dir format requires working tree")
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
863
        self.failIfExists('target/foo')
3983.1.9 by Daniel Watkins
Wrapped long line.
864
        self.assertEqual(tree.branch.last_revision(),
865
                         target.open_branch().last_revision())
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
866
5316.1.1 by Andrew Bennetts
Fix BzrDir.sprout to respect default stacking policy.
867
    def test_sprout_with_revision_id_uses_default_stack_on(self):
868
        # Make a branch with three commits to stack on.
869
        builder = self.make_branch_builder('stack-on')
870
        builder.start_series()
871
        builder.build_commit(message='Rev 1.', rev_id='rev-1')
872
        builder.build_commit(message='Rev 2.', rev_id='rev-2')
873
        builder.build_commit(message='Rev 3.', rev_id='rev-3')
874
        builder.finish_series()
875
        stack_on = builder.get_branch()
876
        # Make a bzrdir with a default stacking policy to stack on that branch.
877
        config = self.make_bzrdir('policy-dir').get_config()
878
        try:
879
            config.set_default_stack_on(self.get_url('stack-on'))
880
        except errors.BzrError:
881
            raise TestNotApplicable('Only relevant for stackable formats.')
882
        # Sprout the stacked-on branch into the bzrdir.
883
        sprouted = stack_on.bzrdir.sprout(
884
            self.get_url('policy-dir/sprouted'), revision_id='rev-3')
885
        # Not all revisions are copied into the sprouted repository.
886
        repo = sprouted.open_repository()
887
        self.addCleanup(repo.lock_read().unlock)
888
        self.assertEqual(None, repo.get_parent_map(['rev-1']).get('rev-1'))
889
1534.4.39 by Robert Collins
Basic BzrDir support.
890
    def test_format_initialize_find_open(self):
891
        # loopback test to check the current format initializes to itself.
892
        if not self.bzrdir_format.is_supported():
893
            # unsupported formats are not loopback testable
894
            # because the default open will not open them and
895
            # they may not be initializable.
896
            return
4934.4.2 by Martin Pool
Check RemoteBzrDirFormat._network_name is none before running tests that rely on this (for bug 504102)
897
        # for remote formats, there must be no prior assumption about the
898
        # network name to use - it's possible that this may somehow have got
899
        # in through an unisolated test though - see
5243.1.2 by Martin
Point launchpad links in comments at production server rather than edge
900
        # <https://bugs.launchpad.net/bzr/+bug/504102>
4934.4.2 by Martin Pool
Check RemoteBzrDirFormat._network_name is none before running tests that rely on this (for bug 504102)
901
        self.assertEquals(getattr(self.bzrdir_format,
902
            '_network_name', None),
903
            None)
1534.4.39 by Robert Collins
Basic BzrDir support.
904
        # supported formats must be able to init and open
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
905
        t = self.get_transport()
906
        readonly_t = self.get_readonly_transport()
1534.4.39 by Robert Collins
Basic BzrDir support.
907
        made_control = self.bzrdir_format.initialize(t.base)
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
908
        self.failUnless(isinstance(made_control, controldir.ControlDir))
1534.4.39 by Robert Collins
Basic BzrDir support.
909
        self.assertEqual(self.bzrdir_format,
5363.2.3 by Jelmer Vernooij
Add ControlDirFormat.
910
                         controldir.ControlDirFormat.find_format(readonly_t))
1534.4.39 by Robert Collins
Basic BzrDir support.
911
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
912
        opened_dir = bzrdir.BzrDir.open(t.base)
913
        self.assertEqual(made_control._format,
914
                         opened_dir._format)
915
        self.assertEqual(direct_opened_dir._format,
916
                         opened_dir._format)
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
917
        self.failUnless(isinstance(opened_dir, controldir.ControlDir))
1534.4.39 by Robert Collins
Basic BzrDir support.
918
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
919
    def test_format_initialize_on_transport_ex(self):
920
        t = self.get_transport('dir')
921
        self.assertInitializeEx(t)
922
923
    def test_format_initialize_on_transport_ex_use_existing_dir_True(self):
924
        t = self.get_transport('dir')
925
        t.ensure_base()
926
        self.assertInitializeEx(t, use_existing_dir=True)
927
928
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
929
        if not self.bzrdir_format.is_supported():
930
            # Not initializable - not a failure either.
931
            return
932
        t = self.get_transport('dir')
933
        t.ensure_base()
4294.2.10 by Robert Collins
Review feedback.
934
        self.assertRaises(errors.FileExists,
935
            self.bzrdir_format.initialize_on_transport_ex, t,
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
936
            use_existing_dir=False)
937
938
    def test_format_initialize_on_transport_ex_create_prefix_True(self):
939
        t = self.get_transport('missing/dir')
940
        self.assertInitializeEx(t, create_prefix=True)
941
942
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
943
        if not self.bzrdir_format.is_supported():
944
            # Not initializable - not a failure either.
945
            return
946
        t = self.get_transport('missing/dir')
947
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
948
            create_prefix=False)
949
950
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
951
        t = self.get_transport('repo')
952
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
953
        repo_name = repo_fmt.repository_format.network_name()
954
        repo = repo_fmt.initialize_on_transport_ex(t,
955
            repo_format_name=repo_name, shared_repo=True)[0]
956
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
957
            force_new_repo=True, repo_format_name=repo_name)
958
        if control is None:
959
            # uninitialisable format
960
            return
961
        self.assertNotEqual(repo.bzrdir.root_transport.base,
962
            made_repo.bzrdir.root_transport.base)
963
964
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
965
        t = self.get_transport('repo')
966
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
967
        repo_name = repo_fmt.repository_format.network_name()
968
        repo = repo_fmt.initialize_on_transport_ex(t,
969
            repo_format_name=repo_name, shared_repo=True)[0]
970
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
971
            force_new_repo=False, repo_format_name=repo_name)
972
        if control is None:
973
            # uninitialisable format
974
            return
5673.1.3 by Jelmer Vernooij
Change flexible_components to fixed_components.
975
        if not control._format.fixed_components:
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
976
            self.assertEqual(repo.bzrdir.root_transport.base,
977
                made_repo.bzrdir.root_transport.base)
978
979
    def test_format_initialize_on_transport_ex_stacked_on(self):
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
980
        # trunk is a stackable format.  Note that its in the same server area
981
        # which is what launchpad does, but not sufficient to exercise the
982
        # general case.
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
983
        trunk = self.make_branch('trunk', format='1.9')
984
        t = self.get_transport('stacked')
985
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
986
        repo_name = old_fmt.repository_format.network_name()
987
        # Should end up with a 1.9 format (stackable)
988
        repo, control = self.assertInitializeEx(t, need_meta=True,
989
            repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
990
        if control is None:
991
            # uninitialisable format
992
            return
993
        self.assertLength(1, repo._fallback_repositories)
994
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
995
    def test_format_initialize_on_transport_ex_default_stack_on(self):
996
        # When initialize_on_transport_ex uses a stacked-on branch because of
997
        # a stacking policy on the target, the location of the fallback
998
        # repository is the same as the external location of the stacked-on
999
        # branch.
1000
        balloon = self.make_bzrdir('balloon')
4617.6.1 by Robert Collins
Fix a broken check in per_bzr tests that causes failures when the default format is rich roots.
1001
        if isinstance(balloon._format, bzrdir.BzrDirMetaFormat1):
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1002
            stack_on = self.make_branch('stack-on', format='1.9')
1003
        else:
1004
            stack_on = self.make_branch('stack-on')
1005
        config = self.make_bzrdir('.').get_config()
1006
        try:
1007
            config.set_default_stack_on('stack-on')
1008
        except errors.BzrError:
1009
            raise TestNotApplicable('Only relevant for stackable formats.')
1010
        # Initialize a bzrdir subject to the policy.
1011
        t = self.get_transport('stacked')
1012
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1013
        repo_name = repo_fmt.repository_format.network_name()
1014
        repo, control = self.assertInitializeEx(
1015
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
4807.3.2 by John Arbash Meinel
Some tests *did* know that the repo was write locked
1016
        # self.addCleanup(repo.unlock)
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1017
        if control is None:
1018
            # uninitialisable format
1019
            return
1020
        # There's one fallback repo, with a public location.
1021
        self.assertLength(1, repo._fallback_repositories)
1022
        fallback_repo = repo._fallback_repositories[0]
1023
        self.assertEqual(
1024
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
4456.2.1 by Andrew Bennetts
Fix automatic branch format upgrades triggered by a default stacking policy on a 1.16rc1 (or later) smart server.
1025
        # The bzrdir creates a branch in stacking-capable format.
1026
        new_branch = control.create_branch()
1027
        self.assertTrue(new_branch._format.supports_stacking())
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1028
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1029
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1030
        t = self.get_transport('dir')
1031
        repo, control = self.assertInitializeEx(t)
1032
        self.assertEqual(None, repo)
1033
1034
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1035
        t = self.get_transport('dir')
4294.2.10 by Robert Collins
Review feedback.
1036
        # 1.6 is likely to never be default
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1037
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
1038
        repo_name = fmt.repository_format.network_name()
1039
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1040
        if control is None:
1041
            # uninitialisable format
1042
            return
5673.1.3 by Jelmer Vernooij
Change flexible_components to fixed_components.
1043
        if self.bzrdir_format.fixed_components:
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1044
            # must stay with the all-in-one-format.
1045
            repo_name = self.bzrdir_format.network_name()
1046
        self.assertEqual(repo_name, repo._format.network_name())
1047
1048
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
1049
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1050
4294.2.10 by Robert Collins
Review feedback.
1051
        This involves checking that the disk objects were created, open with
1052
        the same format returned, and had the expected disk format.
1053
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1054
        :param t: The transport to initialize on.
1055
        :param **kwargs: Additional arguments to pass to
1056
            initialize_on_transport_ex.
1057
        :return: the resulting repo, control dir tuple.
1058
        """
1059
        if not self.bzrdir_format.is_supported():
1060
            # Not initializable - not a failure either.
1061
            return None, None
1062
        repo, control, require_stacking, repo_policy = \
1063
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
4807.3.2 by John Arbash Meinel
Some tests *did* know that the repo was write locked
1064
        if repo is not None:
1065
            # Repositories are open write-locked
1066
            self.assertTrue(repo.is_write_locked())
1067
            self.addCleanup(repo.unlock)
5699.1.1 by Jelmer Vernooij
Require ControlDirFormat.initialize_on_transport_ex to return a ControlDir instance, not a BzrDir instance.
1068
        self.assertIsInstance(control, controldir.ControlDir)
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1069
        opened = bzrdir.BzrDir.open(t.base)
1070
        expected_format = self.bzrdir_format
1071
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
4294.2.10 by Robert Collins
Review feedback.
1072
            # Current RemoteBzrDirFormat's do not reliably get network_name
1073
            # set, so we skip a number of tests for RemoteBzrDirFormat's.
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1074
            self.assertIsInstance(control, RemoteBzrDir)
1075
        else:
5673.1.3 by Jelmer Vernooij
Change flexible_components to fixed_components.
1076
            if need_meta and expected_format.fixed_components:
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1077
                # Pre-metadir formats change when we are making something that
1078
                # needs a metaformat, because clone is used for push.
1079
                expected_format = bzrdir.BzrDirMetaFormat1()
1080
            self.assertEqual(control._format.network_name(),
1081
                expected_format.network_name())
1082
            self.assertEqual(control._format.network_name(),
1083
                opened._format.network_name())
1084
        self.assertEqual(control.__class__, opened.__class__)
1085
        return repo, control
1086
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1087
    def test_format_network_name(self):
1088
        # All control formats must have a network name.
1089
        dir = self.make_bzrdir('.')
1090
        format = dir._format
1091
        # We want to test that the network_name matches the actual format on
1092
        # disk. For local control dirsthat means that using network_name as a
1093
        # key in the registry gives back the same format. For remote obects
1094
        # we check that the network_name of the RemoteBzrDirFormat we have
1095
        # locally matches the actual format present on disk.
1096
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
1097
            dir._ensure_real()
1098
            real_dir = dir._real_bzrdir
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1099
            network_name = format.network_name()
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1100
            self.assertEqual(real_dir._format.network_name(), network_name)
1101
        else:
5363.2.23 by Jelmer Vernooij
Move network_format_registry to bzrlib.controldir.
1102
            registry = controldir.network_format_registry
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1103
            network_name = format.network_name()
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1104
            looked_up_format = registry.get(network_name)
5418.3.1 by Jelmer Vernooij
Cope with control directories that are local but can't have working trees.
1105
            self.assertTrue(
1106
                issubclass(format.__class__, looked_up_format.__class__))
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1107
        # The network name must be a byte string.
1108
        self.assertIsInstance(network_name, str)
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1109
1534.4.39 by Robert Collins
Basic BzrDir support.
1110
    def test_open_not_bzrdir(self):
1111
        # test the formats specific behaviour for no-content or similar dirs.
5363.2.29 by Jelmer Vernooij
Move some bzrdir-specific tests to bzrlib.tests.per_bzrdir.
1112
        self.assertRaises(errors.NotBranchError,
1534.4.39 by Robert Collins
Basic BzrDir support.
1113
                          self.bzrdir_format.open,
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1114
                          transport.get_transport(self.get_readonly_url()))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1115
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1116
    def test_create_branch(self):
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
1117
        # a bzrdir can construct a branch and repository for itself.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1118
        if not self.bzrdir_format.is_supported():
1119
            # unsupported formats are not loopback testable
1120
            # because the default open will not open them and
1121
            # they may not be initializable.
1122
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1123
        t = self.get_transport()
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1124
        made_control = self.bzrdir_format.initialize(t.base)
1125
        made_repo = made_control.create_repository()
1126
        made_branch = made_control.create_branch()
1508.1.25 by Robert Collins
Update per review comments.
1127
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1128
        self.assertEqual(made_control, made_branch.bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1129
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1130
    def test_open_branch(self):
1131
        if not self.bzrdir_format.is_supported():
1132
            # unsupported formats are not loopback testable
1133
            # because the default open will not open them and
1134
            # they may not be initializable.
1135
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1136
        t = self.get_transport()
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1137
        made_control = self.bzrdir_format.initialize(t.base)
1138
        made_repo = made_control.create_repository()
1139
        made_branch = made_control.create_branch()
1140
        opened_branch = made_control.open_branch()
1141
        self.assertEqual(made_control, opened_branch.bzrdir)
1142
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1143
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1144
4997.1.1 by Jelmer Vernooij
Add BzrDir.list_branches().
1145
    def test_list_branches(self):
1146
        if not self.bzrdir_format.is_supported():
1147
            # unsupported formats are not loopback testable
1148
            # because the default open will not open them and
1149
            # they may not be initializable.
1150
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1151
        t = self.get_transport()
4997.1.1 by Jelmer Vernooij
Add BzrDir.list_branches().
1152
        made_control = self.bzrdir_format.initialize(t.base)
1153
        made_repo = made_control.create_repository()
1154
        made_branch = made_control.create_branch()
1155
        branches = made_control.list_branches()
1156
        self.assertEquals(1, len(branches))
1157
        self.assertEquals(made_branch.base, branches[0].base)
1158
        try:
1159
            made_control.destroy_branch()
1160
        except errors.UnsupportedOperation:
1161
            pass # Not all bzrdirs support destroying directories
1162
        else:
1163
            self.assertEquals([], made_control.list_branches())
1164
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1165
    def test_create_repository(self):
1166
        # a bzrdir can construct a repository for itself.
1167
        if not self.bzrdir_format.is_supported():
1168
            # unsupported formats are not loopback testable
1169
            # because the default open will not open them and
1170
            # they may not be initializable.
1171
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1172
        t = self.get_transport()
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1173
        made_control = self.bzrdir_format.initialize(t.base)
1174
        made_repo = made_control.create_repository()
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
1175
        # Check that we have a repository object.
1176
        made_repo.has_revision('foo')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1177
        self.assertEqual(made_control, made_repo.bzrdir)
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1178
1179
    def test_create_repository_shared(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1180
        # a bzrdir can create a shared repository or
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1181
        # fail appropriately
1182
        if not self.bzrdir_format.is_supported():
1183
            # unsupported formats are not loopback testable
1184
            # because the default open will not open them and
1185
            # they may not be initializable.
1186
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1187
        t = self.get_transport()
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1188
        made_control = self.bzrdir_format.initialize(t.base)
1189
        try:
1190
            made_repo = made_control.create_repository(shared=True)
1191
        except errors.IncompatibleFormat:
1192
            # Old bzrdir formats don't support shared repositories
1193
            # and should raise IncompatibleFormat
1194
            return
1195
        self.assertTrue(made_repo.is_shared())
1196
1197
    def test_create_repository_nonshared(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1198
        # a bzrdir can create a non-shared repository
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1199
        if not self.bzrdir_format.is_supported():
1200
            # unsupported formats are not loopback testable
1201
            # because the default open will not open them and
1202
            # they may not be initializable.
1203
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1204
        t = self.get_transport()
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1205
        made_control = self.bzrdir_format.initialize(t.base)
1206
        made_repo = made_control.create_repository(shared=False)
1207
        self.assertFalse(made_repo.is_shared())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1208
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1209
    def test_open_repository(self):
1210
        if not self.bzrdir_format.is_supported():
1211
            # unsupported formats are not loopback testable
1212
            # because the default open will not open them and
1213
            # they may not be initializable.
1214
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1215
        t = self.get_transport()
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1216
        made_control = self.bzrdir_format.initialize(t.base)
1217
        made_repo = made_control.create_repository()
1218
        opened_repo = made_control.open_repository()
1219
        self.assertEqual(made_control, opened_repo.bzrdir)
1220
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1221
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1222
1223
    def test_create_workingtree(self):
1224
        # a bzrdir can construct a working tree for itself.
1225
        if not self.bzrdir_format.is_supported():
1226
            # unsupported formats are not loopback testable
1227
            # because the default open will not open them and
1228
            # they may not be initializable.
1229
            return
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1230
        t = self.get_transport()
1910.5.9 by Andrew Bennetts
Move stuff out of a try block that doesn't need to be there.
1231
        made_control = self.bzrdir_format.initialize(t.base)
1232
        made_repo = made_control.create_repository()
1233
        made_branch = made_control.create_branch()
1910.5.11 by Andrew Bennetts
Use createWorkingTreeOrSkip helper in test_create_workingtree.
1234
        made_tree = self.createWorkingTreeOrSkip(made_control)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1235
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1236
        self.assertEqual(made_control, made_tree.bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1237
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1238
    def test_create_workingtree_revision(self):
1239
        # a bzrdir can construct a working tree for itself @ a specific revision.
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1240
        t = self.get_transport()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1241
        source = self.make_branch_and_tree('source')
1242
        source.commit('a', rev_id='a', allow_pointless=True)
1243
        source.commit('b', rev_id='b', allow_pointless=True)
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
1244
        t.mkdir('new')
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1245
        t_new = t.clone('new')
1246
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1247
        source.branch.repository.clone(made_control)
1248
        source.branch.clone(made_control)
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1249
        try:
1250
            made_tree = made_control.create_workingtree(revision_id='a')
5418.3.1 by Jelmer Vernooij
Cope with control directories that are local but can't have working trees.
1251
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1910.5.1 by Andrew Bennetts
Make some old formats create at least a stub working tree rather than incomplete bzrdirs, and change some tests to use the test suite transport rather than hard-coded to local-only.
1252
            raise TestSkipped("Can't make working tree on transport %r" % t)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1253
        self.assertEqual(['a'], made_tree.get_parent_ids())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1254
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1255
    def test_open_workingtree(self):
1256
        if not self.bzrdir_format.is_supported():
1257
            # unsupported formats are not loopback testable
1258
            # because the default open will not open them and
1259
            # they may not be initializable.
1260
            return
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1261
        # this has to be tested with local access as we still support creating
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1262
        # format 6 bzrdirs
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1263
        t = self.get_transport()
1264
        try:
1265
            made_control = self.bzrdir_format.initialize(t.base)
1266
            made_repo = made_control.create_repository()
1267
            made_branch = made_control.create_branch()
1268
            made_tree = made_control.create_workingtree()
5418.3.1 by Jelmer Vernooij
Cope with control directories that are local but can't have working trees.
1269
        except (errors.NotLocalUrl, errors.UnsupportedOperation):
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1270
            raise TestSkipped("Can't initialize %r on transport %r"
1271
                              % (self.bzrdir_format, t))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1272
        opened_tree = made_control.open_workingtree()
1273
        self.assertEqual(made_control, opened_tree.bzrdir)
1274
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1275
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1276
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1277
    def test_root_transport(self):
1278
        dir = self.make_bzrdir('.')
1279
        self.assertEqual(dir.root_transport.base,
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1280
                         self.get_transport().base)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1281
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.
1282
    def test_find_repository_no_repo_under_standalone_branch(self):
1283
        # finding a repo stops at standalone branches even if there is a
1284
        # higher repository available.
1285
        try:
1286
            repo = self.make_repository('.', shared=True)
1287
        except errors.IncompatibleFormat:
1288
            # need a shared repository to test this.
1289
            return
1290
        url = self.get_url('intermediate')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1291
        t = self.get_transport()
1292
        t.mkdir('intermediate')
1293
        t.mkdir('intermediate/child')
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.
1294
        made_control = self.bzrdir_format.initialize(url)
1295
        made_control.create_repository()
1296
        innermost_control = self.bzrdir_format.initialize(
1297
            self.get_url('intermediate/child'))
1298
        try:
1299
            child_repo = innermost_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1300
            # 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.
1301
            # code path.
1302
            return
1303
        except errors.NoRepositoryPresent:
1304
            pass
1305
        self.assertRaises(errors.NoRepositoryPresent,
1306
                          innermost_control.find_repository)
1307
1308
    def test_find_repository_containing_shared_repository(self):
1309
        # find repo inside a shared repo with an empty control dir
1310
        # returns the shared repo.
1311
        try:
1312
            repo = self.make_repository('.', shared=True)
1313
        except errors.IncompatibleFormat:
1314
            # need a shared repository to test this.
1315
            return
1316
        url = self.get_url('childbzrdir')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1317
        self.get_transport().mkdir('childbzrdir')
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.
1318
        made_control = self.bzrdir_format.initialize(url)
1319
        try:
1320
            child_repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1321
            # 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.
1322
            # code path.
1323
            return
1324
        except errors.NoRepositoryPresent:
1325
            pass
1326
        found_repo = made_control.find_repository()
1327
        self.assertEqual(repo.bzrdir.root_transport.base,
1328
                         found_repo.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1329
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.
1330
    def test_find_repository_standalone_with_containing_shared_repository(self):
1331
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1332
        try:
1333
            containing_repo = self.make_repository('.', shared=True)
1334
        except errors.IncompatibleFormat:
1335
            # need a shared repository to test this.
1336
            return
1337
        child_repo = self.make_repository('childrepo')
1338
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1339
        found_repo = opened_control.find_repository()
1340
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1341
                         found_repo.bzrdir.root_transport.base)
1342
1343
    def test_find_repository_shared_within_shared_repository(self):
1344
        # find repo at a shared repo inside a shared repo finds the inner repo
1345
        try:
1346
            containing_repo = self.make_repository('.', shared=True)
1347
        except errors.IncompatibleFormat:
1348
            # need a shared repository to test this.
1349
            return
1350
        url = self.get_url('childrepo')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1351
        self.get_transport().mkdir('childrepo')
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.
1352
        child_control = self.bzrdir_format.initialize(url)
1353
        child_repo = child_control.create_repository(shared=True)
1354
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1355
        found_repo = opened_control.find_repository()
1356
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1357
                         found_repo.bzrdir.root_transport.base)
1358
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1359
                            containing_repo.bzrdir.root_transport.base)
1360
1361
    def test_find_repository_with_nested_dirs_works(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1362
        # find repo inside a bzrdir inside a bzrdir inside a shared repo
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.
1363
        # finds the outer shared repo.
1364
        try:
1365
            repo = self.make_repository('.', shared=True)
1366
        except errors.IncompatibleFormat:
1367
            # need a shared repository to test this.
1368
            return
1369
        url = self.get_url('intermediate')
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
1370
        t = self.get_transport()
1371
        t.mkdir('intermediate')
1372
        t.mkdir('intermediate/child')
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.
1373
        made_control = self.bzrdir_format.initialize(url)
1374
        try:
1375
            child_repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1376
            # 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.
1377
            # code path.
1378
            return
1379
        except errors.NoRepositoryPresent:
1380
            pass
1381
        innermost_control = self.bzrdir_format.initialize(
1382
            self.get_url('intermediate/child'))
1383
        try:
1384
            child_repo = innermost_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1385
            # 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.
1386
            # code path.
1387
            return
1388
        except errors.NoRepositoryPresent:
1389
            pass
1390
        found_repo = innermost_control.find_repository()
1391
        self.assertEqual(repo.bzrdir.root_transport.base,
1392
                         found_repo.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1393
1534.5.16 by Robert Collins
Review feedback.
1394
    def test_can_and_needs_format_conversion(self):
1534.5.8 by Robert Collins
Ensure that bzrdir implementations offer the can_update_format and needs_format_update api.
1395
        # check that we can ask an instance if its upgradable
1396
        dir = self.make_bzrdir('.')
1534.5.16 by Robert Collins
Review feedback.
1397
        if dir.can_convert_format():
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1398
            # if its default updatable there must be an updater
2204.4.14 by Aaron Bentley
lastest -> latest
1399
            # (we force the latest known format as downgrades may not be
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1400
            # available
1401
            self.assertTrue(isinstance(dir._format.get_converter(
5692.1.1 by Jelmer Vernooij
Move Converter (which is generic) from bzrlib.bzrdir to bzrlib.controldir.
1402
                format=dir._format), controldir.Converter))
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1403
        dir.needs_format_conversion(
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
1404
            controldir.ControlDirFormat.get_default_format())
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.
1405
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1406
    def test_backup_copies_existing(self):
1407
        tree = self.make_branch_and_tree('test')
1408
        self.build_tree(['test/a'])
1409
        tree.add(['a'], ['a-id'])
1410
        tree.commit('some data to be copied.')
1411
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1412
        old_path = urlutils.local_path_from_url(old_url)
1413
        new_path = urlutils.local_path_from_url(new_url)
1414
        self.failUnlessExists(old_path)
1415
        self.failUnlessExists(new_path)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1416
        for (((dir_relpath1, _), entries1),
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1417
             ((dir_relpath2, _), entries2)) in izip(
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1418
                osutils.walkdirs(old_path),
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1419
                osutils.walkdirs(new_path)):
1420
            self.assertEquals(dir_relpath1, dir_relpath2)
1421
            for f1, f2 in zip(entries1, entries2):
1422
                self.assertEquals(f1[0], f2[0])
1423
                self.assertEquals(f1[2], f2[2])
1424
                if f1[2] == "file":
1425
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1426
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1427
    def test_upgrade_new_instance(self):
1910.4.9 by Andrew Bennetts
Skip test_upgrade_new_instance if we don't have a local transport, and cosmetic tweaks.
1428
        """Does an available updater work?"""
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1429
        dir = self.make_bzrdir('.')
1910.4.9 by Andrew Bennetts
Skip test_upgrade_new_instance if we don't have a local transport, and cosmetic tweaks.
1430
        # for now, upgrade is not ready for partial bzrdirs.
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1431
        dir.create_repository()
1432
        dir.create_branch()
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1433
        self.createWorkingTreeOrSkip(dir)
1534.5.16 by Robert Collins
Review feedback.
1434
        if dir.can_convert_format():
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1435
            # if its default updatable there must be an updater
2204.4.14 by Aaron Bentley
lastest -> latest
1436
            # (we force the latest known format as downgrades may not be
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1437
            # available
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1438
            pb = ui.ui_factory.nested_progress_bar()
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1439
            try:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1440
                dir._format.get_converter(format=dir._format).convert(dir, pb)
1556.1.4 by Robert Collins
Add a new format for what will become knit, and the surrounding logic to upgrade repositories within metadirs, and tests for the same.
1441
            finally:
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1442
                pb.finished()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1443
            # and it should pass 'check' now.
4332.3.36 by Robert Collins
Silence a warning in test_bzrdir.
1444
            check.check_dwim(self.get_url('.'), False, True, True)
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1445
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1446
    def test_format_description(self):
1447
        dir = self.make_bzrdir('.')
1448
        text = dir._format.get_format_description()
1449
        self.failUnless(len(text))
1450
2830.1.3 by Ian Clatworthy
test that bzrdir retiring fails as expected once limit reached
1451
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
1452
class TestBreakLock(TestCaseWithControlDir):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1453
1454
    def test_break_lock_empty(self):
1455
        # break lock on an empty bzrdir should work silently.
1456
        dir = self.make_bzrdir('.')
1457
        try:
1458
            dir.break_lock()
1459
        except NotImplementedError:
1460
            pass
1461
1462
    def test_break_lock_repository(self):
1463
        # break lock with just a repo should unlock the repo.
1464
        repo = self.make_repository('.')
1465
        repo.lock_write()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1466
        lock_repo = repo.bzrdir.open_repository()
1467
        if not lock_repo.get_physical_lock_status():
1468
            # This bzrdir's default repository does not physically lock things
1469
            # and thus this interaction cannot be tested at the interface
1470
            # level.
1471
            repo.unlock()
1472
            return
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1473
        # only one yes needed here: it should only be unlocking
1474
        # the repo
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1475
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1476
        try:
1477
            repo.bzrdir.break_lock()
1478
        except NotImplementedError:
1479
            # this bzrdir does not implement break_lock - so we cant test it.
1480
            repo.unlock()
1481
            return
1482
        lock_repo.lock_write()
1483
        lock_repo.unlock()
1484
        self.assertRaises(errors.LockBroken, repo.unlock)
1485
1486
    def test_break_lock_branch(self):
1487
        # break lock with just a repo should unlock the branch.
1488
        # and not directly try the repository.
1489
        # we test this by making a branch reference to a branch
1490
        # and repository in another bzrdir
1491
        # for pre-metadir formats this will fail, thats ok.
1492
        master = self.make_branch('branch')
1493
        thisdir = self.make_bzrdir('this')
1494
        try:
1495
            bzrlib.branch.BranchReferenceFormat().initialize(
5051.3.10 by Jelmer Vernooij
Pass colocated branch name around in more places.
1496
                thisdir, target_branch=master)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1497
        except errors.IncompatibleFormat:
1498
            return
1499
        unused_repo = thisdir.create_repository()
1500
        master.lock_write()
1501
        unused_repo.lock_write()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1502
        try:
1503
            # two yes's : branch and repository. If the repo in this
1504
            # dir is inappropriately accessed, 3 will be needed, and
1505
            # we'll see that because the stream will be fully consumed
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1506
            bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1507
            # determine if the repository will have been locked;
1508
            this_repo_locked = \
1509
                thisdir.open_repository().get_physical_lock_status()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1510
            master.bzrdir.break_lock()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1511
            if this_repo_locked:
1512
                # only two ys should have been read
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1513
                self.assertEqual([True],
1514
                    bzrlib.ui.ui_factory.responses)
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1515
            else:
1516
                # only one y should have been read
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1517
                self.assertEqual([True, True],
1518
                    bzrlib.ui.ui_factory.responses)
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1519
            # we should be able to lock a newly opened branch now
1520
            branch = master.bzrdir.open_branch()
1521
            branch.lock_write()
1522
            branch.unlock()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1523
            if this_repo_locked:
1524
                # we should not be able to lock the repository in thisdir as
1525
                # its still held by the explicit lock we took, and the break
1526
                # lock should not have touched it.
1527
                repo = thisdir.open_repository()
3287.4.2 by Martin Pool
Change more tests to use reduceLockdirTimeout
1528
                self.assertRaises(errors.LockContention, repo.lock_write)
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1529
        finally:
1530
            unused_repo.unlock()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1531
        self.assertRaises(errors.LockBroken, master.unlock)
1532
1533
    def test_break_lock_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1534
        # break lock with a tree should unlock the tree but not try the
1535
        # branch explicitly. However this is very hard to test for as we
1536
        # dont have a tree reference class, nor is one needed;
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1537
        # the worst case if this code unlocks twice is an extra question
1538
        # being asked.
1539
        tree = self.make_branch_and_tree('.')
1540
        tree.lock_write()
1541
        # three yes's : tree, branch and repository.
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1542
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1543
        try:
1544
            tree.bzrdir.break_lock()
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1545
        except (NotImplementedError, errors.LockActive):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1546
            # bzrdir does not support break_lock
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1547
            # or one of the locked objects (currently only tree does this)
1548
            # raised a LockActive because we do still have a live locked
1549
            # object.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1550
            tree.unlock()
1551
            return
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1552
        self.assertEqual([True],
1553
                bzrlib.ui.ui_factory.responses)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1554
        lock_tree = tree.bzrdir.open_workingtree()
1555
        lock_tree.lock_write()
1556
        lock_tree.unlock()
1557
        self.assertRaises(errors.LockBroken, tree.unlock)
1558
1559
5363.2.18 by Jelmer Vernooij
Rename TestCaseWithBzrDir -> TestCaseWithControlDir.
1560
class TestTransportConfig(TestCaseWithControlDir):
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
1561
1562
    def test_get_config(self):
1563
        my_dir = self.make_bzrdir('.')
1564
        config = my_dir.get_config()
4288.1.6 by Robert Collins
Fix bzrdir implementation tests to handle read only bzrdir configs.
1565
        try:
1566
            config.set_default_stack_on('http://example.com')
1567
        except errors.BzrError, e:
1568
            if 'Cannot set config' in str(e):
1569
                self.assertFalse(
1570
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1571
                    "%r should support configs" % my_dir)
1572
                raise TestNotApplicable(
1573
                    'This BzrDir format does not support configs.')
1574
            else:
1575
                raise
3242.3.14 by Aaron Bentley
Make BzrDirConfig use TransportConfig
1576
        self.assertEqual('http://example.com', config.get_default_stack_on())
3567.1.2 by Michael Hudson
fix test some more
1577
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
3242.3.36 by Aaron Bentley
Updates from review comments
1578
        config2 = my_dir2.get_config()
3242.3.14 by Aaron Bentley
Make BzrDirConfig use TransportConfig
1579
        self.assertEqual('http://example.com', config2.get_default_stack_on())
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
1580
1581
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
1582
class ChrootedControlDirTests(ChrootedTestCase):
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.
1583
1584
    def test_find_repository_no_repository(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1585
        # loopback test to check the current format fails to find a
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.
1586
        # share repository correctly.
1587
        if not self.bzrdir_format.is_supported():
1588
            # unsupported formats are not loopback testable
1589
            # because the default open will not open them and
1590
            # they may not be initializable.
1591
            return
1592
        # supported formats must be able to init and open
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1593
        # - do the vfs initialisation over the basic vfs transport
1594
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1595
        url = self.get_vfs_only_url('subdir')
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1596
        transport.get_transport(self.get_vfs_only_url()).mkdir('subdir')
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1597
        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.
1598
        try:
1599
            repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1600
            # 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.
1601
            # code path.
1602
            return
1603
        except errors.NoRepositoryPresent:
1604
            pass
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1605
        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.
1606
        self.assertRaises(errors.NoRepositoryPresent,
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1607
                          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.
1608
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
1609
5363.2.22 by Jelmer Vernooij
Provide bzrlib.bzrdir.format_registry.
1610
class TestControlDirControlComponent(TestCaseWithControlDir):
1611
    """ControlDir implementations adequately implement ControlComponent."""
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1612
5158.6.1 by Martin Pool
Add ControlComponent interface and make BzrDir implement it
1613
    def test_urls(self):
1614
        bd = self.make_bzrdir('bd')
1615
        self.assertIsInstance(bd.user_url, str)
1616
        self.assertEqual(bd.user_url, bd.user_transport.base)
1617
        # for all current bzrdir implementations the user dir must be 
1618
        # above the control dir but we might need to relax that?
1619
        self.assertEqual(bd.control_url.find(bd.user_url), 0)
1620
        self.assertEqual(bd.control_url, bd.control_transport.base)