/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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.39 by Robert Collins
Basic BzrDir support.
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
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
21
from itertools import izip
1534.4.39 by Robert Collins
Basic BzrDir support.
22
import os
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
23
from stat import S_ISDIR
1534.4.39 by Robert Collins
Basic BzrDir support.
24
import sys
25
1508.1.25 by Robert Collins
Update per review comments.
26
import bzrlib.branch
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
27
from bzrlib import (
28
    bzrdir,
4332.3.36 by Robert Collins
Silence a warning in test_bzrdir.
29
    check,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
30
    errors,
31
    lockdir,
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
32
    osutils,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
33
    repository,
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
34
    revision as _mod_revision,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
35
    transactions,
36
    transport,
37
    ui,
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
38
    urlutils,
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
39
    workingtree,
40
    )
1534.4.39 by Robert Collins
Basic BzrDir support.
41
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
42
from bzrlib.errors import (FileExists,
43
                           NoSuchRevision,
44
                           NoSuchFile,
45
                           UninitializableFormat,
46
                           NotBranchError,
47
                           )
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
48
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.
49
from bzrlib.tests import (
50
                          ChrootedTestCase,
51
                          TestCase,
52
                          TestCaseWithTransport,
2796.2.6 by Aaron Bentley
Implement destroy_branch
53
                          TestNotApplicable,
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
54
                          TestSkipped,
55
                          )
4523.1.2 by Martin Pool
Rename bzrdir_implementations to per_bzrdir
56
from bzrlib.tests.per_bzrdir import TestCaseWithBzrDir
1534.4.39 by Robert Collins
Basic BzrDir support.
57
from bzrlib.trace import mutter
58
from bzrlib.transport import get_transport
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
59
from bzrlib.transport.local import LocalTransport
4449.3.25 by Martin Pool
Move CannedInputUIFactory to bzrlib.ui for reuse
60
from bzrlib.ui import (
61
    CannedInputUIFactory,
62
    )
1534.4.39 by Robert Collins
Basic BzrDir support.
63
from bzrlib.upgrade import upgrade
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
64
from bzrlib.remote import RemoteBzrDir, RemoteRepository
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
65
from bzrlib.repofmt import weaverepo
1534.4.39 by Robert Collins
Basic BzrDir support.
66
67
68
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.
69
    # Many of these tests test for disk equality rather than checking
70
    # for semantic equivalence. This works well for some tests but
71
    # is not good at handling changes in representation or the addition
72
    # or removal of control data. It would be nice to for instance:
73
    # sprout a new branch, check that the nickname has been reset by hand
74
    # and then set the nickname to match the source branch, at which point
75
    # a semantic equivalence should pass
76
77
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
78
        """Assert that the content of source and target are identical.
79
80
        paths in ignore list will be completely ignored.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
81
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
82
        We ignore paths that represent data which is allowed to change during
83
        a clone or sprout: for instance, inventory.knit contains gzip fragements
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
84
        which have timestamps in them, and as we have read the inventory from
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
85
        the source knit, the already-read data is recompressed rather than
86
        reading it again, which leads to changed timestamps. This is ok though,
87
        because the inventory.kndx file is not ignored, and the integrity of
88
        knit joins is tested by test_knit and test_versionedfile.
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
89
90
        :seealso: Additionally, assertRepositoryHasSameItems provides value
91
            rather than representation checking of repositories for
92
            equivalence.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
93
        """
94
        files = []
95
        directories = ['.']
96
        while directories:
97
            dir = directories.pop()
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
98
            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.
99
                path = dir + '/' + path
100
                if path in ignore_list:
101
                    continue
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
102
                try:
103
                    stat = source.stat(path)
2230.3.30 by Aaron Bentley
Fix whitespace issues
104
                except errors.NoSuchFile:
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
105
                    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.
106
                if S_ISDIR(stat.st_mode):
107
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
108
                    directories.append(path)
109
                else:
110
                    self.assertEqualDiff(source.get(path).read(),
111
                                         target.get(path).read(),
112
                                         "text for file %r differs:\n" % path)
113
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
114
    def assertRepositoryHasSameItems(self, left_repo, right_repo):
3015.2.15 by Robert Collins
Review feedback.
115
        """require left_repo and right_repo to contain the same data."""
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
116
        # XXX: TODO: Doesn't work yet, because we need to be able to compare
117
        # local repositories to remote ones...  but this is an as-yet unsolved
118
        # aspect of format management and the Remote protocols...
119
        # self.assertEqual(left_repo._format.__class__,
120
        #     right_repo._format.__class__)
121
        left_repo.lock_read()
122
        try:
123
            right_repo.lock_read()
124
            try:
125
                # revs
126
                all_revs = left_repo.all_revision_ids()
127
                self.assertEqual(left_repo.all_revision_ids(),
128
                    right_repo.all_revision_ids())
129
                for rev_id in left_repo.all_revision_ids():
130
                    self.assertEqual(left_repo.get_revision(rev_id),
131
                        right_repo.get_revision(rev_id))
4118.1.3 by Andrew Bennetts
Remove redundant assertion method.
132
                # Assert the revision trees (and thus the inventories) are equal
133
                sort_key = lambda rev_tree: rev_tree.get_revision_id()
134
                rev_trees_a = sorted(
135
                    left_repo.revision_trees(all_revs), key=sort_key)
136
                rev_trees_b = sorted(
137
                    right_repo.revision_trees(all_revs), key=sort_key)
138
                for tree_a, tree_b in zip(rev_trees_a, rev_trees_b):
139
                    self.assertEqual([], list(tree_a.iter_changes(tree_b)))
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
140
                # texts
141
                text_index = left_repo._generate_text_key_index()
142
                self.assertEqual(text_index,
143
                    right_repo._generate_text_key_index())
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
144
                desired_files = []
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
145
                for file_id, revision_id in text_index.iterkeys():
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
146
                    desired_files.append(
147
                        (file_id, revision_id, (file_id, revision_id)))
148
                left_texts = list(left_repo.iter_files_bytes(desired_files))
149
                right_texts = list(right_repo.iter_files_bytes(desired_files))
150
                left_texts.sort()
151
                right_texts.sort()
152
                self.assertEqual(left_texts, right_texts)
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
153
                # signatures
154
                for rev_id in all_revs:
155
                    try:
156
                        left_text = left_repo.get_signature_text(rev_id)
157
                    except NoSuchRevision:
158
                        continue
159
                    right_text = right_repo.get_signature_text(rev_id)
160
                    self.assertEqual(left_text, right_text)
161
            finally:
162
                right_repo.unlock()
163
        finally:
164
            left_repo.unlock()
165
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
166
    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.
167
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
168
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
169
        If the bzrdir does have a workingtree, this is a no-op.
170
        """
171
        try:
172
            a_bzrdir.open_workingtree()
173
        except (errors.NotLocalUrl, errors.NoWorkingTree):
174
            raise TestSkipped("bzrdir on transport %r has no working tree"
175
                              % a_bzrdir.transport)
176
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
177
    def openWorkingTreeIfLocal(self, a_bzrdir):
178
        """If a_bzrdir is on a local transport, call open_workingtree() on it.
179
        """
180
        if not isinstance(a_bzrdir.root_transport, LocalTransport):
181
            # it's not local, but that's ok
182
            return
183
        a_bzrdir.open_workingtree()
184
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
185
    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.
186
        """Create a working tree on a_bzrdir, or raise TestSkipped.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
187
1910.4.11 by Andrew Bennetts
Add 'create_workingtree_or_skip' and 'skip_if_no_workingtree' helper methods to reduce duplicated code.
188
        A simple wrapper for create_workingtree that translates NotLocalUrl into
189
        TestSkipped.  Returns the newly created working tree.
190
        """
191
        try:
192
            return a_bzrdir.create_workingtree()
193
        except errors.NotLocalUrl:
194
            raise TestSkipped("cannot make working tree with transport %r"
195
                              % a_bzrdir.transport)
196
2387.1.1 by Robert Collins
Remove the --basis parameter to clone etc. (Robert Collins)
197
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None,
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
198
                     force_new_repo=False, accelerator_tree=None,
3983.1.7 by Daniel Watkins
Review comments from jam.
199
                     create_tree_if_local=True):
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
200
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
201
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
202
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
203
        TestSkipped.  Returns the newly sprouted bzrdir.
204
        """
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
205
        to_transport = get_transport(to_url)
206
        if not isinstance(to_transport, LocalTransport):
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
207
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
2485.8.56 by Vincent Ladeuil
Fix bug #112173 and bzr branch multiple connections.
208
        target = from_bzrdir.sprout(to_url, revision_id=revision_id,
209
                                    force_new_repo=force_new_repo,
3123.5.8 by Aaron Bentley
Work around double-opening lock issue
210
                                    possible_transports=[to_transport],
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
211
                                    accelerator_tree=accelerator_tree,
3983.1.7 by Daniel Watkins
Review comments from jam.
212
                                    create_tree_if_local=create_tree_if_local)
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
213
        return target
214
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
215
    def test_create_null_workingtree(self):
216
        dir = self.make_bzrdir('dir1')
217
        dir.create_repository()
218
        dir.create_branch()
1752.2.87 by Andrew Bennetts
Make tests pass.
219
        try:
220
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
221
        except errors.NotLocalUrl:
222
            raise TestSkipped("cannot make working tree with transport %r"
223
                              % dir.transport)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
224
        self.assertEqual([], wt.get_parent_ids())
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
225
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
226
    def test_destroy_workingtree(self):
227
        tree = self.make_branch_and_tree('tree')
228
        self.build_tree(['tree/file'])
229
        tree.add('file')
230
        tree.commit('first commit')
231
        bzrdir = tree.bzrdir
232
        try:
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
233
            bzrdir.destroy_workingtree()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
234
        except errors.UnsupportedOperation:
235
            raise TestSkipped('Format does not support destroying tree')
236
        self.failIfExists('tree/file')
237
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
238
        bzrdir.create_workingtree()
239
        self.failUnlessExists('tree/file')
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
240
        bzrdir.destroy_workingtree_metadata()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
241
        self.failUnlessExists('tree/file')
242
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
243
2796.2.6 by Aaron Bentley
Implement destroy_branch
244
    def test_destroy_branch(self):
245
        branch = self.make_branch('branch')
246
        bzrdir = branch.bzrdir
247
        try:
248
            bzrdir.destroy_branch()
249
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
250
            raise TestNotApplicable('Format does not support destroying tree')
