/brz/remove-bazaar

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