/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
    def test_clone_bzrdir_tree_branch_reference(self):
455
        # a tree with a branch reference (aka a checkout) 
456
        # should stay a checkout on clone.
457
        referenced_branch = self.make_branch('referencced')
458
        dir = self.make_bzrdir('source')
459
        try:
1508.1.25 by Robert Collins
Update per review comments.
460
            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.
461
                referenced_branch)
462
        except errors.IncompatibleFormat:
463
            # this is ok too, not all formats have to support references.
464
            return
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
465
        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.
466
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
467
        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.
468
        self.assertNotEqual(dir.transport.base, target.transport.base)
469
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
470
                                    ['./.bzr/stat-cache',
471
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
472
                                     './.bzr/checkout/merge-hashes',
473
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
474
                                     './.bzr/repository/inventory.knit',
475
                                     ])
476
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.
477
    def test_clone_bzrdir_tree_revision(self):
478
        # test for revision limiting, [smoke test, not corner case checks].
479
        # make a tree with a revision with a last-revision
480
        # and clone it with a revision limit.
481
        # This smoke test just checks the revision-id is right. Tree specific
482
        # tests will check corner cases.
483
        tree = self.make_branch_and_tree('source')
484
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
485
        tree.add('foo')
486
        tree.commit('revision 1', rev_id='1')
487
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
488
        dir = tree.bzrdir
489
        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.
490
        self.skipIfNoWorkingTree(target)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
491
        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.
492
493
    def test_clone_bzrdir_incomplete_source_with_basis(self):
494
        # ensure that basis really does grab from the basis by having incomplete source
495
        tree = self.make_branch_and_tree('commit_tree')
496
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
497
        tree.add('foo')
498
        tree.commit('revision 1', rev_id='1')
499
        source = self.make_branch_and_tree('source')
500
        # this gives us an incomplete repository
501
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
502
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
503
        tree.bzrdir.open_branch().copy_content_into(source.branch)
504
        tree.copy_content_into(source)
505
        self.assertFalse(source.branch.repository.has_revision('2'))
506
        dir = source.bzrdir
507
        target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
508
        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.
509
        try:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
510
            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.
511
        except errors.NoWorkingTree:
512
            # It should have a working tree if it's able to have one, so if
513
            # we're here make sure it really can't have one.
514
            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.
515
        self.assertTrue(target.open_branch().repository.has_revision('2'))
516
517
    def test_sprout_bzrdir_empty(self):
518
        dir = self.make_bzrdir('source')
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
519
        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.
520
        self.assertNotEqual(dir.transport.base, target.transport.base)
521
        # creates a new repository branch and tree
522
        target.open_repository()
523
        target.open_branch()
524
        target.open_workingtree()
1534.6.9 by Robert Collins
sprouting into shared repositories
525
526
    def test_sprout_bzrdir_empty_under_shared_repo(self):
527
        # sprouting an empty dir into a repo uses the repo
528
        dir = self.make_bzrdir('source')
529
        try:
530
            self.make_repository('target', shared=True)
531
        except errors.IncompatibleFormat:
532
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
533
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
534
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
535
        target.open_branch()
536
        target.open_workingtree()
537
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.
538
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
539
        # the force_new_repo parameter should force use of a new repo in an empty
540
        # bzrdir's sprout logic
541
        dir = self.make_bzrdir('source')
542
        try:
543
            self.make_repository('target', shared=True)
544
        except errors.IncompatibleFormat:
545
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
546
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
547
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
548
        target.open_repository()
549
        target.open_branch()
550
        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.
551
    
552
    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.
553
        tree = self.make_branch_and_tree('commit_tree')
554
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
555
        tree.add('foo')
556
        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.
557
        dir = self.make_bzrdir('source')
558
        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.
559
        repo.fetch(tree.branch.repository)
560
        self.assertTrue(repo.has_revision('1'))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
561
        try:
562
            self.assertIs(dir.open_branch().last_revision(), None)
563
        except errors.NotBranchError:
564
            pass
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
565
        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.
566
        self.assertNotEqual(dir.transport.base, target.transport.base)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
567
        # testing inventory isn't reasonable for repositories
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
568
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
569
                                    [
570
                                     './.bzr/branch',
571
                                     './.bzr/checkout',
572
                                     './.bzr/inventory',
573
                                     './.bzr/parent',
574
                                     './.bzr/repository/inventory.knit',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
575
                                     ])
1731.1.33 by Aaron Bentley
Revert no-special-root changes
576
        try:
577
            # If we happen to have a tree, we'll guarantee everything
578
            # except for the tree root is the same.
579
            inventory_f = file(dir.transport.base+'inventory', 'rb')
580
            self.assertContainsRe(inventory_f.read(), 
581
                                  '<inventory file_id="TREE_ROOT[^"]*"'
582
                                  ' format="5">\n</inventory>\n')
583
            inventory_f.close()
584
        except IOError, e:
585
            if e.errno != errno.ENOENT:
586
                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.