251
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
252
        bzrdir.create_branch()
253
        bzrdir.open_branch()
254
2796.2.19 by Aaron Bentley
Support reconfigure --lightweight-checkout
255
    def test_destroy_repository(self):
256
        repo = self.make_repository('repository')
257
        bzrdir = repo.bzrdir
258
        try:
259
            bzrdir.destroy_repository()
260
        except (errors.UnsupportedOperation, errors.TransportNotPossible):
261
            raise TestNotApplicable('Format does not support destroying'
262
                                    ' repository')
263
        self.assertRaises(errors.NoRepositoryPresent, bzrdir.open_repository)
264
        bzrdir.create_repository()
265
        bzrdir.open_repository()
266
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
267
    def test_open_workingtree_raises_no_working_tree(self):
268
        """BzrDir.open_workingtree() should raise NoWorkingTree (rather than
269
        e.g. NotLocalUrl) if there is no working tree.
270
        """
271
        dir = self.make_bzrdir('source')
272
        vfs_dir = bzrdir.BzrDir.open(self.get_vfs_only_url('source'))
273
        if vfs_dir.has_workingtree():
274
            # This BzrDir format doesn't support BzrDirs without working trees,
275
            # so this test is irrelevant.
276
            return
277
        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()
278
279
    def test_clone_on_transport(self):
280
        a_dir = self.make_bzrdir('source')
281
        target_transport = a_dir.root_transport.clone('..').clone('target')
282
        target = a_dir.clone_on_transport(target_transport)
283
        self.assertNotEqual(a_dir.transport.base, target.transport.base)
284
        self.assertDirectoriesEqual(a_dir.root_transport, target.root_transport,
285
                                    ['./.bzr/merge-hashes'])
286
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
287
    def test_clone_bzrdir_empty(self):
288
        dir = self.make_bzrdir('source')
289
        target = dir.clone(self.get_url('target'))
