~bzr-pqm/bzr/bzr.dev

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