/brz/remove-bazaar

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