587
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
588
    def test_sprout_bzrdir_with_repository_to_shared(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
589
        tree = self.make_branch_and_tree('commit_tree')
590
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
591
        tree.add('foo')
592
        tree.commit('revision 1', rev_id='1')
593
        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.
594
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
595
        tree.commit('revision 2', rev_id='2')
596
        source = self.make_repository('source')
597
        tree.bzrdir.open_repository().copy_content_into(source)
598
        dir = source.bzrdir
599
        try:
600
            shared_repo = self.make_repository('target', shared=True)
601
        except errors.IncompatibleFormat:
602
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
603
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
604
        self.assertNotEqual(dir.transport.base, target.transport.base)
605
        self.assertTrue(shared_repo.has_revision('1'))
606
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
607
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
608
        try:
609
            shared_repo = self.make_repository('shared', shared=True)
610
        except errors.IncompatibleFormat:
611
            return
612
        tree = self.make_branch_and_tree('commit_tree')
613
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
614
        tree.add('foo')
615
        tree.commit('revision 1', rev_id='1')
616
        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.
617
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
618
        tree.commit('revision 2', rev_id='2')
619
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
620
        dir = self.make_bzrdir('shared/source')
621
        dir.create_branch()
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
622
        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.
623
        self.assertNotEqual(dir.transport.base, target.transport.base)
624
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
625
        self.assertTrue(shared_repo.has_revision('1'))
626
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
627
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
628
        try:
629
            shared_repo = self.make_repository('shared', shared=True)
630
        except errors.IncompatibleFormat:
631
            return
632
        tree = self.make_branch_and_tree('commit_tree')
633
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
634
        tree.add('foo')
635
        tree.commit('revision 1', rev_id='1')
636
        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.
637
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
638
        tree.commit('revision 2', rev_id='2')
639
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
640
        shared_repo.set_make_working_trees(False)
641
        self.assertFalse(shared_repo.make_working_trees())
642
        self.assertTrue(shared_repo.has_revision('1'))
643
        dir = self.make_bzrdir('shared/source')
644
        dir.create_branch()
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
645
        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
646
        self.assertNotEqual(dir.transport.base, target.transport.base)
647
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
648
        branch = target.open_branch()
649
        self.assertTrue(branch.repository.has_revision('1'))
650
        self.assertTrue(branch.repository.make_working_trees())
651
        self.assertFalse(branch.repository.is_shared())
652
1534.6.9 by Robert Collins
sprouting into shared repositories
653
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
654
        tree = self.make_branch_and_tree('commit_tree')
655
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
656
        tree.add('foo')
657
        tree.commit('revision 1', rev_id='1')
658
        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.
659
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
660
        tree.commit('revision 2', rev_id='2')
661
        source = self.make_repository('source')
662
        tree.bzrdir.open_repository().copy_content_into(source)
663
        dir = source.bzrdir
664
        try:
665
            shared_repo = self.make_repository('target', shared=True)
666
        except errors.IncompatibleFormat:
667
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
668
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
669
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
670
        self.assertNotEqual(dir.transport.base, target.transport.base)
671
        self.assertFalse(shared_repo.has_revision('1'))
672
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.
673
    def test_sprout_bzrdir_repository_revision(self):
674
        # test for revision limiting, [smoke test, not corner case checks].
675
        # make a repository with some revisions,
676
        # and sprout it with a revision limit.
677
        # 
678
        tree = self.make_branch_and_tree('commit_tree')
679
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
680
        tree.add('foo')
681
        tree.commit('revision 1', rev_id='1')
682
        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.
683
        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.
684
        tree.commit('revision 2', rev_id='2')
685
        source = self.make_repository('source')
686
        tree.bzrdir.open_repository().copy_content_into(source)
687
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
688
        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.
689
        raise TestSkipped('revision limiting not strict yet')
690
691
    def test_sprout_bzrdir_branch_and_repo(self):
692
        tree = self.make_branch_and_tree('commit_tree')
693
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
694
        tree.add('foo')
695
        tree.commit('revision 1')
696
        source = self.make_branch('source')
697
        tree.bzrdir.open_repository().copy_content_into(source.repository)
698
        tree.bzrdir.open_branch().copy_content_into(source)
699
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
700
        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.
701
        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.
702
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
703
                                    [
704
                                     './.bzr/basis-inventory-cache',
705
                                     './.bzr/branch/branch.conf',
706
                                     './.bzr/branch/parent',
707
                                     './.bzr/checkout',
708
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
709
                                     './.bzr/checkout/stat-cache',
710
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
711
                                     './.bzr/parent',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
712
                                     './.bzr/repository/inventory.knit',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
713
                                     './.bzr/stat-cache',
714
                                     './foo',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
715
                                     ])
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.
716
1534.6.9 by Robert Collins
sprouting into shared repositories
717
    def test_sprout_bzrdir_branch_and_repo_shared(self):
718
        # sprouting a branch with a repo into a shared repo uses the shared
719
        # repo
720
        tree = self.make_branch_and_tree('commit_tree')
721
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
722
        tree.add('foo')
723
        tree.commit('revision 1', rev_id='1')
724
        source = self.make_branch('source')
725
        tree.bzrdir.open_repository().copy_content_into(source.repository)
726
        tree.bzrdir.open_branch().copy_content_into(source)
