/brz/remove-bazaar

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