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