727
        dir = source.bzrdir
728
        try:
729
            shared_repo = self.make_repository('target', shared=True)
730
        except errors.IncompatibleFormat:
731
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
732
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
733
        self.assertTrue(shared_repo.has_revision('1'))
734
735
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
736
        # sprouting a branch with a repo into a shared repo uses the shared
737
        # repo
738
        tree = self.make_branch_and_tree('commit_tree')
739
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
740
        tree.add('foo')
741
        tree.commit('revision 1', rev_id='1')
742
        source = self.make_branch('source')
743
        tree.bzrdir.open_repository().copy_content_into(source.repository)
744
        tree.bzrdir.open_branch().copy_content_into(source)
745
        dir = source.bzrdir
746
        try:
747
            shared_repo = self.make_repository('target', shared=True)
748
        except errors.IncompatibleFormat:
749
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
750
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
751
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
752
        self.assertNotEqual(dir.transport.base, target.transport.base)
753
        self.assertFalse(shared_repo.has_revision('1'))
754
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
755
    def test_sprout_bzrdir_branch_reference(self):
756
        # sprouting should create a repository if needed and a sprouted branch.
757
        referenced_branch = self.make_branch('referencced')
758
        dir = self.make_bzrdir('source')
759
        try:
1508.1.25 by Robert Collins
Update per review comments.
760
            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.
761
                referenced_branch)
762
        except errors.IncompatibleFormat:
763
            # this is ok too, not all formats have to support references.
764
            return
765
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
766
        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.
767
        self.assertNotEqual(dir.transport.base, target.transport.base)
768
        # we want target to have a branch that is in-place.
769
        self.assertEqual(target, target.open_branch().bzrdir)
770
        # and as we dont support repositories being detached yet, a repo in 
771
        # place
772
        target.open_repository()
773
1534.6.9 by Robert Collins
sprouting into shared repositories
774
    def test_sprout_bzrdir_branch_reference_shared(self):
775
        # sprouting should create a repository if needed and a sprouted branch.
776
        referenced_tree = self.make_branch_and_tree('referenced')
777
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
778
        dir = self.make_bzrdir('source')
779
        try:
780
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
781
                referenced_tree.branch)
782
        except errors.IncompatibleFormat:
783
            # this is ok too, not all formats have to support references.
784
            return
785
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
786
        try:
787
            shared_repo = self.make_repository('target', shared=True)
788
        except errors.IncompatibleFormat:
789
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
790
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
791
        self.assertNotEqual(dir.transport.base, target.transport.base)
792
        # we want target to have a branch that is in-place.
793
        self.assertEqual(target, target.open_branch().bzrdir)
794
        # and we want no repository as the target is shared
795
        self.assertRaises(errors.NoRepositoryPresent, 
796
                          target.open_repository)
797
        # and we want revision '1' in the shared repo
798
        self.assertTrue(shared_repo.has_revision('1'))
799
800
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
801
        # sprouting should create a repository if needed and a sprouted branch.
802
        referenced_tree = self.make_branch_and_tree('referenced')
803
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
804
        dir = self.make_bzrdir('source')
805
        try:
806
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
807
                referenced_tree.branch)
808
        except errors.IncompatibleFormat:
809
            # this is ok too, not all formats have to support references.
810
            return
811
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
812
        try:
813
            shared_repo = self.make_repository('target', shared=True)
814
        except errors.IncompatibleFormat:
815
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
816
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
817
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
818
        self.assertNotEqual(dir.transport.base, target.transport.base)
819
        # we want target to have a branch that is in-place.
820
        self.assertEqual(target, target.open_branch().bzrdir)
821
        # and we want revision '1' in the new repo
822
        self.assertTrue(target.open_repository().has_revision('1'))
823
        # but not the shared one
824
        self.assertFalse(shared_repo.has_revision('1'))
825
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.
826
    def test_sprout_bzrdir_branch_revision(self):
827
        # test for revision limiting, [smoke test, not corner case checks].
828
        # make a repository with some revisions,
829
        # and sprout it with a revision limit.
830
        # 
831
        tree = self.make_branch_and_tree('commit_tree')
832
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
833
        tree.add('foo')
834
        tree.commit('revision 1', rev_id='1')
835
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
836
        source = self.make_branch('source')
837
        tree.bzrdir.open_repository().copy_content_into(source.repository)
838
        tree.bzrdir.open_branch().copy_content_into(source)
839
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
840
        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.
841
        self.assertEqual('1', target.open_branch().last_revision())
842
        
843
    def test_sprout_bzrdir_tree_branch_repo(self):
844
        tree = self.make_branch_and_tree('sourcce')
845
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
846
        tree.add('foo')
847
        tree.commit('revision 1')
848
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
849
        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.
850
        self.assertNotEqual(dir.transport.base, target.transport.base)
851
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
852
                                    [
853
                                     './.bzr/branch/branch.conf',
854
                                     './.bzr/branch/parent',
2255.10.9 by John Arbash Meinel
one more test that needs to ignore dirstate
855
                                     './.bzr/checkout/dirstate',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
856
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
857
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
858
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
859
                                     './.bzr/parent',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
860
                                     './.bzr/repository/inventory.knit',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
861
                                     './.bzr/stat-cache',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
862
                                     ])
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.
863
864
    def test_sprout_bzrdir_tree_branch_reference(self):
