/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1
# Copyright (C) 2005, 2006, 2007 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
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Tests for bzrdir implementations - tests a bzrdir format."""
18
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
19
from cStringIO import StringIO
1731.1.33 by Aaron Bentley
Revert no-special-root changes
20
import errno
1534.4.39 by Robert Collins
Basic BzrDir support.
21
import os
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
22
from stat import S_ISDIR
1534.4.39 by Robert Collins
Basic BzrDir support.
23
import sys
24
1508.1.25 by Robert Collins
Update per review comments.
25
import bzrlib.branch
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
26
from bzrlib import (
27
    bzrdir,
28
    errors,
29
    lockdir,
30
    repository,
31
    transactions,
32
    transport,
33
    ui,
34
    workingtree,
35
    )
1534.4.39 by Robert Collins
Basic BzrDir support.
36
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
37
from bzrlib.check import check
1534.4.39 by Robert Collins
Basic BzrDir support.
38
from bzrlib.errors import (FileExists,
39
                           NoSuchRevision,
40
                           NoSuchFile,
41
                           UninitializableFormat,
42
                           NotBranchError,
43
                           )
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
44
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.
45
from bzrlib.tests import (
46
                          ChrootedTestCase,
47
                          TestCase,
48
                          TestCaseWithTransport,
49
                          TestSkipped,
50
                          )
1534.4.39 by Robert Collins
Basic BzrDir support.
51
from bzrlib.trace import mutter
52
from bzrlib.transport import get_transport
53
from bzrlib.upgrade import upgrade
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
54
from bzrlib.repofmt import weaverepo
1534.4.39 by Robert Collins
Basic BzrDir support.
55
56
57
class TestCaseWithBzrDir(TestCaseWithTransport):
58
59
    def setUp(self):
60
        super(TestCaseWithBzrDir, self).setUp()
61
        self.bzrdir = None
62
63
    def get_bzrdir(self):
64
        if self.bzrdir is None:
65
            self.bzrdir = self.make_bzrdir(None)
66
        return self.bzrdir
67
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
68
    def make_bzrdir(self, relpath, format=None):
69
        return super(TestCaseWithBzrDir, self).make_bzrdir(
70
            relpath, format=self.bzrdir_format)
71
1534.4.39 by Robert Collins
Basic BzrDir support.
72
73
74
class TestBzrDir(TestCaseWithBzrDir):
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.
75
    # Many of these tests test for disk equality rather than checking
76
    # for semantic equivalence. This works well for some tests but
77
    # is not good at handling changes in representation or the addition
78
    # or removal of control data. It would be nice to for instance:
79
    # sprout a new branch, check that the nickname has been reset by hand
80
    # and then set the nickname to match the source branch, at which point
81
    # a semantic equivalence should pass
82
83
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
84
        """Assert that the content of source and target are identical.
85
86
        paths in ignore list will be completely ignored.
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
87
        
88
        We ignore paths that represent data which is allowed to change during
89
        a clone or sprout: for instance, inventory.knit contains gzip fragements
90
        which have timestamps in them, and as we have read the inventory from 
91
        the source knit, the already-read data is recompressed rather than
92
        reading it again, which leads to changed timestamps. This is ok though,
93
        because the inventory.kndx file is not ignored, and the integrity of
94
        knit joins is tested by test_knit and test_versionedfile.
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.
95
        """
96
        files = []
97
        directories = ['.']
98
        while directories:
99
            dir = directories.pop()
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
100
            for path in set(source.list_dir(dir) + target.list_dir(dir)):
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.
101
                path = dir + '/' + path
102
                if path in ignore_list:
103
                    continue
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
104
                try:
105
                    stat = source.stat(path)
2230.3.30 by Aaron Bentley
Fix whitespace issues
106
                except errors.NoSuchFile:
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
107
                    self.fail('%s not in source' % path)
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.
108
                if S_ISDIR(stat.st_mode):
109
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
110
                    directories.append(path)
111
                else:
112
                    self.assertEqualDiff(source.get(path).read(),
113
                                         target.get(path).read(),
114
                                         "text for file %r differs:\n" % path)
115
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
116
    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.
117
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
118
        
119
        If the bzrdir does have a workingtree, this is a no-op.
120
        """
121
        try:
122
            a_bzrdir.open_workingtree()
123
        except (errors.NotLocalUrl, errors.NoWorkingTree):
124
            raise TestSkipped("bzrdir on transport %r has no working tree"
125
                              % a_bzrdir.transport)
126
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
127
    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.
128
        """Create a working tree on a_bzrdir, or raise TestSkipped.
129
        
130
        A simple wrapper for create_workingtree that translates NotLocalUrl into
131
        TestSkipped.  Returns the newly created working tree.
132
        """
133
        try:
134
            return a_bzrdir.create_workingtree()
135
        except errors.NotLocalUrl:
136
            raise TestSkipped("cannot make working tree with transport %r"
137
                              % a_bzrdir.transport)
138
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
139
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None, basis=None,
140
                     force_new_repo=False):
141
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
142
        
143
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
144
        TestSkipped.  Returns the newly sprouted bzrdir.
