/brz/remove-bazaar

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