865
        # 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.
866
        # 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.
867
        referenced_branch = self.make_branch('referencced')
868
        dir = self.make_bzrdir('source')
869
        try:
1508.1.25 by Robert Collins
Update per review comments.
870
            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.
871
                referenced_branch)
872
        except errors.IncompatibleFormat:
873
            # this is ok too, not all formats have to support references.
874
            return
875
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
876
        tree = self.createWorkingTreeOrSkip(dir)
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
877
        tree.bzrdir.root_transport.mkdir('subdir')
878
        tree.add('subdir')
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
879
        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.
880
        self.assertNotEqual(dir.transport.base, target.transport.base)
881
        # we want target to have a branch that is in-place.
882
        self.assertEqual(target, target.open_branch().bzrdir)
883
        # and as we dont support repositories being detached yet, a repo in 
884
        # place
885
        target.open_repository()
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
886
        result_tree = target.open_workingtree()
887
        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.
888
889
    def test_sprout_bzrdir_tree_branch_reference_revision(self):
890
        # 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.
891
        # 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.
892
        # and the likewise the new branch should be truncated too
893
        referenced_branch = self.make_branch('referencced')
894
        dir = self.make_bzrdir('source')
895
        try:
1508.1.25 by Robert Collins
Update per review comments.
896
            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.
897
                referenced_branch)
898
        except errors.IncompatibleFormat:
899
            # this is ok too, not all formats have to support references.
900
            return
901
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
902
        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.
903
        self.build_tree(['foo'], transport=dir.root_transport)
904
        tree.add('foo')
905
        tree.commit('revision 1', rev_id='1')
906
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
907
        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.
908
        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.
909
        self.assertNotEqual(dir.transport.base, target.transport.base)
910
        # we want target to have a branch that is in-place.
911
        self.assertEqual(target, target.open_branch().bzrdir)
912
        # and as we dont support repositories being detached yet, a repo in 
913
        # place
914
        target.open_repository()
915
        # we trust that the working tree sprouting works via the other tests.
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
916
        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.
917
        self.assertEqual('1', target.open_branch().last_revision())
918
919
    def test_sprout_bzrdir_tree_revision(self):
920
        # test for revision limiting, [smoke test, not corner case checks].
921
        # make a tree with a revision with a last-revision
922
        # and sprout it with a revision limit.
923
        # This smoke test just checks the revision-id is right. Tree specific
924
        # tests will check corner cases.
925
        tree = self.make_branch_and_tree('source')
926
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
927
        tree.add('foo')
928
        tree.commit('revision 1', rev_id='1')
929
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
930
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
931
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
932
        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.
933
934
    def test_sprout_bzrdir_incomplete_source_with_basis(self):
935
        # ensure that basis really does grab from the basis by having incomplete source
936
        tree = self.make_branch_and_tree('commit_tree')
937
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
938
        tree.add('foo')
939
        tree.commit('revision 1', rev_id='1')
940
        source = self.make_branch_and_tree('source')
941
        # this gives us an incomplete repository
942
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
943
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
944
        tree.bzrdir.open_branch().copy_content_into(source.branch)
945
        tree.copy_content_into(source)
946
        self.assertFalse(source.branch.repository.has_revision('2'))