145
        """
146
        try:
147
            target = from_bzrdir.sprout(to_url, revision_id=revision_id,
148
                                        basis=basis,
149
                                        force_new_repo=force_new_repo)
150
        except errors.NotLocalUrl:
151
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
152
        return target
153
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
154
    def test_create_null_workingtree(self):
155
        dir = self.make_bzrdir('dir1')
156
        dir.create_repository()
157
        dir.create_branch()
158
        wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
159
        self.assertEqual([], wt.get_parent_ids())
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
160
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
161
    def test_destroy_workingtree(self):
162
        tree = self.make_branch_and_tree('tree')
163
        self.build_tree(['tree/file'])
164
        tree.add('file')
165
        tree.commit('first commit')
166
        bzrdir = tree.bzrdir
167
        try:
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
168
            bzrdir.destroy_workingtree()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
169
        except errors.UnsupportedOperation:
170
            raise TestSkipped('Format does not support destroying tree')
171
        self.failIfExists('tree/file')
172
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
173
        bzrdir.create_workingtree()
174
        self.failUnlessExists('tree/file')
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
175
        bzrdir.destroy_workingtree_metadata()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
176
        self.failUnlessExists('tree/file')
177
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
178
            
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.
179
    def test_clone_bzrdir_empty(self):
180
        dir = self.make_bzrdir('source')
181
        target = dir.clone(self.get_url('target'))
182
        self.assertNotEqual(dir.transport.base, target.transport.base)
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
183
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
184
                                    ['./.bzr/merge-hashes'])
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.
185
    
1534.6.8 by Robert Collins
Test the use of clone on empty bzrdir with force_new_repo.
186
    def test_clone_bzrdir_empty_force_new_ignored(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
187
        # the force_new_repo parameter should have no effect on an empty
1534.6.8 by Robert Collins
Test the use of clone on empty bzrdir with force_new_repo.
188
        # bzrdir's clone logic
189
        dir = self.make_bzrdir('source')
190
        target = dir.clone(self.get_url('target'), force_new_repo=True)
191
        self.assertNotEqual(dir.transport.base, target.transport.base)
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
192
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
193
                                    ['./.bzr/merge-hashes'])
1534.6.8 by Robert Collins
Test the use of clone on empty bzrdir with force_new_repo.
194
    
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.
195
    def test_clone_bzrdir_repository(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.
196
        tree = self.make_branch_and_tree('commit_tree')
197
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
198
        tree.add('foo')
199
        tree.commit('revision 1', rev_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.
200
        dir = self.make_bzrdir('source')
201
        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.
202
        repo.fetch(tree.branch.repository)
203
        self.assertTrue(repo.has_revision('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.
204
        target = dir.clone(self.get_url('target'))
205
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
206
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
207
                                    [
208
                                     './.bzr/merge-hashes',
209
                                     './.bzr/repository/inventory.knit',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
210
                                     ])
211
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.
212
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.
213
    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.
214
        tree = self.make_branch_and_tree('commit_tree')
215
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
216
        tree.add('foo')
217
        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.
218
        dir = self.make_bzrdir('source')
219
        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.
220
        repo.fetch(tree.branch.repository)
221
        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.
222
        try:
223
            self.make_repository('target', shared=True)
224
        except errors.IncompatibleFormat:
225
            return
226
        target = dir.clone(self.get_url('target/child'))
227
        self.assertNotEqual(dir.transport.base, target.transport.base)
228
        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.
229
230
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
231
        try:
232
            shared_repo = self.make_repository('shared', shared=True)
233
        except errors.IncompatibleFormat:
234
            return
235
        tree = self.make_branch_and_tree('commit_tree')
236
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
237
        tree.add('foo')
238
        tree.commit('revision 1', rev_id='1')
239
        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.
240
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
241
        tree.commit('revision 2', rev_id='2')
242
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
243
        dir = self.make_bzrdir('shared/source')
244
        dir.create_branch()
245
        target = dir.clone(self.get_url('shared/target'))
246
        self.assertNotEqual(dir.transport.base, target.transport.base)
247
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
248
        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
249
250
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
251
        try:
252
            shared_repo = self.make_repository('shared', shared=True)
253
        except errors.IncompatibleFormat:
254
            return
255
        tree = self.make_branch_and_tree('commit_tree')
256
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
257
        tree.add('foo')
258
        tree.commit('revision 1', rev_id='1')
259
        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.
260
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
261
        tree.commit('revision 2', rev_id='2')
262
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
263
        shared_repo.set_make_working_trees(False)
264
        self.assertFalse(shared_repo.make_working_trees())
265
        self.assertTrue(shared_repo.has_revision('1'))
266
        dir = self.make_bzrdir('shared/source')
267
        dir.create_branch()
268
        target = dir.clone(self.get_url('target'))
269
        self.assertNotEqual(dir.transport.base, target.transport.base)
270
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
271
        branch = target.open_branch()
272
        self.assertTrue(branch.repository.has_revision('1'))
273
        self.assertFalse(branch.repository.make_working_trees())
274
        self.assertTrue(branch.repository.is_shared())
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.
275
        
1534.6.9 by Robert Collins
sprouting into shared repositories
276
    def test_clone_bzrdir_repository_under_shared_force_new_repo(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.
277
        tree = self.make_branch_and_tree('commit_tree')
278
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
279
        tree.add('foo')
280
        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.
281
        dir = self.make_bzrdir('source')
282
        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.
283
        repo.fetch(tree.branch.repository)
284
        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.
285
        try:
286
            self.make_repository('target', shared=True)
287
        except errors.IncompatibleFormat:
288
            return
289
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
290
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
291
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
292
                                    ['./.bzr/repository/inventory.knit',
293
                                     ])
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.
294
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.
295
    def test_clone_bzrdir_repository_revision(self):
296
        # test for revision limiting, [smoke test, not corner case checks].
297
        # make a repository with some revisions,
298
        # and clone it with a revision limit.
299
        # 
300
        tree = self.make_branch_and_tree('commit_tree')
301
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
302
        tree.add('foo')
303
        tree.commit('revision 1', rev_id='1')
304
        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.
305
        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.
306
        tree.commit('revision 2', rev_id='2')
307
        source = self.make_repository('source')
308
        tree.bzrdir.open_repository().copy_content_into(source)
309
        dir = source.bzrdir
310
        target = dir.clone(self.get_url('target'), revision_id='2')
311
        raise TestSkipped('revision limiting not strict yet')
312
313
    def test_clone_bzrdir_branch_and_repo(self):
314
        tree = self.make_branch_and_tree('commit_tree')
315
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
316
        tree.add('foo')
317
        tree.commit('revision 1')
318
        source = self.make_branch('source')
319
        tree.bzrdir.open_repository().copy_content_into(source.repository)
320
        tree.bzrdir.open_branch().copy_content_into(source)
321
        dir = source.bzrdir
322
        target = dir.clone(self.get_url('target'))
323
        self.assertNotEqual(dir.transport.base, target.transport.base)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
324
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
325
                                    [
326
                                     './.bzr/basis-inventory-cache',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
327
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
328
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
329
                                     './.bzr/repository/inventory.knit',
2230.3.30 by Aaron Bentley
Fix whitespace issues
330
                                     './.bzr/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
331
                                    ])
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.
332
333
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
334
        # by default cloning into a shared repo uses the shared repo.
335
        tree = self.make_branch_and_tree('commit_tree')
336
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
337
        tree.add('foo')
338
        tree.commit('revision 1')
339
        source = self.make_branch('source')
340
        tree.bzrdir.open_repository().copy_content_into(source.repository)
341
        tree.bzrdir.open_branch().copy_content_into(source)
342
        try:
343
            self.make_repository('target', shared=True)
344
        except errors.IncompatibleFormat:
345
            return
346
        dir = source.bzrdir
347
        target = dir.clone(self.get_url('target/child'))
348
        self.assertNotEqual(dir.transport.base, target.transport.base)
349
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
350
        self.assertEqual(source.revision_history(),
351
                         target.open_branch().revision_history())
352
353
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
354
        # by default cloning into a shared repo uses the shared repo.
355
        tree = self.make_branch_and_tree('commit_tree')
356
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
357
        tree.add('foo')
358
        tree.commit('revision 1')
359
        source = self.make_branch('source')
360
        tree.bzrdir.open_repository().copy_content_into(source.repository)
361
        tree.bzrdir.open_branch().copy_content_into(source)
362
        try:
363
            self.make_repository('target', shared=True)
364
        except errors.IncompatibleFormat:
365
            return
366
        dir = source.bzrdir
367
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
368
        self.assertNotEqual(dir.transport.base, target.transport.base)
369
        target.open_repository()
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
370
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
371
                                    ['./.bzr/repository/inventory.knit',
372
                                     ])
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.
373
374
    def test_clone_bzrdir_branch_reference(self):
375
        # cloning should preserve the reference status of the branch in a bzrdir
376
        referenced_branch = self.make_branch('referencced')
377
        dir = self.make_bzrdir('source')
378
        try:
1508.1.25 by Robert Collins
Update per review comments.
379
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
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.
380
                referenced_branch)
381
        except errors.IncompatibleFormat:
382
            # this is ok too, not all formats have to support references.
383
            return
384
        target = dir.clone(self.get_url('target'))
385
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
386
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
387
                                    ['./.bzr/repository/inventory.knit',
388
                                     ])
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.
389
390
    def test_clone_bzrdir_branch_revision(self):
391
        # test for revision limiting, [smoke test, not corner case checks].
392
        # make a branch with some revisions,
393
        # and clone it with a revision limit.
394
        # 
395
        tree = self.make_branch_and_tree('commit_tree')
396
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
397
        tree.add('foo')
398
        tree.commit('revision 1', rev_id='1')
399
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
400
        source = self.make_branch('source')
401
        tree.bzrdir.open_repository().copy_content_into(source.repository)
402
        tree.bzrdir.open_branch().copy_content_into(source)
403
        dir = source.bzrdir
404
        target = dir.clone(self.get_url('target'), revision_id='1')
405
        self.assertEqual('1', target.open_branch().last_revision())
406
        
407
    def test_clone_bzrdir_tree_branch_repo(self):
408
        tree = self.make_branch_and_tree('sourcce')
409
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
410
        tree.add('foo')
411
        tree.commit('revision 1')
412
        dir = tree.bzrdir
413
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
414
        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.
415
        self.assertNotEqual(dir.transport.base, target.transport.base)
416
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
417
                                    ['./.bzr/stat-cache',
418
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
419
                                     './.bzr/checkout/merge-hashes',
420
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
421
                                     './.bzr/repository/inventory.knit',
422
                                     ])
423
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
424
        target.open_workingtree().revert([])
425
426
    def test_revert_inventory(self):
427
        tree = self.make_branch_and_tree('sourcce')
428
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
429
        tree.add('foo')
430
        tree.commit('revision 1')
431
        dir = tree.bzrdir
432
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
433
        self.skipIfNoWorkingTree(target)
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
434
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
435
                                    ['./.bzr/stat-cache',
436
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
437
                                     './.bzr/checkout/merge-hashes',
438
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
439
                                     './.bzr/repository/inventory.knit',
440
                                     ])
441
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
442
        target.open_workingtree().revert([])
443
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
444
                                    ['./.bzr/stat-cache',
445
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
446
                                     './.bzr/checkout/merge-hashes',
447
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
448
                                     './.bzr/repository/inventory.knit',
449
                                     ])
450
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.
451
452
    def test_clone_bzrdir_tree_branch_reference(self):
453
        # a tree with a branch reference (aka a checkout) 
454
        # should stay a checkout on clone.
455
        referenced_branch = self.make_branch('referencced')
456
        dir = self.make_bzrdir('source')
457
        try:
1508.1.25 by Robert Collins
Update per review comments.
458
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
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.
459
                referenced_branch)
460
        except errors.IncompatibleFormat:
461
            # this is ok too, not all formats have to support references.
462
            return
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
463
        self.createWorkingTreeOrSkip(dir)
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.
464
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
465
        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.
466
        self.assertNotEqual(dir.transport.base, target.transport.base)
467
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
468
                                    ['./.bzr/stat-cache',
469
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
470
                                     './.bzr/checkout/merge-hashes',
471
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
472
                                     './.bzr/repository/inventory.knit',
473
                                     ])
474
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.
475
    def test_clone_bzrdir_tree_revision(self):
476
        # test for revision limiting, [smoke test, not corner case checks].
477
        # make a tree with a revision with a last-revision
478
        # and clone it with a revision limit.
479
        # This smoke test just checks the revision-id is right. Tree specific
480
        # tests will check corner cases.
481
        tree = self.make_branch_and_tree('source')
482
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
483
        tree.add('foo')
484
        tree.commit('revision 1', rev_id='1')
485
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
486
        dir = tree.bzrdir
487
        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.
488
        self.skipIfNoWorkingTree(target)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
489
        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.
490
491
    def test_clone_bzrdir_incomplete_source_with_basis(self):
492
        # ensure that basis really does grab from the basis by having incomplete source
493
        tree = self.make_branch_and_tree('commit_tree')
494
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
495
        tree.add('foo')
496
        tree.commit('revision 1', rev_id='1')
497
        source = self.make_branch_and_tree('source')
498
        # this gives us an incomplete repository
499
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
500
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
501
        tree.bzrdir.open_branch().copy_content_into(source.branch)
502
        tree.copy_content_into(source)
503
        self.assertFalse(source.branch.repository.has_revision('2'))
504
        dir = source.bzrdir
505
        target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
506
        self.assertEqual('2', target.open_branch().last_revision())
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.
507
        try:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
508
            self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
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.
509
        except errors.NoWorkingTree:
510
            # It should have a working tree if it's able to have one, so if
511
            # we're here make sure it really can't have one.
512
            self.assertRaises(errors.NotLocalUrl, target.create_workingtree)
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.
513
        self.assertTrue(target.open_branch().repository.has_revision('2'))
514
515
    def test_sprout_bzrdir_empty(self):
516
        dir = self.make_bzrdir('source')
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
517
        target = self.sproutOrSkip(dir, 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.
518
        self.assertNotEqual(dir.transport.base, target.transport.base)
519
        # creates a new repository branch and tree
520
        target.open_repository()
521
        target.open_branch()
522
        target.open_workingtree()
1534.6.9 by Robert Collins
sprouting into shared repositories
523
524
    def test_sprout_bzrdir_empty_under_shared_repo(self):
525
        # sprouting an empty dir into a repo uses the repo
526
        dir = self.make_bzrdir('source')
527
        try:
528
            self.make_repository('target', shared=True)
529
        except errors.IncompatibleFormat:
530
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
531
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
532
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
533
        target.open_branch()
534
        target.open_workingtree()
535
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.
536
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
537
        # the force_new_repo parameter should force use of a new repo in an empty
538
        # bzrdir's sprout logic
539
        dir = self.make_bzrdir('source')
540
        try:
541
            self.make_repository('target', shared=True)
542
        except errors.IncompatibleFormat:
543
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
544
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
545
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
546
        target.open_repository()
547
        target.open_branch()
548
        target.open_workingtree()
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.
549
    
550
    def test_sprout_bzrdir_repository(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.
551
        tree = self.make_branch_and_tree('commit_tree')
552
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
553
        tree.add('foo')
554
        tree.commit('revision 1', rev_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.
555
        dir = self.make_bzrdir('source')
556
        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.
557
        repo.fetch(tree.branch.repository)
558
        self.assertTrue(repo.has_revision('1'))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
559
        try:
560
            self.assertIs(dir.open_branch().last_revision(), None)
561
        except errors.NotBranchError:
562
            pass
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
563
        target = self.sproutOrSkip(dir, 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.
564
        self.assertNotEqual(dir.transport.base, target.transport.base)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
565
        # testing inventory isn't reasonable for repositories
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
566
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
567
                                    [
568
                                     './.bzr/branch',
569
                                     './.bzr/checkout',
570
                                     './.bzr/inventory',
571
                                     './.bzr/parent',
572
                                     './.bzr/repository/inventory.knit',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
573
                                     ])
1731.1.33 by Aaron Bentley
Revert no-special-root changes
574
        try:
575
            # If we happen to have a tree, we'll guarantee everything
576
            # except for the tree root is the same.
577
            inventory_f = file(dir.transport.base+'inventory', 'rb')
578
            self.assertContainsRe(inventory_f.read(), 
579
                                  '<inventory file_id="TREE_ROOT[^"]*"'
580
                                  ' format="5">\n</inventory>\n')
581
            inventory_f.close()
582
        except IOError, e:
583
            if e.errno != errno.ENOENT:
584
                raise
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.
585
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
586
    def test_sprout_bzrdir_with_repository_to_shared(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
587
        tree = self.make_branch_and_tree('commit_tree')
588
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
589
        tree.add('foo')
590
        tree.commit('revision 1', rev_id='1')
591
        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.
592
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
593
        tree.commit('revision 2', rev_id='2')
594
        source = self.make_repository('source')
595
        tree.bzrdir.open_repository().copy_content_into(source)
596
        dir = source.bzrdir
597
        try:
598
            shared_repo = self.make_repository('target', shared=True)
599
        except errors.IncompatibleFormat:
600
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
601
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
602
        self.assertNotEqual(dir.transport.base, target.transport.base)
603
        self.assertTrue(shared_repo.has_revision('1'))
604
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
605
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
606
        try:
607
            shared_repo = self.make_repository('shared', shared=True)
608
        except errors.IncompatibleFormat:
609
            return
610
        tree = self.make_branch_and_tree('commit_tree')
611
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
612
        tree.add('foo')
613
        tree.commit('revision 1', rev_id='1')
614
        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.
615
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
616
        tree.commit('revision 2', rev_id='2')
617
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
618
        dir = self.make_bzrdir('shared/source')
619
        dir.create_branch()
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
620
        target = self.sproutOrSkip(dir, self.get_url('shared/target'))
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
621
        self.assertNotEqual(dir.transport.base, target.transport.base)
622
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
623
        self.assertTrue(shared_repo.has_revision('1'))
624
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
625
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
626
        try:
627
            shared_repo = self.make_repository('shared', shared=True)
628
        except errors.IncompatibleFormat:
629
            return
630
        tree = self.make_branch_and_tree('commit_tree')
631
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
632
        tree.add('foo')
633
        tree.commit('revision 1', rev_id='1')
634
        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.
635
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
636
        tree.commit('revision 2', rev_id='2')
637
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
638
        shared_repo.set_make_working_trees(False)
639
        self.assertFalse(shared_repo.make_working_trees())
640
        self.assertTrue(shared_repo.has_revision('1'))
641
        dir = self.make_bzrdir('shared/source')
642
        dir.create_branch()
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
643
        target = self.sproutOrSkip(dir, self.get_url('target'))
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
644
        self.assertNotEqual(dir.transport.base, target.transport.base)
645
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
646
        branch = target.open_branch()
647
        self.assertTrue(branch.repository.has_revision('1'))
648
        self.assertTrue(branch.repository.make_working_trees())
649
        self.assertFalse(branch.repository.is_shared())
650
1534.6.9 by Robert Collins
sprouting into shared repositories
651
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
652
        tree = self.make_branch_and_tree('commit_tree')
653
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
654
        tree.add('foo')
655
        tree.commit('revision 1', rev_id='1')
656
        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.
657
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
658
        tree.commit('revision 2', rev_id='2')
659
        source = self.make_repository('source')
660
        tree.bzrdir.open_repository().copy_content_into(source)
661
        dir = source.bzrdir
662
        try:
663
            shared_repo = self.make_repository('target', shared=True)
664
        except errors.IncompatibleFormat:
665
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
666
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
667
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
668
        self.assertNotEqual(dir.transport.base, target.transport.base)
669
        self.assertFalse(shared_repo.has_revision('1'))
670
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
    def test_sprout_bzrdir_repository_revision(self):
672
        # test for revision limiting, [smoke test, not corner case checks].
673
        # make a repository with some revisions,
674
        # and sprout it with a revision limit.
675
        # 
676
        tree = self.make_branch_and_tree('commit_tree')
677
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
678
        tree.add('foo')
679
        tree.commit('revision 1', rev_id='1')
680
        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.
681
        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.
682
        tree.commit('revision 2', rev_id='2')
683
        source = self.make_repository('source')
684
        tree.bzrdir.open_repository().copy_content_into(source)
685
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
686
        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.
687
        raise TestSkipped('revision limiting not strict yet')
688
689
    def test_sprout_bzrdir_branch_and_repo(self):
690
        tree = self.make_branch_and_tree('commit_tree')
691
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
692
        tree.add('foo')
693
        tree.commit('revision 1')
694
        source = self.make_branch('source')
695
        tree.bzrdir.open_repository().copy_content_into(source.repository)
696
        tree.bzrdir.open_branch().copy_content_into(source)
697
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
698
        target = self.sproutOrSkip(dir, 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.
699
        self.assertNotEqual(dir.transport.base, target.transport.base)
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
700
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
701
                                    [
702
                                     './.bzr/basis-inventory-cache',
703
                                     './.bzr/branch/branch.conf',
704
                                     './.bzr/branch/parent',
705
                                     './.bzr/checkout',
706
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
707
                                     './.bzr/checkout/stat-cache',
708
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
709
                                     './.bzr/parent',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
710
                                     './.bzr/repository/inventory.knit',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
711
                                     './.bzr/stat-cache',
712
                                     './foo',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
713
                                     ])
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.
714
1534.6.9 by Robert Collins
sprouting into shared repositories
715
    def test_sprout_bzrdir_branch_and_repo_shared(self):
716
        # sprouting a branch with a repo into a shared repo uses the shared
717
        # repo
718
        tree = self.make_branch_and_tree('commit_tree')
719
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
720
        tree.add('foo')
721
        tree.commit('revision 1', rev_id='1')
722
        source = self.make_branch('source')
723
        tree.bzrdir.open_repository().copy_content_into(source.repository)
724
        tree.bzrdir.open_branch().copy_content_into(source)
725
        dir = source.bzrdir
726
        try:
727
            shared_repo = self.make_repository('target', shared=True)
728
        except errors.IncompatibleFormat:
729
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
730
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
731
        self.assertTrue(shared_repo.has_revision('1'))
732
733
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
734
        # sprouting a branch with a repo into a shared repo uses the shared
735
        # repo
736
        tree = self.make_branch_and_tree('commit_tree')
737
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
738
        tree.add('foo')
739
        tree.commit('revision 1', rev_id='1')
740
        source = self.make_branch('source')
741
        tree.bzrdir.open_repository().copy_content_into(source.repository)
742
        tree.bzrdir.open_branch().copy_content_into(source)
743
        dir = source.bzrdir
744
        try:
745
            shared_repo = self.make_repository('target', shared=True)
746
        except errors.IncompatibleFormat:
747
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
748
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
749
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
750
        self.assertNotEqual(dir.transport.base, target.transport.base)
751
        self.assertFalse(shared_repo.has_revision('1'))
752
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.
753
    def test_sprout_bzrdir_branch_reference(self):
754
        # sprouting should create a repository if needed and a sprouted branch.
755
        referenced_branch = self.make_branch('referencced')
756
        dir = self.make_bzrdir('source')
757
        try:
1508.1.25 by Robert Collins
Update per review comments.
758
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
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.
759
                referenced_branch)
760
        except errors.IncompatibleFormat:
761
            # this is ok too, not all formats have to support references.
762
            return
763
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
764
        target = self.sproutOrSkip(dir, 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.
765
        self.assertNotEqual(dir.transport.base, target.transport.base)
766
        # we want target to have a branch that is in-place.
767
        self.assertEqual(target, target.open_branch().bzrdir)
768
        # and as we dont support repositories being detached yet, a repo in 
769
        # place
770
        target.open_repository()
771
1534.6.9 by Robert Collins
sprouting into shared repositories
772
    def test_sprout_bzrdir_branch_reference_shared(self):
773
        # sprouting should create a repository if needed and a sprouted branch.
774
        referenced_tree = self.make_branch_and_tree('referenced')
775
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
776
        dir = self.make_bzrdir('source')
777
        try:
778
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
779
                referenced_tree.branch)
780
        except errors.IncompatibleFormat:
781
            # this is ok too, not all formats have to support references.
782
            return
783
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
784
        try:
785
            shared_repo = self.make_repository('target', shared=True)
786
        except errors.IncompatibleFormat:
787
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
788
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
789
        self.assertNotEqual(dir.transport.base, target.transport.base)
790
        # we want target to have a branch that is in-place.
791
        self.assertEqual(target, target.open_branch().bzrdir)
792
        # and we want no repository as the target is shared
793
        self.assertRaises(errors.NoRepositoryPresent, 
794
                          target.open_repository)
795
        # and we want revision '1' in the shared repo
796
        self.assertTrue(shared_repo.has_revision('1'))
797
798
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
799
        # sprouting should create a repository if needed and a sprouted branch.
800
        referenced_tree = self.make_branch_and_tree('referenced')
801
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
802
        dir = self.make_bzrdir('source')
803
        try:
804
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
805
                referenced_tree.branch)
806
        except errors.IncompatibleFormat:
807
            # this is ok too, not all formats have to support references.
808
            return
809
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
810
        try:
811
            shared_repo = self.make_repository('target', shared=True)
812
        except errors.IncompatibleFormat:
813
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
814
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
815
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
816
        self.assertNotEqual(dir.transport.base, target.transport.base)
817
        # we want target to have a branch that is in-place.
818
        self.assertEqual(target, target.open_branch().bzrdir)
819
        # and we want revision '1' in the new repo
820
        self.assertTrue(target.open_repository().has_revision('1'))
821
        # but not the shared one
822
        self.assertFalse(shared_repo.has_revision('1'))
823
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.
824
    def test_sprout_bzrdir_branch_revision(self):
825
        # test for revision limiting, [smoke test, not corner case checks].
826
        # make a repository with some revisions,
827
        # and sprout it with a revision limit.
828
        # 
829
        tree = self.make_branch_and_tree('commit_tree')
830
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
831
        tree.add('foo')
832
        tree.commit('revision 1', rev_id='1')
833
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
834
        source = self.make_branch('source')
835
        tree.bzrdir.open_repository().copy_content_into(source.repository)
836
        tree.bzrdir.open_branch().copy_content_into(source)
837
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
838
        target = self.sproutOrSkip(dir, 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.
839
        self.assertEqual('1', target.open_branch().last_revision())
840
        
841
    def test_sprout_bzrdir_tree_branch_repo(self):
842
        tree = self.make_branch_and_tree('sourcce')
843
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
844
        tree.add('foo')
845
        tree.commit('revision 1')
846
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
847
        target = self.sproutOrSkip(dir, 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.
848
        self.assertNotEqual(dir.transport.base, target.transport.base)
849
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
850
                                    [
851
                                     './.bzr/branch/branch.conf',
852
                                     './.bzr/branch/parent',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
853
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
854
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
855
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
856
                                     './.bzr/parent',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
857
                                     './.bzr/repository/inventory.knit',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
858
                                     './.bzr/stat-cache',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
859
                                     ])
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.
860
861
    def test_sprout_bzrdir_tree_branch_reference(self):
862
        # 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.
863
        # 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.
864
        referenced_branch = self.make_branch('referencced')
865
        dir = self.make_bzrdir('source')
866
        try:
1508.1.25 by Robert Collins
Update per review comments.
867
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
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.
868
                referenced_branch)
869
        except errors.IncompatibleFormat:
870
            # this is ok too, not all formats have to support references.
871
            return
872
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
873
        tree = self.createWorkingTreeOrSkip(dir)
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
874
        tree.bzrdir.root_transport.mkdir('subdir')
875
        tree.add('subdir')
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
876
        target = self.sproutOrSkip(dir, 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.
877
        self.assertNotEqual(dir.transport.base, target.transport.base)
878
        # we want target to have a branch that is in-place.
879
        self.assertEqual(target, target.open_branch().bzrdir)
880
        # and as we dont support repositories being detached yet, a repo in 
881
        # place
882
        target.open_repository()
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
883
        result_tree = target.open_workingtree()
884
        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.
885
886
    def test_sprout_bzrdir_tree_branch_reference_revision(self):
887
        # 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.
888
        # 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.
889
        # and the likewise the new branch should be truncated too
890
        referenced_branch = self.make_branch('referencced')
891
        dir = self.make_bzrdir('source')
892
        try:
1508.1.25 by Robert Collins
Update per review comments.
893
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
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.
894
                referenced_branch)
895
        except errors.IncompatibleFormat:
896
            # this is ok too, not all formats have to support references.
897
            return
898
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
899
        tree = self.createWorkingTreeOrSkip(dir)
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.
900
        self.build_tree(['foo'], transport=dir.root_transport)
901
        tree.add('foo')
902
        tree.commit('revision 1', rev_id='1')
903
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
904
        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.
905
        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.
906
        self.assertNotEqual(dir.transport.base, target.transport.base)
907
        # we want target to have a branch that is in-place.
908
        self.assertEqual(target, target.open_branch().bzrdir)
909
        # and as we dont support repositories being detached yet, a repo in 
910
        # place
911
        target.open_repository()
912
        # we trust that the working tree sprouting works via the other tests.
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
913
        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.
914
        self.assertEqual('1', target.open_branch().last_revision())
915
916
    def test_sprout_bzrdir_tree_revision(self):
917
        # test for revision limiting, [smoke test, not corner case checks].
918
        # make a tree with a revision with a last-revision
919
        # and sprout it with a revision limit.
920
        # This smoke test just checks the revision-id is right. Tree specific
921
        # tests will check corner cases.
922
        tree = self.make_branch_and_tree('source')
923
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
924
        tree.add('foo')
925
        tree.commit('revision 1', rev_id='1')
926
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
927
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
928
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
929
        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.
930
931
    def test_sprout_bzrdir_incomplete_source_with_basis(self):
932
        # ensure that basis really does grab from the basis by having incomplete source
933
        tree = self.make_branch_and_tree('commit_tree')
934
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
935
        tree.add('foo')
936
        tree.commit('revision 1', rev_id='1')
937
        source = self.make_branch_and_tree('source')
938
        # this gives us an incomplete repository
939
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
940
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
941
        tree.bzrdir.open_branch().copy_content_into(source.branch)
942
        tree.copy_content_into(source)
943
        self.assertFalse(source.branch.repository.has_revision('2'))
944
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
945
        target = self.sproutOrSkip(dir, self.get_url('target'),
946
                                   basis=tree.bzrdir)
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.
947
        self.assertEqual('2', target.open_branch().last_revision())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
948
        self.assertEqual(['2'], 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.
949
        self.assertTrue(target.open_branch().repository.has_revision('2'))
1534.4.39 by Robert Collins
Basic BzrDir support.
950
951
    def test_format_initialize_find_open(self):
952
        # loopback test to check the current format initializes to itself.
953
        if not self.bzrdir_format.is_supported():
954
            # unsupported formats are not loopback testable
955
            # because the default open will not open them and
956
            # they may not be initializable.
957
            return
958
        # supported formats must be able to init and open
959
        t = get_transport(self.get_url())
960
        readonly_t = get_transport(self.get_readonly_url())
961
        made_control = self.bzrdir_format.initialize(t.base)
962
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
963
        self.assertEqual(self.bzrdir_format,
964
                         bzrdir.BzrDirFormat.find_format(readonly_t))
965
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
966
        opened_dir = bzrdir.BzrDir.open(t.base)
967
        self.assertEqual(made_control._format,
968
                         opened_dir._format)
969
        self.assertEqual(direct_opened_dir._format,
970
                         opened_dir._format)
971
        self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
972
973
    def test_open_not_bzrdir(self):
974
        # test the formats specific behaviour for no-content or similar dirs.
975
        self.assertRaises(NotBranchError,
976
                          self.bzrdir_format.open,
977
                          get_transport(self.get_readonly_url()))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
978
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
979
    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.
980
        # a bzrdir can construct a branch and repository for itself.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
981
        if not self.bzrdir_format.is_supported():
982
            # unsupported formats are not loopback testable
983
            # because the default open will not open them and
984
            # they may not be initializable.
985
            return
986
        t = get_transport(self.get_url())
987
        made_control = self.bzrdir_format.initialize(t.base)
988
        made_repo = made_control.create_repository()
989
        made_branch = made_control.create_branch()
1508.1.25 by Robert Collins
Update per review comments.
990
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
991
        self.assertEqual(made_control, made_branch.bzrdir)
992
        
993
    def test_open_branch(self):
994
        if not self.bzrdir_format.is_supported():
995
            # unsupported formats are not loopback testable
996
            # because the default open will not open them and
997
            # they may not be initializable.
998
            return
999
        t = get_transport(self.get_url())
1000
        made_control = self.bzrdir_format.initialize(t.base)
1001
        made_repo = made_control.create_repository()
1002
        made_branch = made_control.create_branch()
1003
        opened_branch = made_control.open_branch()
1004
        self.assertEqual(made_control, opened_branch.bzrdir)
1005
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1006
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1007
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1008
    def test_create_repository(self):
1009
        # a bzrdir can construct a repository for itself.
1010
        if not self.bzrdir_format.is_supported():
1011
            # unsupported formats are not loopback testable
1012
            # because the default open will not open them and
1013
            # they may not be initializable.
1014
            return
1015
        t = get_transport(self.get_url())
1016
        made_control = self.bzrdir_format.initialize(t.base)
1017
        made_repo = made_control.create_repository()
1018
        self.failUnless(isinstance(made_repo, repository.Repository))
1019
        self.assertEqual(made_control, made_repo.bzrdir)
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1020
1021
    def test_create_repository_shared(self):
1022
        # a bzrdir can create a shared repository or 
1023
        # fail appropriately
1024
        if not self.bzrdir_format.is_supported():
1025
            # unsupported formats are not loopback testable
1026
            # because the default open will not open them and
1027
            # they may not be initializable.
1028
            return
1029
        t = get_transport(self.get_url())
1030
        made_control = self.bzrdir_format.initialize(t.base)
1031
        try:
1032
            made_repo = made_control.create_repository(shared=True)
1033
        except errors.IncompatibleFormat:
1034
            # Old bzrdir formats don't support shared repositories
1035
            # and should raise IncompatibleFormat
1036
            return
1037
        self.assertTrue(made_repo.is_shared())
1038
1039
    def test_create_repository_nonshared(self):
1040
        # a bzrdir can create a non-shared repository 
1041
        if not self.bzrdir_format.is_supported():
1042
            # unsupported formats are not loopback testable
1043
            # because the default open will not open them and
1044
            # they may not be initializable.
1045
            return
1046
        t = get_transport(self.get_url())
1047
        made_control = self.bzrdir_format.initialize(t.base)
1048
        made_repo = made_control.create_repository(shared=False)
1049
        self.assertFalse(made_repo.is_shared())
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1050
        
1051
    def test_open_repository(self):
1052
        if not self.bzrdir_format.is_supported():
1053
            # unsupported formats are not loopback testable
1054
            # because the default open will not open them and
1055
            # they may not be initializable.
1056
            return
1057
        t = get_transport(self.get_url())
1058
        made_control = self.bzrdir_format.initialize(t.base)
1059
        made_repo = made_control.create_repository()
1060
        opened_repo = made_control.open_repository()
1061
        self.assertEqual(made_control, opened_repo.bzrdir)
1062
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1063
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1064
1065
    def test_create_workingtree(self):
1066
        # a bzrdir can construct a working tree for itself.
1067
        if not self.bzrdir_format.is_supported():
1068
            # unsupported formats are not loopback testable
1069
            # because the default open will not open them and
1070
            # they may not be initializable.
1071
            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.
1072
        t = self.get_transport()
1910.5.9 by Andrew Bennetts
Move stuff out of a try block that doesn't need to be there.
1073
        made_control = self.bzrdir_format.initialize(t.base)
1074
        made_repo = made_control.create_repository()
1075
        made_branch = made_control.create_branch()
1910.5.11 by Andrew Bennetts
Use createWorkingTreeOrSkip helper in test_create_workingtree.
1076
        made_tree = self.createWorkingTreeOrSkip(made_control)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1077
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1078
        self.assertEqual(made_control, made_tree.bzrdir)
1079
        
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1080
    def test_create_workingtree_revision(self):
1081
        # 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.
1082
        t = self.get_transport()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1083
        source = self.make_branch_and_tree('source')
1084
        source.commit('a', rev_id='a', allow_pointless=True)
1085
        source.commit('b', rev_id='b', allow_pointless=True)
1086
        self.build_tree(['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.
1087
        t_new = t.clone('new')
1088
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1089
        source.branch.repository.clone(made_control)
1090
        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.
1091
        try:
1092
            made_tree = made_control.create_workingtree(revision_id='a')
1093
        except errors.NotLocalUrl:
1094
            raise TestSkipped("Can't make working tree on transport %r" % t)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1095
        self.assertEqual(['a'], made_tree.get_parent_ids())
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1096
        
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1097
    def test_open_workingtree(self):
1098
        if not self.bzrdir_format.is_supported():
1099
            # unsupported formats are not loopback testable
1100
            # because the default open will not open them and
1101
            # they may not be initializable.
1102
            return
1103
        # this has to be tested with local access as we still support creating 
1104
        # format 6 bzrdirs
1105
        t = get_transport('.')
1106
        made_control = self.bzrdir_format.initialize(t.base)
1107
        made_repo = made_control.create_repository()
1108
        made_branch = made_control.create_branch()
1109
        made_tree = made_control.create_workingtree()
1110
        opened_tree = made_control.open_workingtree()
1111
        self.assertEqual(made_control, opened_tree.bzrdir)
1112
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1113
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1114
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1115
    def test_get_branch_transport(self):
1116
        dir = self.make_bzrdir('.')
1117
        # without a format, get_branch_transport gives use a transport
1118
        # which -may- point to an existing dir.
1119
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1120
                                   transport.Transport))
1121
        # with a given format, either the bzr dir supports identifiable
1122
        # branches, or it supports anonymous  branch formats, but not both.
1508.1.25 by Robert Collins
Update per review comments.
1123
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1124
        identifiable_format = bzrlib.branch.BzrBranchFormat5()
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1125
        try:
1126
            found_transport = dir.get_branch_transport(anonymous_format)
1127
            self.assertRaises(errors.IncompatibleFormat,
1128
                              dir.get_branch_transport,
1129
                              identifiable_format)
1130
        except errors.IncompatibleFormat:
1131
            found_transport = dir.get_branch_transport(identifiable_format)
1132
        self.assertTrue(isinstance(found_transport, transport.Transport))
1910.4.1 by Andrew Bennetts
Clearer comment and more precise test for directory existence in test_get_branch_transport.
1133
        # and the dir which has been initialized for us must exist.
1134
        found_transport.list_dir('.')
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1135
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1136
    def test_get_repository_transport(self):
1137
        dir = self.make_bzrdir('.')
1138
        # without a format, get_repository_transport gives use a transport
1139
        # which -may- point to an existing dir.
1140
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1141
                                   transport.Transport))
1142
        # with a given format, either the bzr dir supports identifiable
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
1143
        # repositories, or it supports anonymous  repository formats, but not both.
1144
        anonymous_format = weaverepo.RepositoryFormat6()
1145
        identifiable_format = weaverepo.RepositoryFormat7()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1146
        try:
1147
            found_transport = dir.get_repository_transport(anonymous_format)
1148
            self.assertRaises(errors.IncompatibleFormat,
1149
                              dir.get_repository_transport,
1150
                              identifiable_format)
1151
        except errors.IncompatibleFormat:
1152
            found_transport = dir.get_repository_transport(identifiable_format)
1153
        self.assertTrue(isinstance(found_transport, transport.Transport))
1910.4.2 by Andrew Bennetts
Clearer comment and more precise test for directory existence in test_get_*_transport.
1154
        # and the dir which has been initialized for us must exist.
1155
        found_transport.list_dir('.')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1156
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1157
    def test_get_workingtree_transport(self):
1158
        dir = self.make_bzrdir('.')
1159
        # without a format, get_workingtree_transport gives use a transport
1160
        # which -may- point to an existing dir.
1161
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1162
                                   transport.Transport))
1163
        # with a given format, either the bzr dir supports identifiable
1164
        # trees, or it supports anonymous tree formats, but not both.
1165
        anonymous_format = workingtree.WorkingTreeFormat2()
1166
        identifiable_format = workingtree.WorkingTreeFormat3()
1167
        try:
1168
            found_transport = dir.get_workingtree_transport(anonymous_format)
1169
            self.assertRaises(errors.IncompatibleFormat,
1170
                              dir.get_workingtree_transport,
1171
                              identifiable_format)
1172
        except errors.IncompatibleFormat:
1173
            found_transport = dir.get_workingtree_transport(identifiable_format)
1174
        self.assertTrue(isinstance(found_transport, transport.Transport))
1910.4.2 by Andrew Bennetts
Clearer comment and more precise test for directory existence in test_get_*_transport.
1175
        # and the dir which has been initialized for us must exist.
1176
        found_transport.list_dir('.')
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.
1177
1178
    def test_root_transport(self):
1179
        dir = self.make_bzrdir('.')
1180
        self.assertEqual(dir.root_transport.base,
1181
                         get_transport(self.get_url('.')).base)
1182
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.
1183
    def test_find_repository_no_repo_under_standalone_branch(self):
1184
        # finding a repo stops at standalone branches even if there is a
1185
        # higher repository available.
1186
        try:
1187
            repo = self.make_repository('.', shared=True)
1188
        except errors.IncompatibleFormat:
1189
            # need a shared repository to test this.
1190
            return
1191
        url = self.get_url('intermediate')
1192
        get_transport(self.get_url()).mkdir('intermediate')
1193
        get_transport(self.get_url()).mkdir('intermediate/child')
1194
        made_control = self.bzrdir_format.initialize(url)
1195
        made_control.create_repository()
1196
        innermost_control = self.bzrdir_format.initialize(
1197
            self.get_url('intermediate/child'))
1198
        try:
1199
            child_repo = innermost_control.open_repository()
1200
            # if there is a repository, then the format cannot ever hit this 
1201
            # code path.
1202
            return
1203
        except errors.NoRepositoryPresent:
1204
            pass
1205
        self.assertRaises(errors.NoRepositoryPresent,
1206
                          innermost_control.find_repository)
1207
1208
    def test_find_repository_containing_shared_repository(self):
1209
        # find repo inside a shared repo with an empty control dir
1210
        # returns the shared repo.
1211
        try:
1212
            repo = self.make_repository('.', shared=True)
1213
        except errors.IncompatibleFormat:
1214
            # need a shared repository to test this.
1215
            return
1216
        url = self.get_url('childbzrdir')
1217
        get_transport(self.get_url()).mkdir('childbzrdir')
1218
        made_control = self.bzrdir_format.initialize(url)
1219
        try:
1220
            child_repo = made_control.open_repository()
1221
            # if there is a repository, then the format cannot ever hit this 
1222
            # code path.
1223
            return
1224
        except errors.NoRepositoryPresent:
1225
            pass
1226
        found_repo = made_control.find_repository()
1227
        self.assertEqual(repo.bzrdir.root_transport.base,
1228
                         found_repo.bzrdir.root_transport.base)
1229
        
1230
    def test_find_repository_standalone_with_containing_shared_repository(self):
1231
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1232
        try:
1233
            containing_repo = self.make_repository('.', shared=True)
1234
        except errors.IncompatibleFormat:
1235
            # need a shared repository to test this.
1236
            return
1237
        child_repo = self.make_repository('childrepo')
1238
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1239
        found_repo = opened_control.find_repository()
1240
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1241
                         found_repo.bzrdir.root_transport.base)
1242
1243
    def test_find_repository_shared_within_shared_repository(self):
1244
        # find repo at a shared repo inside a shared repo finds the inner repo
1245
        try:
1246
            containing_repo = self.make_repository('.', shared=True)
1247
        except errors.IncompatibleFormat:
1248
            # need a shared repository to test this.
1249
            return
1250
        url = self.get_url('childrepo')
1251
        get_transport(self.get_url()).mkdir('childrepo')
1252
        child_control = self.bzrdir_format.initialize(url)
1253
        child_repo = child_control.create_repository(shared=True)
1254
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1255
        found_repo = opened_control.find_repository()
1256
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1257
                         found_repo.bzrdir.root_transport.base)
1258
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1259
                            containing_repo.bzrdir.root_transport.base)
1260
1261
    def test_find_repository_with_nested_dirs_works(self):
1262
        # find repo inside a bzrdir inside a bzrdir inside a shared repo 
1263
        # finds the outer shared repo.
1264
        try:
1265
            repo = self.make_repository('.', shared=True)
1266
        except errors.IncompatibleFormat:
1267
            # need a shared repository to test this.
1268
            return
1269
        url = self.get_url('intermediate')
1270
        get_transport(self.get_url()).mkdir('intermediate')
1271
        get_transport(self.get_url()).mkdir('intermediate/child')
1272
        made_control = self.bzrdir_format.initialize(url)
1273
        try:
1274
            child_repo = made_control.open_repository()
1275
            # if there is a repository, then the format cannot ever hit this 
1276
            # code path.
1277
            return
1278
        except errors.NoRepositoryPresent:
1279
            pass
1280
        innermost_control = self.bzrdir_format.initialize(
1281
            self.get_url('intermediate/child'))
1282
        try:
1283
            child_repo = innermost_control.open_repository()
1284
            # if there is a repository, then the format cannot ever hit this 
1285
            # code path.
1286
            return
1287
        except errors.NoRepositoryPresent:
1288
            pass
1289
        found_repo = innermost_control.find_repository()
1290
        self.assertEqual(repo.bzrdir.root_transport.base,
1291
                         found_repo.bzrdir.root_transport.base)
1292
        
1534.5.16 by Robert Collins
Review feedback.
1293
    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.
1294
        # check that we can ask an instance if its upgradable
1295
        dir = self.make_bzrdir('.')
1534.5.16 by Robert Collins
Review feedback.
1296
        if dir.can_convert_format():
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.
1297
            # if its default updatable there must be an updater 
2204.4.14 by Aaron Bentley
lastest -> latest
1298
            # (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
1299
            # available
1300
            self.assertTrue(isinstance(dir._format.get_converter(
1301
                format=dir._format), bzrdir.Converter))
1534.5.16 by Robert Collins
Review feedback.
1302
        dir.needs_format_conversion(None)
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.
1303
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1304
    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.
1305
        """Does an available updater work?"""
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1306
        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.
1307
        # 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.
1308
        dir.create_repository()
1309
        dir.create_branch()
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1310
        self.createWorkingTreeOrSkip(dir)
1534.5.16 by Robert Collins
Review feedback.
1311
        if dir.can_convert_format():
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.
1312
            # if its default updatable there must be an updater 
2204.4.14 by Aaron Bentley
lastest -> latest
1313
            # (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
1314
            # available
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1315
            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.
1316
            try:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1317
                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.
1318
            finally:
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1319
                pb.finished()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1320
            # and it should pass 'check' now.
1321
            check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
1322
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1323
    def test_format_description(self):
1324
        dir = self.make_bzrdir('.')
1325
        text = dir._format.get_format_description()
1326
        self.failUnless(len(text))
1327
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.
1328
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1329
class TestBreakLock(TestCaseWithBzrDir):
1330
1331
    def setUp(self):
1332
        super(TestBreakLock, self).setUp()
1333
        # we want a UI factory that accepts canned input for the tests:
1334
        # while SilentUIFactory still accepts stdin, we need to customise
1335
        # ours
1336
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
1337
        self.addCleanup(self.restoreFactory)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1338
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1339
1687.1.15 by Robert Collins
Review comments.
1340
    def restoreFactory(self):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1341
        bzrlib.ui.ui_factory = self.old_factory
1342
1343
    def test_break_lock_empty(self):
1344
        # break lock on an empty bzrdir should work silently.
1345
        dir = self.make_bzrdir('.')
1346
        try:
1347
            dir.break_lock()
1348
        except NotImplementedError:
1349
            pass
1350
1351
    def test_break_lock_repository(self):
1352
        # break lock with just a repo should unlock the repo.
1353
        repo = self.make_repository('.')
1354
        repo.lock_write()
1355
        # only one yes needed here: it should only be unlocking
1356
        # the repo
1357
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1358
        try:
1359
            repo.bzrdir.break_lock()
1360
        except NotImplementedError:
1361
            # this bzrdir does not implement break_lock - so we cant test it.
1362
            repo.unlock()
1363
            return
1364
        lock_repo = repo.bzrdir.open_repository()
1365
        lock_repo.lock_write()
1366
        lock_repo.unlock()
1367
        self.assertRaises(errors.LockBroken, repo.unlock)
1368
1369
    def test_break_lock_branch(self):
1370
        # break lock with just a repo should unlock the branch.
1371
        # and not directly try the repository.
1372
        # we test this by making a branch reference to a branch
1373
        # and repository in another bzrdir
1374
        # for pre-metadir formats this will fail, thats ok.
1375
        master = self.make_branch('branch')
1376
        thisdir = self.make_bzrdir('this')
1377
        try:
1378
            bzrlib.branch.BranchReferenceFormat().initialize(
1379
                thisdir, master)
1380
        except errors.IncompatibleFormat:
1381
            return
1382
        unused_repo = thisdir.create_repository()
1383
        master.lock_write()
1384
        unused_repo.lock_write()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1385
        try:
1386
            # two yes's : branch and repository. If the repo in this
1387
            # dir is inappropriately accessed, 3 will be needed, and
1388
            # we'll see that because the stream will be fully consumed
1389
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1390
            master.bzrdir.break_lock()
1391
            # only two ys should have been read
1392
            self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1393
            # we should be able to lock a newly opened branch now
1394
            branch = master.bzrdir.open_branch()
1395
            branch.lock_write()
1396
            branch.unlock()
1397
            # we should not be able to lock the repository in thisdir as its still
1398
            # held by the explicit lock we took, and the break lock should not have
1399
            # touched it.
1400
            repo = thisdir.open_repository()
1401
            orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1402
            try:
1403
                lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1404
                self.assertRaises(errors.LockContention, repo.lock_write)
1405
            finally:
1406
                lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1407
        finally:
1408
            unused_repo.unlock()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1409
        self.assertRaises(errors.LockBroken, master.unlock)
1410
1411
    def test_break_lock_tree(self):
1412
        # break lock with a tree should unlock the tree but not try the 
1413
        # branch explicitly. However this is very hard to test for as we 
1414
        # dont have a tree reference class, nor is one needed; 
1415
        # the worst case if this code unlocks twice is an extra question
1416
        # being asked.
1417
        tree = self.make_branch_and_tree('.')
1418
        tree.lock_write()
1419
        # three yes's : tree, branch and repository.
1420
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1421
        try:
1422
            tree.bzrdir.break_lock()
1423
        except NotImplementedError:
1424
            # bzrdir does not support break_lock
1425
            tree.unlock()
1426
            return
1427
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1428
        lock_tree = tree.bzrdir.open_workingtree()
1429
        lock_tree.lock_write()
1430
        lock_tree.unlock()
1431
        self.assertRaises(errors.LockBroken, tree.unlock)
1432
1433
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.
1434
class ChrootedBzrDirTests(ChrootedTestCase):
1435
1436
    def test_find_repository_no_repository(self):
1437
        # loopback test to check the current format fails to find a 
1438
        # share repository correctly.
1439
        if not self.bzrdir_format.is_supported():
1440
            # unsupported formats are not loopback testable
1441
            # because the default open will not open them and
1442
            # they may not be initializable.
1443
            return
1444
        # supported formats must be able to init and open
1445
        url = self.get_url('subdir')
1446
        get_transport(self.get_url()).mkdir('subdir')
1447
        made_control = self.bzrdir_format.initialize(url)
1448
        try:
1449
            repo = made_control.open_repository()
1450
            # if there is a repository, then the format cannot ever hit this 
1451
            # code path.
1452
            return
1453
        except errors.NoRepositoryPresent:
1454
            pass
1455
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1456
        self.assertRaises(errors.NoRepositoryPresent,
1457
                          opened_control.find_repository)
1458