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