947
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
948
        target = self.sproutOrSkip(dir, self.get_url('target'),
949
                                   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.
950
        self.assertEqual('2', target.open_branch().last_revision())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
951
        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.
952
        self.assertTrue(target.open_branch().repository.has_revision('2'))
1534.4.39 by Robert Collins
Basic BzrDir support.
953
954
    def test_format_initialize_find_open(self):
955
        # loopback test to check the current format initializes to itself.
956
        if not self.bzrdir_format.is_supported():
957
            # unsupported formats are not loopback testable
958
            # because the default open will not open them and
959
            # they may not be initializable.
960
            return
961
        # supported formats must be able to init and open
962
        t = get_transport(self.get_url())
963
        readonly_t = get_transport(self.get_readonly_url())
964
        made_control = self.bzrdir_format.initialize(t.base)
965
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
966
        self.assertEqual(self.bzrdir_format,
967
                         bzrdir.BzrDirFormat.find_format(readonly_t))
968
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
969
        opened_dir = bzrdir.BzrDir.open(t.base)
970
        self.assertEqual(made_control._format,
971
                         opened_dir._format)
972
        self.assertEqual(direct_opened_dir._format,
973
                         opened_dir._format)
974
        self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
975
976
    def test_open_not_bzrdir(self):
977
        # test the formats specific behaviour for no-content or similar dirs.
978
        self.assertRaises(NotBranchError,
979
                          self.bzrdir_format.open,
980
                          get_transport(self.get_readonly_url()))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
981
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
982
    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.
983
        # a bzrdir can construct a branch and repository for itself.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
984
        if not self.bzrdir_format.is_supported():
985
            # unsupported formats are not loopback testable
986
            # because the default open will not open them and
987
            # they may not be initializable.
988
            return
989
        t = get_transport(self.get_url())
990
        made_control = self.bzrdir_format.initialize(t.base)
991
        made_repo = made_control.create_repository()
992
        made_branch = made_control.create_branch()
1508.1.25 by Robert Collins
Update per review comments.
993
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
994
        self.assertEqual(made_control, made_branch.bzrdir)
995
        
996
    def test_open_branch(self):
997
        if not self.bzrdir_format.is_supported():
998
            # unsupported formats are not loopback testable
999
            # because the default open will not open them and
1000
            # they may not be initializable.
1001
            return
1002
        t = get_transport(self.get_url())
1003
        made_control = self.bzrdir_format.initialize(t.base)
1004
        made_repo = made_control.create_repository()
1005
        made_branch = made_control.create_branch()
1006
        opened_branch = made_control.open_branch()
1007
        self.assertEqual(made_control, opened_branch.bzrdir)
1008
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1009
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1010
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1011
    def test_create_repository(self):
1012
        # a bzrdir can construct a repository for itself.
1013
        if not self.bzrdir_format.is_supported():
1014
            # unsupported formats are not loopback testable
1015
            # because the default open will not open them and
1016
            # they may not be initializable.
1017
            return
1018
        t = get_transport(self.get_url())
1019
        made_control = self.bzrdir_format.initialize(t.base)
1020
        made_repo = made_control.create_repository()
1021
        self.failUnless(isinstance(made_repo, repository.Repository))
1022
        self.assertEqual(made_control, made_repo.bzrdir)
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1023
1024
    def test_create_repository_shared(self):
1025
        # a bzrdir can create a shared repository or 
1026
        # fail appropriately
1027
        if not self.bzrdir_format.is_supported():
1028
            # unsupported formats are not loopback testable
1029
            # because the default open will not open them and
1030
            # they may not be initializable.
1031
            return
1032
        t = get_transport(self.get_url())
1033
        made_control = self.bzrdir_format.initialize(t.base)
1034
        try:
1035
            made_repo = made_control.create_repository(shared=True)
1036
        except errors.IncompatibleFormat:
1037
            # Old bzrdir formats don't support shared repositories
1038
            # and should raise IncompatibleFormat
1039
            return
1040
        self.assertTrue(made_repo.is_shared())
1041
1042
    def test_create_repository_nonshared(self):
1043
        # a bzrdir can create a non-shared repository 
1044
        if not self.bzrdir_format.is_supported():
1045
            # unsupported formats are not loopback testable
1046
            # because the default open will not open them and
1047
            # they may not be initializable.
1048
            return
1049
        t = get_transport(self.get_url())
1050
        made_control = self.bzrdir_format.initialize(t.base)
1051
        made_repo = made_control.create_repository(shared=False)
1052
        self.assertFalse(made_repo.is_shared())
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1053
        
1054
    def test_open_repository(self):
1055
        if not self.bzrdir_format.is_supported():
1056
            # unsupported formats are not loopback testable
1057
            # because the default open will not open them and
1058
            # they may not be initializable.
1059
            return
1060
        t = get_transport(self.get_url())
1061
        made_control = self.bzrdir_format.initialize(t.base)
1062
        made_repo = made_control.create_repository()
1063
        opened_repo = made_control.open_repository()
1064
        self.assertEqual(made_control, opened_repo.bzrdir)
1065
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1066
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1067
1068
    def test_create_workingtree(self):
1069
        # a bzrdir can construct a working tree for itself.
1070
        if not self.bzrdir_format.is_supported():
1071
            # unsupported formats are not loopback testable
1072
            # because the default open will not open them and
1073
            # they may not be initializable.
1074
            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.
1075
        t = self.get_transport()
1910.5.9 by Andrew Bennetts
Move stuff out of a try block that doesn't need to be there.
1076
        made_control = self.bzrdir_format.initialize(t.base)
1077
        made_repo = made_control.create_repository()
1078
        made_branch = made_control.create_branch()
1910.5.11 by Andrew Bennetts
Use createWorkingTreeOrSkip helper in test_create_workingtree.
1079
        made_tree = self.createWorkingTreeOrSkip(made_control)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1080
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1081
        self.assertEqual(made_control, made_tree.bzrdir)
1082
        
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1083
    def test_create_workingtree_revision(self):
1084
        # 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.
1085
        t = self.get_transport()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1086
        source = self.make_branch_and_tree('source')
1087
        source.commit('a', rev_id='a', allow_pointless=True)
1088
        source.commit('b', rev_id='b', allow_pointless=True)
1089
        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.
1090
        t_new = t.clone('new')
1091
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1092
        source.branch.repository.clone(made_control)
1093
        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.
1094
        try:
1095
            made_tree = made_control.create_workingtree(revision_id='a')
1096
        except errors.NotLocalUrl:
1097
            raise TestSkipped("Can't make working tree on transport %r" % t)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1098
        self.assertEqual(['a'], made_tree.get_parent_ids())
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1099
        
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1100
    def test_open_workingtree(self):
1101
        if not self.bzrdir_format.is_supported():
1102
            # unsupported formats are not loopback testable
1103
            # because the default open will not open them and
1104
            # they may not be initializable.
1105
            return
1106
        # this has to be tested with local access as we still support creating 
1107
        # format 6 bzrdirs
1108
        t = get_transport('.')
1109
        made_control = self.bzrdir_format.initialize(t.base)
1110
        made_repo = made_control.create_repository()
1111
        made_branch = made_control.create_branch()
1112
        made_tree = made_control.create_workingtree()
1113
        opened_tree = made_control.open_workingtree()
1114
        self.assertEqual(made_control, opened_tree.bzrdir)
1115
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1116
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1117
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1118
    def test_get_branch_transport(self):
1119
        dir = self.make_bzrdir('.')
1120
        # without a format, get_branch_transport gives use a transport
1121
        # which -may- point to an existing dir.
1122
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1123
                                   transport.Transport))
