/brz/remove-bazaar

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