/brz/remove-bazaar

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