1124
        # with a given format, either the bzr dir supports identifiable
1125
        # branches, or it supports anonymous  branch formats, but not both.
1508.1.25 by Robert Collins
Update per review comments.
1126
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1127
        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.
1128
        try:
1129
            found_transport = dir.get_branch_transport(anonymous_format)
1130
            self.assertRaises(errors.IncompatibleFormat,
1131
                              dir.get_branch_transport,
1132
                              identifiable_format)
1133
        except errors.IncompatibleFormat:
1134
            found_transport = dir.get_branch_transport(identifiable_format)
1135
        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.
1136
        # and the dir which has been initialized for us must exist.
1137
        found_transport.list_dir('.')
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1138
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1139
    def test_get_repository_transport(self):
1140
        dir = self.make_bzrdir('.')
1141
        # without a format, get_repository_transport gives use a transport
1142
        # which -may- point to an existing dir.
1143
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1144
                                   transport.Transport))
1145
        # 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.
1146
        # repositories, or it supports anonymous  repository formats, but not both.
1147
        anonymous_format = weaverepo.RepositoryFormat6()
1148
        identifiable_format = weaverepo.RepositoryFormat7()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1149
        try:
1150
            found_transport = dir.get_repository_transport(anonymous_format)
1151
            self.assertRaises(errors.IncompatibleFormat,
1152
                              dir.get_repository_transport,
1153
                              identifiable_format)
1154
        except errors.IncompatibleFormat:
1155
            found_transport = dir.get_repository_transport(identifiable_format)
1156
        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.
1157
        # and the dir which has been initialized for us must exist.
1158
        found_transport.list_dir('.')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1159
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1160
    def test_get_workingtree_transport(self):
1161
        dir = self.make_bzrdir('.')
1162
        # without a format, get_workingtree_transport gives use a transport
1163
        # which -may- point to an existing dir.
1164
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1165
                                   transport.Transport))
1166
        # with a given format, either the bzr dir supports identifiable
1167
        # trees, or it supports anonymous tree formats, but not both.
1168
        anonymous_format = workingtree.WorkingTreeFormat2()
1169
        identifiable_format = workingtree.WorkingTreeFormat3()
1170
        try:
1171
            found_transport = dir.get_workingtree_transport(anonymous_format)
1172
            self.assertRaises(errors.IncompatibleFormat,
1173
                              dir.get_workingtree_transport,
1174
                              identifiable_format)
1175
        except errors.IncompatibleFormat:
1176
            found_transport = dir.get_workingtree_transport(identifiable_format)
1177
        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.
1178
        # and the dir which has been initialized for us must exist.
1179
        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.
1180
1181
    def test_root_transport(self):
1182
        dir = self.make_bzrdir('.')
1183
        self.assertEqual(dir.root_transport.base,
1184
                         get_transport(self.get_url('.')).base)
1185
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.
1186
    def test_find_repository_no_repo_under_standalone_branch(self):
1187
        # finding a repo stops at standalone branches even if there is a
1188
        # higher repository available.
1189
        try:
1190
            repo = self.make_repository('.', shared=True)
1191
        except errors.IncompatibleFormat:
1192
            # need a shared repository to test this.
1193
            return
1194
        url = self.get_url('intermediate')
1195
        get_transport(self.get_url()).mkdir('intermediate')
1196
        get_transport(self.get_url()).mkdir('intermediate/child')
1197
        made_control = self.bzrdir_format.initialize(url)
1198
        made_control.create_repository()
1199
        innermost_control = self.bzrdir_format.initialize(
1200
            self.get_url('intermediate/child'))
1201
        try:
1202
            child_repo = innermost_control.open_repository()
1203
            # if there is a repository, then the format cannot ever hit this 
1204
            # code path.
1205
            return
1206
        except errors.NoRepositoryPresent:
1207
            pass
1208
        self.assertRaises(errors.NoRepositoryPresent,
1209
                          innermost_control.find_repository)
1210
1211
    def test_find_repository_containing_shared_repository(self):
1212
        # find repo inside a shared repo with an empty control dir
1213
        # returns the shared repo.
1214
        try:
1215
            repo = self.make_repository('.', shared=True)
1216
        except errors.IncompatibleFormat:
1217
            # need a shared repository to test this.
1218
            return
1219
        url = self.get_url('childbzrdir')
