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