290
        self.assertNotEqual(dir.transport.base, target.transport.base)
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
291
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
292
                                    ['./.bzr/merge-hashes'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
293
1534.6.8 by Robert Collins
Test the use of clone on empty bzrdir with force_new_repo.
294
    def test_clone_bzrdir_empty_force_new_ignored(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
295
        # 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.
296
        # bzrdir's clone logic
297
        dir = self.make_bzrdir('source')
298
        target = dir.clone(self.get_url('target'), force_new_repo=True)
299
        self.assertNotEqual(dir.transport.base, target.transport.base)
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
300
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
301
                                    ['./.bzr/merge-hashes'])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
302
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
303
    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.
304
        tree = self.make_branch_and_tree('commit_tree')
305
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
306
        tree.add('foo')
307
        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.
308
        dir = self.make_bzrdir('source')
309
        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.
310
        repo.fetch(tree.branch.repository)
311
        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.
312
        target = dir.clone(self.get_url('target'))
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,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
315
                                    [
316
                                     './.bzr/merge-hashes',
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
317
                                     './.bzr/repository',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
318
                                     ])
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
319
        self.assertRepositoryHasSameItems(tree.branch.repository,
320
            target.open_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.
321
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
322
    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.
323
        tree = self.make_branch_and_tree('commit_tree')
324
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
325
        tree.add('foo')
326
        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.
327
        dir = self.make_bzrdir('source')
328
        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.
329
        repo.fetch(tree.branch.repository)
330
        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.
331
        try:
332
            self.make_repository('target', shared=True)
333
        except errors.IncompatibleFormat:
334
            return
335
        target = dir.clone(self.get_url('target/child'))
336
        self.assertNotEqual(dir.transport.base, target.transport.base)
337
        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.
338
339
    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.
340
        # Create a shared repository
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
341
        try:
342
            shared_repo = self.make_repository('shared', shared=True)
343
        except errors.IncompatibleFormat:
344
            return
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
345
        # Make a branch, 'commit_tree', and working tree outside of the shared
346
        # 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.
347
        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.
348
        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.
349
        tree.add('foo')
350
        tree.commit('revision 1', rev_id='1')
351
        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.
352
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
353
        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.
354
        # Copy the content (i.e. revisions) from the 'commit_tree' branch's
355
        # repository into the shared repository.
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
356
        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.
357
        # 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.
358
        dir = self.make_bzrdir('shared/source')
359
        dir.create_branch()
2018.5.168 by Andrew Bennetts
Add some comments to test_clone_bzrdir_repository_branch_both_under_shared.
360
        # 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.
361
        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.
362
        # '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.
363
        self.assertNotEqual(dir.transport.base, target.transport.base)
364
        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.
365
        # The shared repository will contain revisions from the 'commit_tree'
366
        # repository, even revisions that are not part of the history of the
367
        # 'commit_tree' branch.
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
368
        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
369
370
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
371
        try:
372
            shared_repo = self.make_repository('shared', shared=True)
373
        except errors.IncompatibleFormat:
374
            return
375
        tree = self.make_branch_and_tree('commit_tree')
2018.5.132 by Robert Collins
Make all BzrDir implementation tests pass on RemoteBzrDir - fix some things, and remove the incomplete_with_basis tests as cruft.
376
        self.build_tree(['commit_tree/foo'])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
377
        tree.add('foo')
378
        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.
379
        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.
380
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
381
        tree.commit('revision 2', rev_id='2')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
382
        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.
383
        if shared_repo.make_working_trees():
384
            shared_repo.set_make_working_trees(False)
385
            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
386
        self.assertTrue(shared_repo.has_revision('1'))
387
        dir = self.make_bzrdir('shared/source')
388
        dir.create_branch()
389
        target = dir.clone(self.get_url('target'))
390
        self.assertNotEqual(dir.transport.base, target.transport.base)
391
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
392
        branch = target.open_branch()
393
        self.assertTrue(branch.repository.has_revision('1'))
394
        self.assertFalse(branch.repository.make_working_trees())
395
        self.assertTrue(branch.repository.is_shared())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
396
1534.6.9 by Robert Collins
sprouting into shared repositories
397
    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.
398
        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.
399
        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.
400
        tree.add('foo')
401
        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.
402
        dir = self.make_bzrdir('source')
403
        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.
404
        repo.fetch(tree.branch.repository)
405
        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.
406
        try:
407
            self.make_repository('target', shared=True)
408
        except errors.IncompatibleFormat:
409
            return
410
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
411
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
412
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
413
                                    ['./.bzr/repository',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
414
                                     ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
415
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
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.
416
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
417
    def test_clone_bzrdir_repository_revision(self):
418
        # test for revision limiting, [smoke test, not corner case checks].
419
        # make a repository with some revisions,
420
        # and clone it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
421
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
422
        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.
423
        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.
424
        tree.add('foo')
425
        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.
426
        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.
427
        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.
428
        tree.commit('revision 2', rev_id='2')
429
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
430
        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.
431
        dir = source.bzrdir
432
        target = dir.clone(self.get_url('target'), revision_id='2')
433
        raise TestSkipped('revision limiting not strict yet')
434
435
    def test_clone_bzrdir_branch_and_repo(self):
436
        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.
437
        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.
438
        tree.add('foo')
439
        tree.commit('revision 1')
440
        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.
441
        tree.branch.repository.copy_content_into(source.repository)
442
        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.
443
        dir = source.bzrdir
444
        target = dir.clone(self.get_url('target'))
445
        self.assertNotEqual(dir.transport.base, target.transport.base)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
446
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
447
                                    [
448
                                     './.bzr/basis-inventory-cache',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
449
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
450
                                     './.bzr/merge-hashes',
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
451
                                     './.bzr/repository',
2230.3.30 by Aaron Bentley
Fix whitespace issues
452
                                     './.bzr/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
453
                                    ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
454
        self.assertRepositoryHasSameItems(
455
            tree.branch.repository, target.open_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.
456
457
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
458
        # by default cloning into a shared repo uses the shared repo.
459
        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.
460
        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.
461
        tree.add('foo')
462
        tree.commit('revision 1')
463
        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.
464
        tree.branch.repository.copy_content_into(source.repository)
465
        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.
466
        try:
467
            self.make_repository('target', shared=True)
468
        except errors.IncompatibleFormat:
469
            return
470
        dir = source.bzrdir
471
        target = dir.clone(self.get_url('target/child'))
472
        self.assertNotEqual(dir.transport.base, target.transport.base)
473
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
474
        self.assertEqual(source.revision_history(),
475
                         target.open_branch().revision_history())
476
477
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
478
        # by default cloning into a shared repo uses the shared repo.
479
        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.
480
        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.
481
        tree.add('foo')
482
        tree.commit('revision 1')
483
        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.
484
        tree.branch.repository.copy_content_into(source.repository)
485
        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.
486
        try:
487
            self.make_repository('target', shared=True)
488
        except errors.IncompatibleFormat:
489
            return
490
        dir = source.bzrdir
491
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
492
        self.assertNotEqual(dir.transport.base, target.transport.base)
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
493
        repo = target.open_repository()
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
494
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
495
                                    ['./.bzr/repository',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
496
                                     ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
497
        self.assertRepositoryHasSameItems(tree.branch.repository, repo)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
498
499
    def test_clone_bzrdir_branch_reference(self):
500
        # cloning should preserve the reference status of the branch in a bzrdir
501
        referenced_branch = self.make_branch('referencced')
502
        dir = self.make_bzrdir('source')
503
        try:
1508.1.25 by Robert Collins
Update per review comments.
504
            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.
505
                referenced_branch)
506
        except errors.IncompatibleFormat:
507
            # this is ok too, not all formats have to support references.
508
            return
509
        target = dir.clone(self.get_url('target'))
510
        self.assertNotEqual(dir.transport.base, target.transport.base)
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
511
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
512
513
    def test_clone_bzrdir_branch_revision(self):
514
        # test for revision limiting, [smoke test, not corner case checks].
515
        # make a branch with some revisions,
516
        # and clone it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
517
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
518
        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.
519
        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.
520
        tree.add('foo')
521
        tree.commit('revision 1', rev_id='1')
522
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
523
        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.
524
        tree.branch.repository.copy_content_into(source.repository)
525
        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.
526
        dir = source.bzrdir
527
        target = dir.clone(self.get_url('target'), revision_id='1')
528
        self.assertEqual('1', target.open_branch().last_revision())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
529
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
530
    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.
531
        tree = self.make_branch_and_tree('source')
532
        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.
533
        tree.add('foo')
534
        tree.commit('revision 1')
535
        dir = tree.bzrdir
536
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
537
        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.
538
        self.assertNotEqual(dir.transport.base, target.transport.base)
539
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
540
                                    ['./.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.
541
                                     './.bzr/checkout/dirstate',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
542
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
543
                                     './.bzr/checkout/merge-hashes',
544
                                     './.bzr/merge-hashes',
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
545
                                     './.bzr/repository',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
546
                                     ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
547
        self.assertRepositoryHasSameItems(tree.branch.repository,
548
            target.open_repository())
2796.1.4 by Aaron Bentley
Fix up various test cases
549
        target.open_workingtree().revert()
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
550
3242.2.14 by Aaron Bentley
Update from review comments
551
    def test_clone_on_transport_preserves_repo_format(self):
552
        if self.bzrdir_format == bzrdir.format_registry.make_bzrdir('default'):
553
            format = 'knit'
554
        else:
555
            format = None
556
        source_branch = self.make_branch('source', format=format)
557
        # Ensure no format data is cached
558
        a_dir = bzrlib.branch.Branch.open_from_transport(
559
            self.get_transport('source')).bzrdir
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
560
        target_transport = self.get_transport('target')
3242.2.14 by Aaron Bentley
Update from review comments
561
        target_bzrdir = a_dir.clone_on_transport(target_transport)
562
        target_repo = target_bzrdir.open_repository()
3242.3.29 by Aaron Bentley
Fix failing test
563
        source_branch = bzrlib.branch.Branch.open(
564
            self.get_vfs_only_url('source'))
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
565
        if isinstance(target_repo, RemoteRepository):
566
            target_repo._ensure_real()
567
            target_repo = target_repo._real_repository
3242.2.14 by Aaron Bentley
Update from review comments
568
        self.assertEqual(target_repo._format, source_branch.repository._format)
569
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
570
    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.
571
        tree = self.make_branch_and_tree('source')
572
        self.build_tree(['source/foo'])
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
573
        tree.add('foo')
574
        tree.commit('revision 1')
575
        dir = tree.bzrdir
576
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
577
        self.skipIfNoWorkingTree(target)
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
578
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
579
                                    ['./.bzr/stat-cache',
2255.10.8 by John Arbash Meinel
Fix another tests that was assuming dirstate was identical
580
                                     './.bzr/checkout/dirstate',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
581
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
582
                                     './.bzr/checkout/merge-hashes',
583
                                     './.bzr/merge-hashes',
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
584
                                     './.bzr/repository',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
585
                                     ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
586
        self.assertRepositoryHasSameItems(tree.branch.repository,
587
            target.open_repository())
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
588
2796.1.4 by Aaron Bentley
Fix up various test cases
589
        target.open_workingtree().revert()
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
590
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
591
                                    ['./.bzr/stat-cache',
2255.10.8 by John Arbash Meinel
Fix another tests that was assuming dirstate was identical
592
                                     './.bzr/checkout/dirstate',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
593
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
594
                                     './.bzr/checkout/merge-hashes',
595
                                     './.bzr/merge-hashes',
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
596
                                     './.bzr/repository',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
597
                                     ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
598
        self.assertRepositoryHasSameItems(tree.branch.repository,
599
            target.open_repository())
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
600
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
601
    def test_clone_bzrdir_tree_branch_reference(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
602
        # a tree with a branch reference (aka a checkout)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
603
        # should stay a checkout on clone.
604
        referenced_branch = self.make_branch('referencced')
605
        dir = self.make_bzrdir('source')
606
        try:
1508.1.25 by Robert Collins
Update per review comments.
607
            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.
608
                referenced_branch)
609
        except errors.IncompatibleFormat:
610
            # this is ok too, not all formats have to support references.
611
            return
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
612
        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.
613
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
614
        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.
615
        self.assertNotEqual(dir.transport.base, target.transport.base)
616
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
617
                                    ['./.bzr/stat-cache',
618
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
619
                                     './.bzr/checkout/merge-hashes',
620
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
621
                                     './.bzr/repository/inventory.knit',
622
                                     ])
623
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
624
    def test_clone_bzrdir_tree_revision(self):
625
        # test for revision limiting, [smoke test, not corner case checks].
626
        # make a tree with a revision with a last-revision
627
        # and clone it with a revision limit.
628
        # This smoke test just checks the revision-id is right. Tree specific
629
        # tests will check corner cases.
630
        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.
631
        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.
632
        tree.add('foo')
633
        tree.commit('revision 1', rev_id='1')
634
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
635
        dir = tree.bzrdir
636
        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.
637
        self.skipIfNoWorkingTree(target)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
638
        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.
639
2991.1.1 by Daniel Watkins
Added (failing) test to ensure that bzrdir.clone won't create a working tree in a no-trees repository.
640
    def test_clone_bzrdir_into_notrees_repo(self):
641
        """Cloning into a no-trees repo should not create a working tree"""
642
        tree = self.make_branch_and_tree('source')
643
        self.build_tree(['source/foo'])
644
        tree.add('foo')
645
        tree.commit('revision 1')
646
647
        try:
648
            repo = self.make_repository('repo', shared=True)
649
        except errors.IncompatibleFormat:
2991.1.4 by Daniel Watkins
Modified tests as per comments on-list.
650
            raise TestNotApplicable('must support shared repositories')
2991.1.1 by Daniel Watkins
Added (failing) test to ensure that bzrdir.clone won't create a working tree in a no-trees repository.
651
        if repo.make_working_trees():
652
            repo.set_make_working_trees(False)
653
            self.assertFalse(repo.make_working_trees())
654
655
        dir = tree.bzrdir
656
        a_dir = dir.clone(self.get_url('repo/a'))
657
        a_dir.open_branch()
2991.1.4 by Daniel Watkins
Modified tests as per comments on-list.
658
        self.assertRaises(errors.NoWorkingTree, a_dir.open_workingtree)
2991.1.1 by Daniel Watkins
Added (failing) test to ensure that bzrdir.clone won't create a working tree in a no-trees repository.
659
3650.5.3 by Aaron Bentley
Add failing test of BzrDir.clone
660
    def test_clone_respects_stacked(self):
661
        branch = self.make_branch('parent')
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
662
        child_transport = self.get_transport('child')
3650.5.3 by Aaron Bentley
Add failing test of BzrDir.clone
663
        child = branch.bzrdir.clone_on_transport(child_transport,
664
                                                 stacked_on=branch.base)
665
        self.assertEqual(child.open_branch().get_stacked_on_url(), branch.base)
666
2414.2.1 by Andrew Bennetts
Some miscellaneous new APIs, tests and other changes from the hpss branch.
667
    def test_get_branch_reference_on_reference(self):
668
        """get_branch_reference should return the right url."""
669
        referenced_branch = self.make_branch('referenced')
670
        dir = self.make_bzrdir('source')
671
        try:
672
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
673
                referenced_branch)
674
        except errors.IncompatibleFormat:
675
            # this is ok too, not all formats have to support references.
676
            return
677
        self.assertEqual(referenced_branch.bzrdir.root_transport.abspath('') + '/',
678
            dir.get_branch_reference())
679
680
    def test_get_branch_reference_on_non_reference(self):
681
        """get_branch_reference should return None for non-reference branches."""
682
        branch = self.make_branch('referenced')
683
        self.assertEqual(None, branch.bzrdir.get_branch_reference())
684
685
    def test_get_branch_reference_no_branch(self):
686
        """get_branch_reference should not mask NotBranchErrors."""
687
        dir = self.make_bzrdir('source')
688
        if dir.has_branch():
689
            # this format does not support branchless bzrdirs.
690
            return
691
        self.assertRaises(errors.NotBranchError, dir.get_branch_reference)
692
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
693
    def test_sprout_bzrdir_empty(self):
694
        dir = self.make_bzrdir('source')
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
695
        target = dir.sprout(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.
696
        self.assertNotEqual(dir.transport.base, target.transport.base)
697
        # creates a new repository branch and tree
698
        target.open_repository()
699
        target.open_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
700
        self.openWorkingTreeIfLocal(target)
1534.6.9 by Robert Collins
sprouting into shared repositories
701
702
    def test_sprout_bzrdir_empty_under_shared_repo(self):
703
        # sprouting an empty dir into a repo uses the repo
704
        dir = self.make_bzrdir('source')
705
        try:
706
            self.make_repository('target', shared=True)
707
        except errors.IncompatibleFormat:
708
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
709
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
710
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
711
        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.
712
        try:
713
            target.open_workingtree()
2445.1.1 by Andrew Bennetts
Make RemoteBzrDir.open_workingtree raise NoWorkingTree rather than NotLocalUrl
714
        except errors.NoWorkingTree:
715
            # bzrdir's that never have working trees are allowed to pass;
716
            # 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.
717
            self.assertIsInstance(target, RemoteBzrDir)
1534.6.9 by Robert Collins
sprouting into shared repositories
718
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.
719
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
720
        # the force_new_repo parameter should force use of a new repo in an empty
721
        # bzrdir's sprout logic
722
        dir = self.make_bzrdir('source')
723
        try:
724
            self.make_repository('target', shared=True)
725
        except errors.IncompatibleFormat:
726
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
727
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
728
        target.open_repository()
729
        target.open_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
730
        self.openWorkingTreeIfLocal(target)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
731
1534.4.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
    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.
733
        tree = self.make_branch_and_tree('commit_tree')
734
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
735
        tree.add('foo')
736
        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.
737
        dir = self.make_bzrdir('source')
738
        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.
739
        repo.fetch(tree.branch.repository)
740
        self.assertTrue(repo.has_revision('1'))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
741
        try:
2598.5.2 by Aaron Bentley
Got all tests passing with Branch returning 'null:' for null revision
742
            self.assertTrue(
2598.5.4 by Aaron Bentley
Restore original Branch.last_revision behavior, fix bits that care
743
                _mod_revision.is_null(_mod_revision.ensure_null(
744
                dir.open_branch().last_revision())))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
745
        except errors.NotBranchError:
746
            pass
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
747
        target = dir.sprout(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.
748
        self.assertNotEqual(dir.transport.base, target.transport.base)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
749
        # testing inventory isn't reasonable for repositories
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
750
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
751
                                    [
752
                                     './.bzr/branch',
753
                                     './.bzr/checkout',
754
                                     './.bzr/inventory',
755
                                     './.bzr/parent',
756
                                     './.bzr/repository/inventory.knit',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
757
                                     ])
1731.1.33 by Aaron Bentley
Revert no-special-root changes
758
        try:
759
            # If we happen to have a tree, we'll guarantee everything
760
            # except for the tree root is the same.
761
            inventory_f = file(dir.transport.base+'inventory', 'rb')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
762
            self.assertContainsRe(inventory_f.read(),
1731.1.33 by Aaron Bentley
Revert no-special-root changes
763
                                  '<inventory file_id="TREE_ROOT[^"]*"'
764
                                  ' format="5">\n</inventory>\n')
765
            inventory_f.close()
766
        except IOError, e:
767
            if e.errno != errno.ENOENT:
768
                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.
769
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
770
    def test_sprout_bzrdir_with_repository_to_shared(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
771
        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.
772
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
773
        tree.add('foo')
774
        tree.commit('revision 1', rev_id='1')
775
        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.
776
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
777
        tree.commit('revision 2', rev_id='2')
778
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
779
        tree.branch.repository.copy_content_into(source)
1534.6.9 by Robert Collins
sprouting into shared repositories
780
        dir = source.bzrdir
781
        try:
782
            shared_repo = self.make_repository('target', shared=True)
783
        except errors.IncompatibleFormat:
784
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
785
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
786
        self.assertNotEqual(dir.transport.base, target.transport.base)
787
        self.assertTrue(shared_repo.has_revision('1'))
788
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
789
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
790
        try:
791
            shared_repo = self.make_repository('shared', shared=True)
792
        except errors.IncompatibleFormat:
793
            return
794
        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.
795
        self.build_tree(['commit_tree/foo'])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
796
        tree.add('foo')
797
        tree.commit('revision 1', rev_id='1')
798
        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.
799
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
800
        tree.commit('revision 2', rev_id='2')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
801
        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.
802
        dir = self.make_bzrdir('shared/source')
803
        dir.create_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
804
        target = dir.sprout(self.get_url('shared/target'))
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
805
        self.assertNotEqual(dir.transport.base, target.transport.base)
806
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
807
        self.assertTrue(shared_repo.has_revision('1'))
808
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
809
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
810
        try:
811
            shared_repo = self.make_repository('shared', shared=True)
812
        except errors.IncompatibleFormat:
813
            return
814
        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.
815
        self.build_tree(['commit_tree/foo'])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
816
        tree.add('foo')
817
        tree.commit('revision 1', rev_id='1')
818
        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.
819
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
820
        tree.commit('revision 2', rev_id='2')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
821
        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.
822
        if shared_repo.make_working_trees():
823
            shared_repo.set_make_working_trees(False)
824
            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
825
        self.assertTrue(shared_repo.has_revision('1'))
826
        dir = self.make_bzrdir('shared/source')
827
        dir.create_branch()
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
828
        target = dir.sprout(self.get_url('target'))
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
829
        self.assertNotEqual(dir.transport.base, target.transport.base)
830
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
831
        branch = target.open_branch()
832
        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.
833
        if not isinstance(branch.bzrdir, RemoteBzrDir):
834
            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
835
        self.assertFalse(branch.repository.is_shared())
836
1534.6.9 by Robert Collins
sprouting into shared repositories
837
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
838
        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.
839
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
840
        tree.add('foo')
841
        tree.commit('revision 1', rev_id='1')
842
        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.
843
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
844
        tree.commit('revision 2', rev_id='2')
845
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
846
        tree.branch.repository.copy_content_into(source)
1534.6.9 by Robert Collins
sprouting into shared repositories
847
        dir = source.bzrdir
848
        try:
849
            shared_repo = self.make_repository('target', shared=True)
850
        except errors.IncompatibleFormat:
851
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
852
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
853
        self.assertNotEqual(dir.transport.base, target.transport.base)
854
        self.assertFalse(shared_repo.has_revision('1'))
855
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
856
    def test_sprout_bzrdir_repository_revision(self):
857
        # test for revision limiting, [smoke test, not corner case checks].
858
        # make a repository with some revisions,
859
        # and sprout it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
860
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
861
        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.
862
        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.
863
        tree.add('foo')
864
        tree.commit('revision 1', rev_id='1')
865
        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.
866
        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.
867
        tree.commit('revision 2', rev_id='2')
868
        source = self.make_repository('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
869
        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.
870
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
871
        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.
872
        raise TestSkipped('revision limiting not strict yet')
873
874
    def test_sprout_bzrdir_branch_and_repo(self):
875
        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.
876
        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.
877
        tree.add('foo')
878
        tree.commit('revision 1')
879
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
880
        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.
881
        tree.bzrdir.open_branch().copy_content_into(source)
882
        dir = source.bzrdir
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
883
        target = dir.sprout(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)
4118.1.2 by Andrew Bennetts
Fix failing test by adding assertRepositoriesEqual.
885
        target_repo = target.open_repository()
4118.1.3 by Andrew Bennetts
Remove redundant assertion method.
886
        self.assertRepositoryHasSameItems(source.repository, target_repo)
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
887
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
888
                                    [
889
                                     './.bzr/basis-inventory-cache',
890
                                     './.bzr/branch/branch.conf',
891
                                     './.bzr/branch/parent',
892
                                     './.bzr/checkout',
893
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
894
                                     './.bzr/checkout/stat-cache',
895
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
896
                                     './.bzr/parent',
4118.1.2 by Andrew Bennetts
Fix failing test by adding assertRepositoriesEqual.
897
                                     './.bzr/repository',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
898
                                     './.bzr/stat-cache',
899
                                     './foo',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
900
                                     ])
1534.4.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
1534.6.9 by Robert Collins
sprouting into shared repositories
902
    def test_sprout_bzrdir_branch_and_repo_shared(self):
903
        # sprouting a branch with a repo into a shared repo uses the shared
904
        # repo
905
        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.
906
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
907
        tree.add('foo')
908
        tree.commit('revision 1', rev_id='1')
909
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
910
        tree.branch.repository.copy_content_into(source.repository)
1534.6.9 by Robert Collins
sprouting into shared repositories
911
        tree.bzrdir.open_branch().copy_content_into(source)
912
        dir = source.bzrdir
913
        try:
914
            shared_repo = self.make_repository('target', shared=True)
915
        except errors.IncompatibleFormat:
916
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
917
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
918
        self.assertTrue(shared_repo.has_revision('1'))
919
920
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
921
        # sprouting a branch with a repo into a shared repo uses the shared
922
        # repo
923
        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.
924
        self.build_tree(['commit_tree/foo'])
1534.6.9 by Robert Collins
sprouting into shared repositories
925
        tree.add('foo')
926
        tree.commit('revision 1', rev_id='1')
927
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
928
        tree.branch.repository.copy_content_into(source.repository)
1534.6.9 by Robert Collins
sprouting into shared repositories
929
        tree.bzrdir.open_branch().copy_content_into(source)
930
        dir = source.bzrdir
931
        try:
932
            shared_repo = self.make_repository('target', shared=True)
933
        except errors.IncompatibleFormat:
934
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
935
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
936
        self.assertNotEqual(dir.transport.base, target.transport.base)
937
        self.assertFalse(shared_repo.has_revision('1'))
938
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
939
    def test_sprout_bzrdir_branch_reference(self):
940
        # sprouting should create a repository if needed and a sprouted branch.
4070.7.3 by Andrew Bennetts
Make the sprout_bzrdir_branch_reference tests pass by returning an error from the cloning_metadir RPC which triggers a VFS fallback on the client.
941
        referenced_branch = self.make_branch('referenced')
942
        dir = self.make_bzrdir('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.
943
        try:
1508.1.25 by Robert Collins
Update per review comments.
944
            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.
945
                referenced_branch)
946
        except errors.IncompatibleFormat:
947
            # this is ok too, not all formats have to support references.
948
            return
949
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
950
        target = dir.sprout(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.
951
        self.assertNotEqual(dir.transport.base, target.transport.base)
952
        # we want target to have a branch that is in-place.
953
        self.assertEqual(target, target.open_branch().bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
954
        # and as we dont support repositories being detached yet, a repo in
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
955
        # place
956
        target.open_repository()
957
1534.6.9 by Robert Collins
sprouting into shared repositories
958
    def test_sprout_bzrdir_branch_reference_shared(self):
959
        # sprouting should create a repository if needed and a sprouted branch.
960
        referenced_tree = self.make_branch_and_tree('referenced')
961
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
4070.7.3 by Andrew Bennetts
Make the sprout_bzrdir_branch_reference tests pass by returning an error from the cloning_metadir RPC which triggers a VFS fallback on the client.
962
        dir = self.make_bzrdir('source')
1534.6.9 by Robert Collins
sprouting into shared repositories
963
        try:
964
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
965
                referenced_tree.branch)
966
        except errors.IncompatibleFormat:
967
            # this is ok too, not all formats have to support references.
968
            return
969
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
970
        try:
971
            shared_repo = self.make_repository('target', shared=True)
972
        except errors.IncompatibleFormat:
973
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
974
        target = dir.sprout(self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
975
        self.assertNotEqual(dir.transport.base, target.transport.base)
976
        # we want target to have a branch that is in-place.
977
        self.assertEqual(target, target.open_branch().bzrdir)
978
        # and we want no repository as the target is shared
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
979
        self.assertRaises(errors.NoRepositoryPresent,
1534.6.9 by Robert Collins
sprouting into shared repositories
980
                          target.open_repository)
981
        # and we want revision '1' in the shared repo
982
        self.assertTrue(shared_repo.has_revision('1'))
983
984
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
985
        # sprouting should create a repository if needed and a sprouted branch.
986
        referenced_tree = self.make_branch_and_tree('referenced')
987
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
4070.7.3 by Andrew Bennetts
Make the sprout_bzrdir_branch_reference tests pass by returning an error from the cloning_metadir RPC which triggers a VFS fallback on the client.
988
        dir = self.make_bzrdir('source')
1534.6.9 by Robert Collins
sprouting into shared repositories
989
        try:
990
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
991
                referenced_tree.branch)
992
        except errors.IncompatibleFormat:
993
            # this is ok too, not all formats have to support references.
994
            return
995
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
996
        try:
997
            shared_repo = self.make_repository('target', shared=True)
998
        except errors.IncompatibleFormat:
999
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
1000
        target = dir.sprout(self.get_url('target/child'), force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
1001
        self.assertNotEqual(dir.transport.base, target.transport.base)
1002
        # we want target to have a branch that is in-place.
1003
        self.assertEqual(target, target.open_branch().bzrdir)
1004
        # and we want revision '1' in the new repo
1005
        self.assertTrue(target.open_repository().has_revision('1'))
1006
        # but not the shared one
1007
        self.assertFalse(shared_repo.has_revision('1'))
1008
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1009
    def test_sprout_bzrdir_branch_revision(self):
1010
        # test for revision limiting, [smoke test, not corner case checks].
1011
        # make a repository with some revisions,
1012
        # and sprout it with a revision limit.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1013
        #
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1014
        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.
1015
        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.
1016
        tree.add('foo')
1017
        tree.commit('revision 1', rev_id='1')
1018
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1019
        source = self.make_branch('source')
2018.5.167 by Andrew Bennetts
Various changes in response to John's review.
1020
        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.
1021
        tree.bzrdir.open_branch().copy_content_into(source)
1022
        dir = source.bzrdir
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
1023
        target = dir.sprout(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.
1024
        self.assertEqual('1', target.open_branch().last_revision())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1025
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1026
    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.
1027
        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.
1028
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
1029
        tree.add('foo')
1030
        tree.commit('revision 1')
1031
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
1032
        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.
1033
        self.assertNotEqual(dir.transport.base, target.transport.base)
1034
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
1035
                                    [
1036
                                     './.bzr/branch/branch.conf',
1037
                                     './.bzr/branch/parent',
2255.10.9 by John Arbash Meinel
one more test that needs to ignore dirstate
1038
                                     './.bzr/checkout/dirstate',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
1039
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
1040
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
1041
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
1042
                                     './.bzr/parent',
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1043
                                     './.bzr/repository',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
1044
                                     './.bzr/stat-cache',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
1045
                                     ])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1046
        self.assertRepositoryHasSameItems(
1047
            tree.branch.repository, target.open_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.
1048
1049
    def test_sprout_bzrdir_tree_branch_reference(self):
1050
        # 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.
1051
        # 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.
1052
        referenced_branch = self.make_branch('referencced')
1053
        dir = self.make_bzrdir('source')
1054
        try:
1508.1.25 by Robert Collins
Update per review comments.
1055
            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.
1056
                referenced_branch)
1057
        except errors.IncompatibleFormat:
1058
            # this is ok too, not all formats have to support references.
1059
            return
1060
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1061
        tree = self.createWorkingTreeOrSkip(dir)
2381.1.3 by Robert Collins
Review feedback.
1062
        self.build_tree(['source/subdir/'])
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
1063
        tree.add('subdir')
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
1064
        target = dir.sprout(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.
1065
        self.assertNotEqual(dir.transport.base, target.transport.base)
1066
        # we want target to have a branch that is in-place.
1067
        self.assertEqual(target, target.open_branch().bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1068
        # and as we dont support repositories being detached yet, a repo in
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1069
        # place
1070
        target.open_repository()
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
1071
        result_tree = target.open_workingtree()
1072
        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.
1073
1074
    def test_sprout_bzrdir_tree_branch_reference_revision(self):
1075
        # 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.
1076
        # 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.
1077
        # and the likewise the new branch should be truncated too
1078
        referenced_branch = self.make_branch('referencced')
1079
        dir = self.make_bzrdir('source')
1080
        try:
1508.1.25 by Robert Collins
Update per review comments.
1081
            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.
1082
                referenced_branch)
1083
        except errors.IncompatibleFormat:
1084
            # this is ok too, not all formats have to support references.
1085
            return
1086
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1087
        tree = self.createWorkingTreeOrSkip(dir)
2381.1.3 by Robert Collins
Review feedback.
1088
        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.
1089
        tree.add('foo')
1090
        tree.commit('revision 1', rev_id='1')
1091
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1092
        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.
1093
        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.
1094
        self.assertNotEqual(dir.transport.base, target.transport.base)
1095
        # we want target to have a branch that is in-place.
1096
        self.assertEqual(target, target.open_branch().bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1097
        # and as we dont support repositories being detached yet, a repo in
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
1098
        # place
1099
        target.open_repository()
1100
        # we trust that the working tree sprouting works via the other tests.
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1101
        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.
1102
        self.assertEqual('1', target.open_branch().last_revision())
1103
1104
    def test_sprout_bzrdir_tree_revision(self):
1105
        # test for revision limiting, [smoke test, not corner case checks].
1106
        # make a tree with a revision with a last-revision
1107
        # and sprout it with a revision limit.
1108
        # This smoke test just checks the revision-id is right. Tree specific
1109
        # tests will check corner cases.
1110
        tree = self.make_branch_and_tree('source')
2381.1.3 by Robert Collins
Review feedback.
1111
        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.
1112
        tree.add('foo')
1113
        tree.commit('revision 1', rev_id='1')
1114
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1115
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
1116
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1117
        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.
1118
3123.5.8 by Aaron Bentley
Work around double-opening lock issue
1119
    def test_sprout_takes_accelerator(self):
1120
        tree = self.make_branch_and_tree('source')
1121
        self.build_tree(['source/foo'])
1122
        tree.add('foo')
1123
        tree.commit('revision 1', rev_id='1')
1124
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1125
        dir = tree.bzrdir
1126
        target = self.sproutOrSkip(dir, self.get_url('target'),
1127
                                   accelerator_tree=tree)
1128
        self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
1129
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
1130
    def test_sprout_branch_no_tree(self):
1131
        tree = self.make_branch_and_tree('source')
1132
        self.build_tree(['source/foo'])
1133
        tree.add('foo')
1134
        tree.commit('revision 1', rev_id='1')
1135
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
1136
        dir = tree.bzrdir
3983.1.11 by Daniel Watkins
Old BzrDirs which must have working trees are now allowed for in the test.
1137
        if isinstance(dir, (bzrdir.BzrDirPreSplitOut,)):
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
1138
            self.assertRaises(errors.MustHaveWorkingTree, dir.sprout,
1139
                              self.get_url('target'),
3983.1.11 by Daniel Watkins
Old BzrDirs which must have working trees are now allowed for in the test.
1140
                              create_tree_if_local=False)
1141
            return
4070.7.1 by Andrew Bennetts
Cause 32 less test skips in bzrdir_implementations.test_bzrdir.
1142
        target = dir.sprout(self.get_url('target'), create_tree_if_local=False)
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
1143
        self.failIfExists('target/foo')
3983.1.9 by Daniel Watkins
Wrapped long line.
1144
        self.assertEqual(tree.branch.last_revision(),
1145
                         target.open_branch().last_revision())
3983.1.3 by Daniel Watkins
Added test to ensure BzrDirs accept the 'no_tree' argument.
1146
1534.4.39 by Robert Collins
Basic BzrDir support.
1147
    def test_format_initialize_find_open(self):
1148
        # loopback test to check the current format initializes to itself.
1149
        if not self.bzrdir_format.is_supported():
1150
            # unsupported formats are not loopback testable
1151
            # because the default open will not open them and
1152
            # they may not be initializable.
1153
            return
1154
        # supported formats must be able to init and open
1155
        t = get_transport(self.get_url())
1156
        readonly_t = get_transport(self.get_readonly_url())
1157
        made_control = self.bzrdir_format.initialize(t.base)
1158
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
1159
        self.assertEqual(self.bzrdir_format,
1160
                         bzrdir.BzrDirFormat.find_format(readonly_t))
1161
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
1162
        opened_dir = bzrdir.BzrDir.open(t.base)
1163
        self.assertEqual(made_control._format,
1164
                         opened_dir._format)
1165
        self.assertEqual(direct_opened_dir._format,
1166
                         opened_dir._format)
1167
        self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
1168
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1169
    def test_format_initialize_on_transport_ex(self):
1170
        t = self.get_transport('dir')
1171
        self.assertInitializeEx(t)
1172
1173
    def test_format_initialize_on_transport_ex_use_existing_dir_True(self):
1174
        t = self.get_transport('dir')
1175
        t.ensure_base()
1176
        self.assertInitializeEx(t, use_existing_dir=True)
1177
1178
    def test_format_initialize_on_transport_ex_use_existing_dir_False(self):
1179
        if not self.bzrdir_format.is_supported():
1180
            # Not initializable - not a failure either.
1181
            return
1182
        t = self.get_transport('dir')
1183
        t.ensure_base()
4294.2.10 by Robert Collins
Review feedback.
1184
        self.assertRaises(errors.FileExists,
1185
            self.bzrdir_format.initialize_on_transport_ex, t,
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1186
            use_existing_dir=False)
1187
1188
    def test_format_initialize_on_transport_ex_create_prefix_True(self):
1189
        t = self.get_transport('missing/dir')
1190
        self.assertInitializeEx(t, create_prefix=True)
1191
1192
    def test_format_initialize_on_transport_ex_create_prefix_False(self):
1193
        if not self.bzrdir_format.is_supported():
1194
            # Not initializable - not a failure either.
1195
            return
1196
        t = self.get_transport('missing/dir')
1197
        self.assertRaises(errors.NoSuchFile, self.assertInitializeEx, t,
1198
            create_prefix=False)
1199
1200
    def test_format_initialize_on_transport_ex_force_new_repo_True(self):
1201
        t = self.get_transport('repo')
1202
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1203
        repo_name = repo_fmt.repository_format.network_name()
1204
        repo = repo_fmt.initialize_on_transport_ex(t,
1205
            repo_format_name=repo_name, shared_repo=True)[0]
1206
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1207
            force_new_repo=True, repo_format_name=repo_name)
1208
        if control is None:
1209
            # uninitialisable format
1210
            return
1211
        self.assertNotEqual(repo.bzrdir.root_transport.base,
1212
            made_repo.bzrdir.root_transport.base)
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
1213
        # New repositories are write locked.
1214
        self.assertTrue(made_repo.is_write_locked())
1215
        made_repo.unlock()
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1216
1217
    def test_format_initialize_on_transport_ex_force_new_repo_False(self):
1218
        t = self.get_transport('repo')
1219
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1220
        repo_name = repo_fmt.repository_format.network_name()
1221
        repo = repo_fmt.initialize_on_transport_ex(t,
1222
            repo_format_name=repo_name, shared_repo=True)[0]
1223
        made_repo, control = self.assertInitializeEx(t.clone('branch'),
1224
            force_new_repo=False, repo_format_name=repo_name)
1225
        if control is None:
1226
            # uninitialisable format
1227
            return
1228
        if not isinstance(control._format, (bzrdir.BzrDirFormat5,
1229
            bzrdir.BzrDirFormat6,)):
1230
            self.assertEqual(repo.bzrdir.root_transport.base,
1231
                made_repo.bzrdir.root_transport.base)
1232
1233
    def test_format_initialize_on_transport_ex_stacked_on(self):
4294.2.8 by Robert Collins
Reduce round trips pushing new branches substantially.
1234
        # trunk is a stackable format.  Note that its in the same server area
1235
        # which is what launchpad does, but not sufficient to exercise the
1236
        # general case.
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1237
        trunk = self.make_branch('trunk', format='1.9')
1238
        t = self.get_transport('stacked')
1239
        old_fmt = bzrdir.format_registry.make_bzrdir('pack-0.92')
1240
        repo_name = old_fmt.repository_format.network_name()
1241
        # Should end up with a 1.9 format (stackable)
1242
        repo, control = self.assertInitializeEx(t, need_meta=True,
1243
            repo_format_name=repo_name, stacked_on='../trunk', stack_on_pwd=t.base)
1244
        if control is None:
1245
            # uninitialisable format
1246
            return
1247
        self.assertLength(1, repo._fallback_repositories)
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
1248
        # New repositories are write locked.
1249
        self.assertTrue(repo.is_write_locked())
1250
        repo.unlock()
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1251
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1252
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1253
        # When initialize_on_transport_ex uses a stacked-on branch because of
1254
        # a stacking policy on the target, the location of the fallback
1255
        # repository is the same as the external location of the stacked-on
1256
        # branch.
1257
        balloon = self.make_bzrdir('balloon')
1258
        if isinstance(balloon, bzrdir.BzrDirMetaFormat1):
1259
            stack_on = self.make_branch('stack-on', format='1.9')
1260
        else:
1261
            stack_on = self.make_branch('stack-on')
1262
        config = self.make_bzrdir('.').get_config()
1263
        try:
1264
            config.set_default_stack_on('stack-on')
1265
        except errors.BzrError:
1266
            raise TestNotApplicable('Only relevant for stackable formats.')
1267
        # Initialize a bzrdir subject to the policy.
1268
        t = self.get_transport('stacked')
1269
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1270
        repo_name = repo_fmt.repository_format.network_name()
1271
        repo, control = self.assertInitializeEx(
1272
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1273
        if control is None:
1274
            # uninitialisable format
1275
            return
1276
        # There's one fallback repo, with a public location.
1277
        self.assertLength(1, repo._fallback_repositories)
1278
        fallback_repo = repo._fallback_repositories[0]
1279
        self.assertEqual(
1280
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
4456.2.1 by Andrew Bennetts
Fix automatic branch format upgrades triggered by a default stacking policy on a 1.16rc1 (or later) smart server.
1281
        # The bzrdir creates a branch in stacking-capable format.
1282
        new_branch = control.create_branch()
1283
        self.assertTrue(new_branch._format.supports_stacking())
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1284
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1285
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1286
        t = self.get_transport('dir')
1287
        repo, control = self.assertInitializeEx(t)
1288
        self.assertEqual(None, repo)
1289
1290
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1291
        t = self.get_transport('dir')
4294.2.10 by Robert Collins
Review feedback.
1292
        # 1.6 is likely to never be default
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1293
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
1294
        repo_name = fmt.repository_format.network_name()
1295
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1296
        if control is None:
1297
            # uninitialisable format
1298
            return
1299
        if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
1300
            bzrdir.BzrDirFormat6)):
1301
            # must stay with the all-in-one-format.
1302
            repo_name = self.bzrdir_format.network_name()
1303
        self.assertEqual(repo_name, repo._format.network_name())
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
1304
        # New repositories are write locked.
1305
        self.assertTrue(repo.is_write_locked())
1306
        repo.unlock()
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1307
1308
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
1309
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1310
4294.2.10 by Robert Collins
Review feedback.
1311
        This involves checking that the disk objects were created, open with
1312
        the same format returned, and had the expected disk format.
1313
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1314
        :param t: The transport to initialize on.
1315
        :param **kwargs: Additional arguments to pass to
1316
            initialize_on_transport_ex.
1317
        :return: the resulting repo, control dir tuple.
1318
        """
1319
        if not self.bzrdir_format.is_supported():
1320
            # Not initializable - not a failure either.
1321
            return None, None
1322
        repo, control, require_stacking, repo_policy = \
1323
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1324
        self.assertIsInstance(control, bzrdir.BzrDir)
1325
        opened = bzrdir.BzrDir.open(t.base)
1326
        expected_format = self.bzrdir_format
1327
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
4294.2.10 by Robert Collins
Review feedback.
1328
            # Current RemoteBzrDirFormat's do not reliably get network_name
1329
            # set, so we skip a number of tests for RemoteBzrDirFormat's.
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1330
            self.assertIsInstance(control, RemoteBzrDir)
1331
        else:
1332
            if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
1333
                bzrdir.BzrDirFormat6)):
1334
                # Pre-metadir formats change when we are making something that
1335
                # needs a metaformat, because clone is used for push.
1336
                expected_format = bzrdir.BzrDirMetaFormat1()
1337
            self.assertEqual(control._format.network_name(),
1338
                expected_format.network_name())
1339
            self.assertEqual(control._format.network_name(),
1340
                opened._format.network_name())
1341
        self.assertEqual(control.__class__, opened.__class__)
1342
        return repo, control
1343
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1344
    def test_format_network_name(self):
1345
        # All control formats must have a network name.
1346
        dir = self.make_bzrdir('.')
1347
        format = dir._format
1348
        # We want to test that the network_name matches the actual format on
1349
        # disk. For local control dirsthat means that using network_name as a
1350
        # key in the registry gives back the same format. For remote obects
1351
        # we check that the network_name of the RemoteBzrDirFormat we have
1352
        # locally matches the actual format present on disk.
1353
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
1354
            dir._ensure_real()
1355
            real_dir = dir._real_bzrdir
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1356
            network_name = format.network_name()
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1357
            self.assertEqual(real_dir._format.network_name(), network_name)
1358
        else:
1359
            registry = bzrdir.network_format_registry
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1360
            network_name = format.network_name()
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1361
            looked_up_format = registry.get(network_name)
1362
            self.assertEqual(format.__class__, looked_up_format.__class__)
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1363
        # The network name must be a byte string.
1364
        self.assertIsInstance(network_name, str)
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1365
1534.4.39 by Robert Collins
Basic BzrDir support.
1366
    def test_open_not_bzrdir(self):
1367
        # test the formats specific behaviour for no-content or similar dirs.
1368
        self.assertRaises(NotBranchError,
1369
                          self.bzrdir_format.open,
1370
                          get_transport(self.get_readonly_url()))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1371
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1372
    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.
1373
        # a bzrdir can construct a branch and repository for itself.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1374
        if not self.bzrdir_format.is_supported():
1375
            # unsupported formats are not loopback testable
1376
            # because the default open will not open them and
1377
            # they may not be initializable.
1378
            return
1379
        t = get_transport(self.get_url())
1380
        made_control = self.bzrdir_format.initialize(t.base)
1381
        made_repo = made_control.create_repository()
1382
        made_branch = made_control.create_branch()
1508.1.25 by Robert Collins
Update per review comments.
1383
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1384
        self.assertEqual(made_control, made_branch.bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1385
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1386
    def test_open_branch(self):
1387
        if not self.bzrdir_format.is_supported():
1388
            # unsupported formats are not loopback testable
1389
            # because the default open will not open them and
1390
            # they may not be initializable.
1391
            return
1392
        t = get_transport(self.get_url())
1393
        made_control = self.bzrdir_format.initialize(t.base)
1394
        made_repo = made_control.create_repository()
1395
        made_branch = made_control.create_branch()
1396
        opened_branch = made_control.open_branch()
1397
        self.assertEqual(made_control, opened_branch.bzrdir)
1398
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1399
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1400
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1401
    def test_create_repository(self):
1402
        # a bzrdir can construct a repository for itself.
1403
        if not self.bzrdir_format.is_supported():
1404
            # unsupported formats are not loopback testable
1405
            # because the default open will not open them and
1406
            # they may not be initializable.
1407
            return
1408
        t = get_transport(self.get_url())
1409
        made_control = self.bzrdir_format.initialize(t.base)
1410
        made_repo = made_control.create_repository()
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
1411
        # Check that we have a repository object.
1412
        made_repo.has_revision('foo')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1413
        self.assertEqual(made_control, made_repo.bzrdir)
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1414
1415
    def test_create_repository_shared(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1416
        # a bzrdir can create a shared repository or
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1417
        # fail appropriately
1418
        if not self.bzrdir_format.is_supported():
1419
            # unsupported formats are not loopback testable
1420
            # because the default open will not open them and
1421
            # they may not be initializable.
1422
            return
1423
        t = get_transport(self.get_url())
1424
        made_control = self.bzrdir_format.initialize(t.base)
1425
        try:
1426
            made_repo = made_control.create_repository(shared=True)
1427
        except errors.IncompatibleFormat:
1428
            # Old bzrdir formats don't support shared repositories
1429
            # and should raise IncompatibleFormat
1430
            return
1431
        self.assertTrue(made_repo.is_shared())
1432
1433
    def test_create_repository_nonshared(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1434
        # a bzrdir can create a non-shared repository
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1435
        if not self.bzrdir_format.is_supported():
1436
            # unsupported formats are not loopback testable
1437
            # because the default open will not open them and
1438
            # they may not be initializable.
1439
            return
1440
        t = get_transport(self.get_url())
1441
        made_control = self.bzrdir_format.initialize(t.base)
1442
        made_repo = made_control.create_repository(shared=False)
1443
        self.assertFalse(made_repo.is_shared())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1444
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1445
    def test_open_repository(self):
1446
        if not self.bzrdir_format.is_supported():
1447
            # unsupported formats are not loopback testable
1448
            # because the default open will not open them and
1449
            # they may not be initializable.
1450
            return
1451
        t = get_transport(self.get_url())
1452
        made_control = self.bzrdir_format.initialize(t.base)
1453
        made_repo = made_control.create_repository()
1454
        opened_repo = made_control.open_repository()
1455
        self.assertEqual(made_control, opened_repo.bzrdir)
1456
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1457
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1458
1459
    def test_create_workingtree(self):
1460
        # a bzrdir can construct a working tree for itself.
1461
        if not self.bzrdir_format.is_supported():
1462
            # unsupported formats are not loopback testable
1463
            # because the default open will not open them and
1464
            # they may not be initializable.
1465
            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.
1466
        t = self.get_transport()
1910.5.9 by Andrew Bennetts
Move stuff out of a try block that doesn't need to be there.
1467
        made_control = self.bzrdir_format.initialize(t.base)
1468
        made_repo = made_control.create_repository()
1469
        made_branch = made_control.create_branch()
1910.5.11 by Andrew Bennetts
Use createWorkingTreeOrSkip helper in test_create_workingtree.
1470
        made_tree = self.createWorkingTreeOrSkip(made_control)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1471
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1472
        self.assertEqual(made_control, made_tree.bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1473
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1474
    def test_create_workingtree_revision(self):
1475
        # 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.
1476
        t = self.get_transport()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1477
        source = self.make_branch_and_tree('source')
1478
        source.commit('a', rev_id='a', allow_pointless=True)
1479
        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.
1480
        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.
1481
        t_new = t.clone('new')
1482
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1483
        source.branch.repository.clone(made_control)
1484
        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.
1485
        try:
1486
            made_tree = made_control.create_workingtree(revision_id='a')
1487
        except errors.NotLocalUrl:
1488
            raise TestSkipped("Can't make working tree on transport %r" % t)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1489
        self.assertEqual(['a'], made_tree.get_parent_ids())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1490
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1491
    def test_open_workingtree(self):
1492
        if not self.bzrdir_format.is_supported():
1493
            # unsupported formats are not loopback testable
1494
            # because the default open will not open them and
1495
            # they may not be initializable.
1496
            return
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1497
        # 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.
1498
        # format 6 bzrdirs
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1499
        t = self.get_transport()
1500
        try:
1501
            made_control = self.bzrdir_format.initialize(t.base)
1502
            made_repo = made_control.create_repository()
1503
            made_branch = made_control.create_branch()
1504
            made_tree = made_control.create_workingtree()
1505
        except errors.NotLocalUrl:
1506
            raise TestSkipped("Can't initialize %r on transport %r"
1507
                              % (self.bzrdir_format, t))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1508
        opened_tree = made_control.open_workingtree()
1509
        self.assertEqual(made_control, opened_tree.bzrdir)
1510
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1511
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1512
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1513
    def test_get_branch_transport(self):
1514
        dir = self.make_bzrdir('.')
1515
        # without a format, get_branch_transport gives use a transport
1516
        # which -may- point to an existing dir.
1517
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1518
                                   transport.Transport))
1519
        # with a given format, either the bzr dir supports identifiable
1520
        # branches, or it supports anonymous  branch formats, but not both.
1508.1.25 by Robert Collins
Update per review comments.
1521
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1522
        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.
1523
        try:
1524
            found_transport = dir.get_branch_transport(anonymous_format)
1525
            self.assertRaises(errors.IncompatibleFormat,
1526
                              dir.get_branch_transport,
1527
                              identifiable_format)
1528
        except errors.IncompatibleFormat:
1529
            found_transport = dir.get_branch_transport(identifiable_format)
1530
        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.
1531
        # and the dir which has been initialized for us must exist.
1532
        found_transport.list_dir('.')
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1533
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1534
    def test_get_repository_transport(self):
1535
        dir = self.make_bzrdir('.')
1536
        # without a format, get_repository_transport gives use a transport
1537
        # which -may- point to an existing dir.
1538
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1539
                                   transport.Transport))
1540
        # 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.
1541
        # repositories, or it supports anonymous  repository formats, but not both.
1542
        anonymous_format = weaverepo.RepositoryFormat6()
1543
        identifiable_format = weaverepo.RepositoryFormat7()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1544
        try:
1545
            found_transport = dir.get_repository_transport(anonymous_format)
1546
            self.assertRaises(errors.IncompatibleFormat,
1547
                              dir.get_repository_transport,
1548
                              identifiable_format)
1549
        except errors.IncompatibleFormat:
1550
            found_transport = dir.get_repository_transport(identifiable_format)
1551
        self.assertTrue(isinstance(found_transport, transport.Transport))
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
1552
        # and the dir which has been initialized for us must exist.
1553
        found_transport.list_dir('.')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1554
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1555
    def test_get_workingtree_transport(self):
1556
        dir = self.make_bzrdir('.')
1557
        # without a format, get_workingtree_transport gives use a transport
1558
        # which -may- point to an existing dir.
1559
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1560
                                   transport.Transport))
1561
        # with a given format, either the bzr dir supports identifiable
1562
        # trees, or it supports anonymous tree formats, but not both.
1563
        anonymous_format = workingtree.WorkingTreeFormat2()
1564
        identifiable_format = workingtree.WorkingTreeFormat3()
1565
        try:
1566
            found_transport = dir.get_workingtree_transport(anonymous_format)
1567
            self.assertRaises(errors.IncompatibleFormat,
1568
                              dir.get_workingtree_transport,
1569
                              identifiable_format)
1570
        except errors.IncompatibleFormat:
1571
            found_transport = dir.get_workingtree_transport(identifiable_format)
1572
        self.assertTrue(isinstance(found_transport, transport.Transport))
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
1573
        # and the dir which has been initialized for us must exist.
1574
        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.
1575
1576
    def test_root_transport(self):
1577
        dir = self.make_bzrdir('.')
1578
        self.assertEqual(dir.root_transport.base,
1579
                         get_transport(self.get_url('.')).base)
1580
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.
1581
    def test_find_repository_no_repo_under_standalone_branch(self):
1582
        # finding a repo stops at standalone branches even if there is a
1583
        # higher repository available.
1584
        try:
1585
            repo = self.make_repository('.', shared=True)
1586
        except errors.IncompatibleFormat:
1587
            # need a shared repository to test this.
1588
            return
1589
        url = self.get_url('intermediate')
1590
        get_transport(self.get_url()).mkdir('intermediate')
1591
        get_transport(self.get_url()).mkdir('intermediate/child')
1592
        made_control = self.bzrdir_format.initialize(url)
1593
        made_control.create_repository()
1594
        innermost_control = self.bzrdir_format.initialize(
1595
            self.get_url('intermediate/child'))
1596
        try:
1597
            child_repo = innermost_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1598
            # if there is a repository, then the format cannot ever hit this
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.
1599
            # code path.
1600
            return
1601
        except errors.NoRepositoryPresent:
1602
            pass
1603
        self.assertRaises(errors.NoRepositoryPresent,
1604
                          innermost_control.find_repository)
1605
1606
    def test_find_repository_containing_shared_repository(self):
1607
        # find repo inside a shared repo with an empty control dir
1608
        # returns the shared repo.
1609
        try:
1610
            repo = self.make_repository('.', shared=True)
1611
        except errors.IncompatibleFormat:
1612
            # need a shared repository to test this.
1613
            return
1614
        url = self.get_url('childbzrdir')
1615
        get_transport(self.get_url()).mkdir('childbzrdir')
1616
        made_control = self.bzrdir_format.initialize(url)
1617
        try:
1618
            child_repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1619
            # if there is a repository, then the format cannot ever hit this
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.
1620
            # code path.
1621
            return
1622
        except errors.NoRepositoryPresent:
1623
            pass
1624
        found_repo = made_control.find_repository()
1625
        self.assertEqual(repo.bzrdir.root_transport.base,
1626
                         found_repo.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1627
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.
1628
    def test_find_repository_standalone_with_containing_shared_repository(self):
1629
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1630
        try:
1631
            containing_repo = self.make_repository('.', shared=True)
1632
        except errors.IncompatibleFormat:
1633
            # need a shared repository to test this.
1634
            return
1635
        child_repo = self.make_repository('childrepo')
1636
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1637
        found_repo = opened_control.find_repository()
1638
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1639
                         found_repo.bzrdir.root_transport.base)
1640
1641
    def test_find_repository_shared_within_shared_repository(self):
1642
        # find repo at a shared repo inside a shared repo finds the inner repo
1643
        try:
1644
            containing_repo = self.make_repository('.', shared=True)
1645
        except errors.IncompatibleFormat:
1646
            # need a shared repository to test this.
1647
            return
1648
        url = self.get_url('childrepo')
1649
        get_transport(self.get_url()).mkdir('childrepo')
1650
        child_control = self.bzrdir_format.initialize(url)
1651
        child_repo = child_control.create_repository(shared=True)
1652
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1653
        found_repo = opened_control.find_repository()
1654
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1655
                         found_repo.bzrdir.root_transport.base)
1656
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1657
                            containing_repo.bzrdir.root_transport.base)
1658
1659
    def test_find_repository_with_nested_dirs_works(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1660
        # find repo inside a bzrdir inside a bzrdir inside a shared repo
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.
1661
        # finds the outer shared repo.
1662
        try:
1663
            repo = self.make_repository('.', shared=True)
1664
        except errors.IncompatibleFormat:
1665
            # need a shared repository to test this.
1666
            return
1667
        url = self.get_url('intermediate')
1668
        get_transport(self.get_url()).mkdir('intermediate')
1669
        get_transport(self.get_url()).mkdir('intermediate/child')
1670
        made_control = self.bzrdir_format.initialize(url)
1671
        try:
1672
            child_repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1673
            # if there is a repository, then the format cannot ever hit this
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.
1674
            # code path.
1675
            return
1676
        except errors.NoRepositoryPresent:
1677
            pass
1678
        innermost_control = self.bzrdir_format.initialize(
1679
            self.get_url('intermediate/child'))
1680
        try:
1681
            child_repo = innermost_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1682
            # if there is a repository, then the format cannot ever hit this
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.
1683
            # code path.
1684
            return
1685
        except errors.NoRepositoryPresent:
1686
            pass
1687
        found_repo = innermost_control.find_repository()
1688
        self.assertEqual(repo.bzrdir.root_transport.base,
1689
                         found_repo.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1690
1534.5.16 by Robert Collins
Review feedback.
1691
    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.
1692
        # check that we can ask an instance if its upgradable
1693
        dir = self.make_bzrdir('.')
1534.5.16 by Robert Collins
Review feedback.
1694
        if dir.can_convert_format():
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1695
            # if its default updatable there must be an updater
2204.4.14 by Aaron Bentley
lastest -> latest
1696
            # (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
1697
            # available
1698
            self.assertTrue(isinstance(dir._format.get_converter(
1699
                format=dir._format), bzrdir.Converter))
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1700
        dir.needs_format_conversion(
1701
            bzrdir.BzrDirFormat.get_default_format())
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.
1702
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1703
    def test_backup_copies_existing(self):
1704
        tree = self.make_branch_and_tree('test')
1705
        self.build_tree(['test/a'])
1706
        tree.add(['a'], ['a-id'])
1707
        tree.commit('some data to be copied.')
1708
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1709
        old_path = urlutils.local_path_from_url(old_url)
1710
        new_path = urlutils.local_path_from_url(new_url)
1711
        self.failUnlessExists(old_path)
1712
        self.failUnlessExists(new_path)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1713
        for (((dir_relpath1, _), entries1),
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1714
             ((dir_relpath2, _), entries2)) in izip(
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1715
                osutils.walkdirs(old_path),
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1716
                osutils.walkdirs(new_path)):
1717
            self.assertEquals(dir_relpath1, dir_relpath2)
1718
            for f1, f2 in zip(entries1, entries2):
1719
                self.assertEquals(f1[0], f2[0])
1720
                self.assertEquals(f1[2], f2[2])
1721
                if f1[2] == "file":
1722
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1723
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1724
    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.
1725
        """Does an available updater work?"""
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1726
        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.
1727
        # 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.
1728
        dir.create_repository()
1729
        dir.create_branch()
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1730
        self.createWorkingTreeOrSkip(dir)
1534.5.16 by Robert Collins
Review feedback.
1731
        if dir.can_convert_format():
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1732
            # if its default updatable there must be an updater
2204.4.14 by Aaron Bentley
lastest -> latest
1733
            # (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
1734
            # available
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1735
            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.
1736
            try:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1737
                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.
1738
            finally:
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1739
                pb.finished()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1740
            # and it should pass 'check' now.
4332.3.36 by Robert Collins
Silence a warning in test_bzrdir.
1741
            check.check_dwim(self.get_url('.'), False, True, True)
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1742
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1743
    def test_format_description(self):
1744
        dir = self.make_bzrdir('.')
1745
        text = dir._format.get_format_description()
1746
        self.failUnless(len(text))
1747
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1748
    def test_retire_bzrdir(self):
1749
        bd = self.make_bzrdir('.')
2018.5.107 by Andrew Bennetts
Fix test_retire_bzrdir to cope with transports that aren't backed by disk.
1750
        transport = bd.root_transport
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1751
        # 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.
1752
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1753
            transport=transport)
1754
        self.failUnless(transport.has('.bzr'))
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1755
        bd.retire_bzrdir()
2018.5.107 by Andrew Bennetts
Fix test_retire_bzrdir to cope with transports that aren't backed by disk.
1756
        self.failIf(transport.has('.bzr'))
1757
        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.
1758
2830.1.3 by Ian Clatworthy
test that bzrdir retiring fails as expected once limit reached
1759
    def test_retire_bzrdir_limited(self):
1760
        bd = self.make_bzrdir('.')
1761
        transport = bd.root_transport
1762
        # must not overwrite existing directories
1763
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1764
            transport=transport)
1765
        self.failUnless(transport.has('.bzr'))
2830.1.4 by Ian Clatworthy
review tweaks
1766
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1767
            bd.retire_bzrdir, limit=0)
2830.1.3 by Ian Clatworthy
test that bzrdir retiring fails as expected once limit reached
1768
1769
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1770
class TestBreakLock(TestCaseWithBzrDir):
1771
1772
    def setUp(self):
1773
        super(TestBreakLock, self).setUp()
1774
        # we want a UI factory that accepts canned input for the tests:
1775
        # while SilentUIFactory still accepts stdin, we need to customise
1776
        # ours
1777
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
1778
        self.addCleanup(self.restoreFactory)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1779
1687.1.15 by Robert Collins
Review comments.
1780
    def restoreFactory(self):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1781
        bzrlib.ui.ui_factory = self.old_factory
1782
1783
    def test_break_lock_empty(self):
1784
        # break lock on an empty bzrdir should work silently.
1785
        dir = self.make_bzrdir('.')
1786
        try:
1787
            dir.break_lock()
1788
        except NotImplementedError:
1789
            pass
1790
1791
    def test_break_lock_repository(self):
1792
        # break lock with just a repo should unlock the repo.
1793
        repo = self.make_repository('.')
1794
        repo.lock_write()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1795
        lock_repo = repo.bzrdir.open_repository()
1796
        if not lock_repo.get_physical_lock_status():
1797
            # This bzrdir's default repository does not physically lock things
1798
            # and thus this interaction cannot be tested at the interface
1799
            # level.
1800
            repo.unlock()
1801
            return
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1802
        # only one yes needed here: it should only be unlocking
1803
        # the repo
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1804
        bzrlib.ui.ui_factory = CannedInputUIFactory([True])
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1805
        try:
1806
            repo.bzrdir.break_lock()
1807
        except NotImplementedError:
1808
            # this bzrdir does not implement break_lock - so we cant test it.
1809
            repo.unlock()
1810
            return
1811
        lock_repo.lock_write()
1812
        lock_repo.unlock()
1813
        self.assertRaises(errors.LockBroken, repo.unlock)
1814
1815
    def test_break_lock_branch(self):
1816
        # break lock with just a repo should unlock the branch.
1817
        # and not directly try the repository.
1818
        # we test this by making a branch reference to a branch
1819
        # and repository in another bzrdir
1820
        # for pre-metadir formats this will fail, thats ok.
1821
        master = self.make_branch('branch')
1822
        thisdir = self.make_bzrdir('this')
1823
        try:
1824
            bzrlib.branch.BranchReferenceFormat().initialize(
1825
                thisdir, master)
1826
        except errors.IncompatibleFormat:
1827
            return
1828
        unused_repo = thisdir.create_repository()
1829
        master.lock_write()
1830
        unused_repo.lock_write()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1831
        try:
1832
            # two yes's : branch and repository. If the repo in this
1833
            # dir is inappropriately accessed, 3 will be needed, and
1834
            # we'll see that because the stream will be fully consumed
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1835
            bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1836
            # determine if the repository will have been locked;
1837
            this_repo_locked = \
1838
                thisdir.open_repository().get_physical_lock_status()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1839
            master.bzrdir.break_lock()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1840
            if this_repo_locked:
1841
                # only two ys should have been read
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1842
                self.assertEqual([True],
1843
                    bzrlib.ui.ui_factory.responses)
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1844
            else:
1845
                # only one y should have been read
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1846
                self.assertEqual([True, True],
1847
                    bzrlib.ui.ui_factory.responses)
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1848
            # we should be able to lock a newly opened branch now
1849
            branch = master.bzrdir.open_branch()
1850
            branch.lock_write()
1851
            branch.unlock()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1852
            if this_repo_locked:
1853
                # we should not be able to lock the repository in thisdir as
1854
                # its still held by the explicit lock we took, and the break
1855
                # lock should not have touched it.
1856
                repo = thisdir.open_repository()
3287.4.2 by Martin Pool
Change more tests to use reduceLockdirTimeout
1857
                self.assertRaises(errors.LockContention, repo.lock_write)
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1858
        finally:
1859
            unused_repo.unlock()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1860
        self.assertRaises(errors.LockBroken, master.unlock)
1861
1862
    def test_break_lock_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1863
        # break lock with a tree should unlock the tree but not try the
1864
        # branch explicitly. However this is very hard to test for as we
1865
        # dont have a tree reference class, nor is one needed;
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1866
        # the worst case if this code unlocks twice is an extra question
1867
        # being asked.
1868
        tree = self.make_branch_and_tree('.')
1869
        tree.lock_write()
1870
        # three yes's : tree, branch and repository.
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1871
        bzrlib.ui.ui_factory = CannedInputUIFactory([True, True, True])
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1872
        try:
1873
            tree.bzrdir.break_lock()
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1874
        except (NotImplementedError, errors.LockActive):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1875
            # bzrdir does not support break_lock
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1876
            # or one of the locked objects (currently only tree does this)
1877
            # raised a LockActive because we do still have a live locked
1878
            # object.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1879
            tree.unlock()
1880
            return
4449.3.24 by Martin Pool
Fix bzrdir break-lock tests that rely on SilentUIFactory reading stdin
1881
        self.assertEqual([True],
1882
                bzrlib.ui.ui_factory.responses)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1883
        lock_tree = tree.bzrdir.open_workingtree()
1884
        lock_tree.lock_write()
1885
        lock_tree.unlock()
1886
        self.assertRaises(errors.LockBroken, tree.unlock)
1887
1888
3242.1.2 by Aaron Bentley
Turn BzrDirConfig into TransportConfig, reduce code duplication
1889
class TestTransportConfig(TestCaseWithBzrDir):
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
1890
1891
    def test_get_config(self):
1892
        my_dir = self.make_bzrdir('.')
1893
        config = my_dir.get_config()
4288.1.6 by Robert Collins
Fix bzrdir implementation tests to handle read only bzrdir configs.
1894
        try:
1895
            config.set_default_stack_on('http://example.com')
1896
        except errors.BzrError, e:
1897
            if 'Cannot set config' in str(e):
1898
                self.assertFalse(
1899
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1900
                    "%r should support configs" % my_dir)
1901
                raise TestNotApplicable(
1902
                    'This BzrDir format does not support configs.')
1903
            else:
1904
                raise
3242.3.14 by Aaron Bentley
Make BzrDirConfig use TransportConfig
1905
        self.assertEqual('http://example.com', config.get_default_stack_on())
3567.1.2 by Michael Hudson
fix test some more
1906
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
3242.3.36 by Aaron Bentley
Updates from review comments
1907
        config2 = my_dir2.get_config()
3242.3.14 by Aaron Bentley
Make BzrDirConfig use TransportConfig
1908
        self.assertEqual('http://example.com', config2.get_default_stack_on())
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
1909
1910
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.
1911
class ChrootedBzrDirTests(ChrootedTestCase):
1912
1913
    def test_find_repository_no_repository(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1914
        # loopback test to check the current format fails to find a
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.
1915
        # share repository correctly.
1916
        if not self.bzrdir_format.is_supported():
1917
            # unsupported formats are not loopback testable
1918
            # because the default open will not open them and
1919
            # they may not be initializable.
1920
            return
1921
        # 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 :).
1922
        # - do the vfs initialisation over the basic vfs transport
1923
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1924
        url = self.get_vfs_only_url('subdir')
1925
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
1926
        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.
1927
        try:
1928
            repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1929
            # if there is a repository, then the format cannot ever hit this
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.
1930
            # code path.
1931
            return
1932
        except errors.NoRepositoryPresent:
1933
            pass
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1934
        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.
1935
        self.assertRaises(errors.NoRepositoryPresent,
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1936
                          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.
1937