1220
        get_transport(self.get_url()).mkdir('childbzrdir')
1221
        made_control = self.bzrdir_format.initialize(url)
1222
        try:
1223
            child_repo = made_control.open_repository()
1224
            # if there is a repository, then the format cannot ever hit this 
1225
            # code path.
1226
            return
1227
        except errors.NoRepositoryPresent:
1228
            pass
1229
        found_repo = made_control.find_repository()
1230
        self.assertEqual(repo.bzrdir.root_transport.base,
1231
                         found_repo.bzrdir.root_transport.base)
1232
        
1233
    def test_find_repository_standalone_with_containing_shared_repository(self):
1234
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1235
        try:
1236
            containing_repo = self.make_repository('.', shared=True)
1237
        except errors.IncompatibleFormat:
1238
            # need a shared repository to test this.
1239
            return
1240
        child_repo = self.make_repository('childrepo')
1241
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1242
        found_repo = opened_control.find_repository()
1243
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1244
                         found_repo.bzrdir.root_transport.base)
1245
1246
    def test_find_repository_shared_within_shared_repository(self):
1247
        # find repo at a shared repo inside a shared repo finds the inner repo
1248
        try:
1249
            containing_repo = self.make_repository('.', shared=True)
1250
        except errors.IncompatibleFormat:
1251
            # need a shared repository to test this.
1252
            return
1253
        url = self.get_url('childrepo')
1254
        get_transport(self.get_url()).mkdir('childrepo')
1255
        child_control = self.bzrdir_format.initialize(url)
1256
        child_repo = child_control.create_repository(shared=True)
1257
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1258
        found_repo = opened_control.find_repository()
1259
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1260
                         found_repo.bzrdir.root_transport.base)
1261
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1262
                            containing_repo.bzrdir.root_transport.base)
1263
1264
    def test_find_repository_with_nested_dirs_works(self):
1265
        # find repo inside a bzrdir inside a bzrdir inside a shared repo 
1266
        # finds the outer shared repo.
1267
        try:
1268
            repo = self.make_repository('.', shared=True)
1269
        except errors.IncompatibleFormat:
1270
            # need a shared repository to test this.
1271
            return
1272
        url = self.get_url('intermediate')
1273
        get_transport(self.get_url()).mkdir('intermediate')
1274
        get_transport(self.get_url()).mkdir('intermediate/child')
1275
        made_control = self.bzrdir_format.initialize(url)
1276
        try:
1277
            child_repo = made_control.open_repository()
1278
            # if there is a repository, then the format cannot ever hit this 
1279
            # code path.
1280
            return
1281
        except errors.NoRepositoryPresent:
1282
            pass
1283
        innermost_control = self.bzrdir_format.initialize(
1284
            self.get_url('intermediate/child'))
1285
        try:
1286
            child_repo = innermost_control.open_repository()
1287
            # if there is a repository, then the format cannot ever hit this 
1288
            # code path.
1289
            return
1290
        except errors.NoRepositoryPresent:
1291
            pass
1292
        found_repo = innermost_control.find_repository()
1293
        self.assertEqual(repo.bzrdir.root_transport.base,
1294
                         found_repo.bzrdir.root_transport.base)
1295
        
1534.5.16 by Robert Collins
Review feedback.
1296
    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.
1297
        # check that we can ask an instance if its upgradable
1298
        dir = self.make_bzrdir('.')
1534.5.16 by Robert Collins
Review feedback.
1299
        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.
1300
            # if its default updatable there must be an updater 
2204.4.14 by Aaron Bentley
lastest -> latest
1301
            # (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
1302
            # available
1303
            self.assertTrue(isinstance(dir._format.get_converter(
1304
                format=dir._format), bzrdir.Converter))
1534.5.16 by Robert Collins
Review feedback.
1305
        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.
1306
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1307
    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.
1308
        """Does an available updater work?"""
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1309
        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.
1310
        # 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.
1311
        dir.create_repository()
1312
        dir.create_branch()
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1313
        self.createWorkingTreeOrSkip(dir)
1534.5.16 by Robert Collins
Review feedback.
1314
        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.
1315
            # if its default updatable there must be an updater 
2204.4.14 by Aaron Bentley
lastest -> latest
1316
            # (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
1317
            # available
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1318
            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.
1319
            try:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1320
                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.
1321
            finally:
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1322
                pb.finished()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1323
            # and it should pass 'check' now.
1324
            check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
1325
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1326
    def test_format_description(self):
1327
        dir = self.make_bzrdir('.')
1328
        text = dir._format.get_format_description()
1329
        self.failUnless(len(text))
1330
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1331
    def test_retire_bzrdir(self):
1332
        bd = self.make_bzrdir('.')
1333
        # must not overwrite existing directories
1334
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',])
1335
        self.failUnlessExists('.bzr')
1336
        bd.retire_bzrdir()
1337
        self.failIfExists('.bzr')
