/brz/remove-bazaar

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