1338
        self.failUnlessExists('.bzr.retired.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.
1339
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1340
class TestBreakLock(TestCaseWithBzrDir):
1341
1342
    def setUp(self):
1343
        super(TestBreakLock, self).setUp()
1344
        # we want a UI factory that accepts canned input for the tests:
1345
        # while SilentUIFactory still accepts stdin, we need to customise
1346
        # ours
1347
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
1348
        self.addCleanup(self.restoreFactory)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1349
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1350
1687.1.15 by Robert Collins
Review comments.
1351
    def restoreFactory(self):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1352
        bzrlib.ui.ui_factory = self.old_factory
1353
1354
    def test_break_lock_empty(self):
1355
        # break lock on an empty bzrdir should work silently.
1356
        dir = self.make_bzrdir('.')
1357
        try:
1358
            dir.break_lock()
1359
        except NotImplementedError:
1360
            pass
1361
1362
    def test_break_lock_repository(self):
1363
        # break lock with just a repo should unlock the repo.
1364
        repo = self.make_repository('.')
1365
        repo.lock_write()
1366
        # only one yes needed here: it should only be unlocking
1367
        # the repo
1368
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1369
        try:
1370
            repo.bzrdir.break_lock()
1371
        except NotImplementedError:
1372
            # this bzrdir does not implement break_lock - so we cant test it.
1373
            repo.unlock()
1374
            return
1375
        lock_repo = repo.bzrdir.open_repository()
1376
        lock_repo.lock_write()
1377
        lock_repo.unlock()
1378
        self.assertRaises(errors.LockBroken, repo.unlock)
1379
1380
    def test_break_lock_branch(self):
1381
        # break lock with just a repo should unlock the branch.
1382
        # and not directly try the repository.
1383
        # we test this by making a branch reference to a branch
1384
        # and repository in another bzrdir
1385
        # for pre-metadir formats this will fail, thats ok.
1386
        master = self.make_branch('branch')
1387
        thisdir = self.make_bzrdir('this')
1388
        try:
1389
            bzrlib.branch.BranchReferenceFormat().initialize(
1390
                thisdir, master)
1391
        except errors.IncompatibleFormat:
1392
            return
1393
        unused_repo = thisdir.create_repository()
1394
        master.lock_write()
1395
        unused_repo.lock_write()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1396
        try:
1397
            # two yes's : branch and repository. If the repo in this
1398
            # dir is inappropriately accessed, 3 will be needed, and
1399
            # we'll see that because the stream will be fully consumed
1400
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1401
            master.bzrdir.break_lock()
1402
            # only two ys should have been read
1403
            self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1404
            # we should be able to lock a newly opened branch now
1405
            branch = master.bzrdir.open_branch()
1406
            branch.lock_write()
1407
            branch.unlock()
1408
            # we should not be able to lock the repository in thisdir as its still
1409
            # held by the explicit lock we took, and the break lock should not have
1410
            # touched it.
1411
            repo = thisdir.open_repository()
1412
            orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1413
            try:
1414
                lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1415
                self.assertRaises(errors.LockContention, repo.lock_write)
1416
            finally:
1417
                lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1418
        finally:
1419
            unused_repo.unlock()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1420
        self.assertRaises(errors.LockBroken, master.unlock)
1421
1422
    def test_break_lock_tree(self):
1423
        # break lock with a tree should unlock the tree but not try the 
1424
        # branch explicitly. However this is very hard to test for as we 
1425
        # dont have a tree reference class, nor is one needed; 
1426
        # the worst case if this code unlocks twice is an extra question
1427
        # being asked.
1428
        tree = self.make_branch_and_tree('.')
1429
        tree.lock_write()
1430
        # three yes's : tree, branch and repository.
1431
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1432
        try:
1433
            tree.bzrdir.break_lock()
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1434
        except (NotImplementedError, errors.LockActive):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1435
            # bzrdir does not support break_lock
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1436
            # or one of the locked objects (currently only tree does this)
1437
            # raised a LockActive because we do still have a live locked
1438
            # object.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1439
            tree.unlock()
1440
            return
1441
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1442
        lock_tree = tree.bzrdir.open_workingtree()
1443
        lock_tree.lock_write()
1444
        lock_tree.unlock()
1445
        self.assertRaises(errors.LockBroken, tree.unlock)
1446
1447
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.
1448
class ChrootedBzrDirTests(ChrootedTestCase):
1449
1450
    def test_find_repository_no_repository(self):
1451
        # loopback test to check the current format fails to find a 
1452
        # share repository correctly.
1453
        if not self.bzrdir_format.is_supported():
1454
            # unsupported formats are not loopback testable
1455
            # because the default open will not open them and
1456
            # they may not be initializable.
1457
            return
1458
        # supported formats must be able to init and open
1459
        url = self.get_url('subdir')
1460
        get_transport(self.get_url()).mkdir('subdir')
1461
        made_control = self.bzrdir_format.initialize(url)
1462
        try:
1463
            repo = made_control.open_repository()
1464
            # if there is a repository, then the format cannot ever hit this 
1465
            # code path.
1466
            return
1467
        except errors.NoRepositoryPresent:
1468
            pass
1469
        opened_control = bzrdir.BzrDir.open(self.get_readonly_url('subdir'))
1470
        self.assertRaises(errors.NoRepositoryPresent,
1471
                          opened_control.find_repository)
1472