/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
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1249
    def test_format_initialize_on_transport_ex_default_stack_on(self):
1250
        # When initialize_on_transport_ex uses a stacked-on branch because of
1251
        # a stacking policy on the target, the location of the fallback
1252
        # repository is the same as the external location of the stacked-on
1253
        # branch.
1254
        balloon = self.make_bzrdir('balloon')
1255
        if isinstance(balloon, bzrdir.BzrDirMetaFormat1):
1256
            stack_on = self.make_branch('stack-on', format='1.9')
1257
        else:
1258
            stack_on = self.make_branch('stack-on')
1259
        config = self.make_bzrdir('.').get_config()
1260
        try:
1261
            config.set_default_stack_on('stack-on')
1262
        except errors.BzrError:
1263
            raise TestNotApplicable('Only relevant for stackable formats.')
1264
        # Initialize a bzrdir subject to the policy.
1265
        t = self.get_transport('stacked')
1266
        repo_fmt = bzrdir.format_registry.make_bzrdir('1.9')
1267
        repo_name = repo_fmt.repository_format.network_name()
1268
        repo, control = self.assertInitializeEx(
1269
            t, need_meta=True, repo_format_name=repo_name, stacked_on=None)
1270
        if control is None:
1271
            # uninitialisable format
1272
            return
1273
        # There's one fallback repo, with a public location.
1274
        self.assertLength(1, repo._fallback_repositories)
1275
        fallback_repo = repo._fallback_repositories[0]
1276
        self.assertEqual(
1277
            stack_on.base, fallback_repo.bzrdir.root_transport.base)
4456.2.1 by Andrew Bennetts
Fix automatic branch format upgrades triggered by a default stacking policy on a 1.16rc1 (or later) smart server.
1278
        # The bzrdir creates a branch in stacking-capable format.
1279
        new_branch = control.create_branch()
1280
        self.assertTrue(new_branch._format.supports_stacking())
4416.3.6 by Jonathan Lange
Failing test that reproduces the error at a low level.
1281
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1282
    def test_format_initialize_on_transport_ex_repo_fmt_name_None(self):
1283
        t = self.get_transport('dir')
1284
        repo, control = self.assertInitializeEx(t)
1285
        self.assertEqual(None, repo)
1286
1287
    def test_format_initialize_on_transport_ex_repo_fmt_name_followed(self):
1288
        t = self.get_transport('dir')
4294.2.10 by Robert Collins
Review feedback.
1289
        # 1.6 is likely to never be default
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1290
        fmt = bzrdir.format_registry.make_bzrdir('1.6')
1291
        repo_name = fmt.repository_format.network_name()
1292
        repo, control = self.assertInitializeEx(t, repo_format_name=repo_name)
1293
        if control is None:
1294
            # uninitialisable format
1295
            return
1296
        if isinstance(self.bzrdir_format, (bzrdir.BzrDirFormat5,
1297
            bzrdir.BzrDirFormat6)):
1298
            # must stay with the all-in-one-format.
1299
            repo_name = self.bzrdir_format.network_name()
1300
        self.assertEqual(repo_name, repo._format.network_name())
4307.2.2 by Robert Collins
Lock repositories created by BzrDirFormat.initialize_on_transport_ex.
1301
        # New repositories are write locked.
1302
        self.assertTrue(repo.is_write_locked())
1303
        repo.unlock()
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1304
1305
    def assertInitializeEx(self, t, need_meta=False, **kwargs):
1306
        """Execute initialize_on_transport_ex and check it succeeded correctly.
1307
4294.2.10 by Robert Collins
Review feedback.
1308
        This involves checking that the disk objects were created, open with
1309
        the same format returned, and had the expected disk format.
1310
4294.2.5 by Robert Collins
Reasonable unit test coverage for initialize_on_transport_ex.
1311
        :param t: The transport to initialize on.
1312
        :param **kwargs: Additional arguments to pass to
1313
            initialize_on_transport_ex.
1314
        :return: the resulting repo, control dir tuple.
1315
        """
1316
        if not self.bzrdir_format.is_supported():
1317
            # Not initializable - not a failure either.
1318
            return None, None
1319
        repo, control, require_stacking, repo_policy = \
1320
            self.bzrdir_format.initialize_on_transport_ex(t, **kwargs)
1321
        self.assertIsInstance(control, bzrdir.BzrDir)
1322
        opened = bzrdir.BzrDir.open(t.base)
1323
        expected_format = self.bzrdir_format
1324
        if isinstance(expected_format, bzrdir.RemoteBzrDirFormat):
4294.2.10 by Robert Collins
Review feedback.
1325
            # Current RemoteBzrDirFormat's do not reliably get network_name
1326
            # 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.
1327
            self.assertIsInstance(control, RemoteBzrDir)
1328
        else:
1329
            if need_meta and isinstance(expected_format, (bzrdir.BzrDirFormat5,
1330
                bzrdir.BzrDirFormat6)):
1331
                # Pre-metadir formats change when we are making something that
1332
                # needs a metaformat, because clone is used for push.
1333
                expected_format = bzrdir.BzrDirMetaFormat1()
1334
            self.assertEqual(control._format.network_name(),
1335
                expected_format.network_name())
1336
            self.assertEqual(control._format.network_name(),
1337
                opened._format.network_name())
1338
        self.assertEqual(control.__class__, opened.__class__)
1339
        return repo, control
1340
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1341
    def test_format_network_name(self):
1342
        # All control formats must have a network name.
1343
        dir = self.make_bzrdir('.')
1344
        format = dir._format
1345
        # We want to test that the network_name matches the actual format on
1346
        # disk. For local control dirsthat means that using network_name as a
1347
        # key in the registry gives back the same format. For remote obects
1348
        # we check that the network_name of the RemoteBzrDirFormat we have
1349
        # locally matches the actual format present on disk.
1350
        if isinstance(format, bzrdir.RemoteBzrDirFormat):
1351
            dir._ensure_real()
1352
            real_dir = dir._real_bzrdir
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1353
            network_name = format.network_name()
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1354
            self.assertEqual(real_dir._format.network_name(), network_name)
1355
        else:
1356
            registry = bzrdir.network_format_registry
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1357
            network_name = format.network_name()
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1358
            looked_up_format = registry.get(network_name)
1359
            self.assertEqual(format.__class__, looked_up_format.__class__)
4070.2.3 by Robert Collins
Get BzrDir.cloning_metadir working.
1360
        # The network name must be a byte string.
1361
        self.assertIsInstance(network_name, str)
4070.2.1 by Robert Collins
Add a BzrDirFormat.network_name.
1362
1534.4.39 by Robert Collins
Basic BzrDir support.
1363
    def test_open_not_bzrdir(self):
1364
        # test the formats specific behaviour for no-content or similar dirs.
1365
        self.assertRaises(NotBranchError,
1366
                          self.bzrdir_format.open,
1367
                          get_transport(self.get_readonly_url()))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1368
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1369
    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.
1370
        # a bzrdir can construct a branch and repository for itself.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1371
        if not self.bzrdir_format.is_supported():
1372
            # unsupported formats are not loopback testable
1373
            # because the default open will not open them and
1374
            # they may not be initializable.
1375
            return
1376
        t = get_transport(self.get_url())
1377
        made_control = self.bzrdir_format.initialize(t.base)
1378
        made_repo = made_control.create_repository()
1379
        made_branch = made_control.create_branch()
1508.1.25 by Robert Collins
Update per review comments.
1380
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1381
        self.assertEqual(made_control, made_branch.bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1382
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1383
    def test_open_branch(self):
1384
        if not self.bzrdir_format.is_supported():
1385
            # unsupported formats are not loopback testable
1386
            # because the default open will not open them and
1387
            # they may not be initializable.
1388
            return
1389
        t = get_transport(self.get_url())
1390
        made_control = self.bzrdir_format.initialize(t.base)
1391
        made_repo = made_control.create_repository()
1392
        made_branch = made_control.create_branch()
1393
        opened_branch = made_control.open_branch()
1394
        self.assertEqual(made_control, opened_branch.bzrdir)
1395
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1396
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1397
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1398
    def test_create_repository(self):
1399
        # a bzrdir can construct a repository for itself.
1400
        if not self.bzrdir_format.is_supported():
1401
            # unsupported formats are not loopback testable
1402
            # because the default open will not open them and
1403
            # they may not be initializable.
1404
            return
1405
        t = get_transport(self.get_url())
1406
        made_control = self.bzrdir_format.initialize(t.base)
1407
        made_repo = made_control.create_repository()
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
1408
        # Check that we have a repository object.
1409
        made_repo.has_revision('foo')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1410
        self.assertEqual(made_control, made_repo.bzrdir)
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1411
1412
    def test_create_repository_shared(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1413
        # a bzrdir can create a shared repository or
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1414
        # fail appropriately
1415
        if not self.bzrdir_format.is_supported():
1416
            # unsupported formats are not loopback testable
1417
            # because the default open will not open them and
1418
            # they may not be initializable.
1419
            return
1420
        t = get_transport(self.get_url())
1421
        made_control = self.bzrdir_format.initialize(t.base)
1422
        try:
1423
            made_repo = made_control.create_repository(shared=True)
1424
        except errors.IncompatibleFormat:
1425
            # Old bzrdir formats don't support shared repositories
1426
            # and should raise IncompatibleFormat
1427
            return
1428
        self.assertTrue(made_repo.is_shared())
1429
1430
    def test_create_repository_nonshared(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1431
        # a bzrdir can create a non-shared repository
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1432
        if not self.bzrdir_format.is_supported():
1433
            # unsupported formats are not loopback testable
1434
            # because the default open will not open them and
1435
            # they may not be initializable.
1436
            return
1437
        t = get_transport(self.get_url())
1438
        made_control = self.bzrdir_format.initialize(t.base)
1439
        made_repo = made_control.create_repository(shared=False)
1440
        self.assertFalse(made_repo.is_shared())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1441
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1442
    def test_open_repository(self):
1443
        if not self.bzrdir_format.is_supported():
1444
            # unsupported formats are not loopback testable
1445
            # because the default open will not open them and
1446
            # they may not be initializable.
1447
            return
1448
        t = get_transport(self.get_url())
1449
        made_control = self.bzrdir_format.initialize(t.base)
1450
        made_repo = made_control.create_repository()
1451
        opened_repo = made_control.open_repository()
1452
        self.assertEqual(made_control, opened_repo.bzrdir)
1453
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1454
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1455
1456
    def test_create_workingtree(self):
1457
        # a bzrdir can construct a working tree for itself.
1458
        if not self.bzrdir_format.is_supported():
1459
            # unsupported formats are not loopback testable
1460
            # because the default open will not open them and
1461
            # they may not be initializable.
1462
            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.
1463
        t = self.get_transport()
1910.5.9 by Andrew Bennetts
Move stuff out of a try block that doesn't need to be there.
1464
        made_control = self.bzrdir_format.initialize(t.base)
1465
        made_repo = made_control.create_repository()
1466
        made_branch = made_control.create_branch()
1910.5.11 by Andrew Bennetts
Use createWorkingTreeOrSkip helper in test_create_workingtree.
1467
        made_tree = self.createWorkingTreeOrSkip(made_control)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1468
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1469
        self.assertEqual(made_control, made_tree.bzrdir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1470
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1471
    def test_create_workingtree_revision(self):
1472
        # 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.
1473
        t = self.get_transport()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1474
        source = self.make_branch_and_tree('source')
1475
        source.commit('a', rev_id='a', allow_pointless=True)
1476
        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.
1477
        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.
1478
        t_new = t.clone('new')
1479
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1480
        source.branch.repository.clone(made_control)
1481
        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.
1482
        try:
1483
            made_tree = made_control.create_workingtree(revision_id='a')
1484
        except errors.NotLocalUrl:
1485
            raise TestSkipped("Can't make working tree on transport %r" % t)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1486
        self.assertEqual(['a'], made_tree.get_parent_ids())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1487
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1488
    def test_open_workingtree(self):
1489
        if not self.bzrdir_format.is_supported():
1490
            # unsupported formats are not loopback testable
1491
            # because the default open will not open them and
1492
            # they may not be initializable.
1493
            return
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1494
        # 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.
1495
        # format 6 bzrdirs
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
1496
        t = self.get_transport()
1497
        try:
1498
            made_control = self.bzrdir_format.initialize(t.base)
1499
            made_repo = made_control.create_repository()
1500
            made_branch = made_control.create_branch()
1501
            made_tree = made_control.create_workingtree()
1502
        except errors.NotLocalUrl:
1503
            raise TestSkipped("Can't initialize %r on transport %r"
1504
                              % (self.bzrdir_format, t))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1505
        opened_tree = made_control.open_workingtree()
1506
        self.assertEqual(made_control, opened_tree.bzrdir)
1507
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1508
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1509
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1510
    def test_get_branch_transport(self):
1511
        dir = self.make_bzrdir('.')
1512
        # without a format, get_branch_transport gives use a transport
1513
        # which -may- point to an existing dir.
1514
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1515
                                   transport.Transport))
1516
        # with a given format, either the bzr dir supports identifiable
1517
        # branches, or it supports anonymous  branch formats, but not both.
1508.1.25 by Robert Collins
Update per review comments.
1518
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1519
        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.
1520
        try:
1521
            found_transport = dir.get_branch_transport(anonymous_format)
1522
            self.assertRaises(errors.IncompatibleFormat,
1523
                              dir.get_branch_transport,
1524
                              identifiable_format)
1525
        except errors.IncompatibleFormat:
1526
            found_transport = dir.get_branch_transport(identifiable_format)
1527
        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.
1528
        # and the dir which has been initialized for us must exist.
1529
        found_transport.list_dir('.')
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1530
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1531
    def test_get_repository_transport(self):
1532
        dir = self.make_bzrdir('.')
1533
        # without a format, get_repository_transport gives use a transport
1534
        # which -may- point to an existing dir.
1535
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1536
                                   transport.Transport))
1537
        # 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.
1538
        # repositories, or it supports anonymous  repository formats, but not both.
1539
        anonymous_format = weaverepo.RepositoryFormat6()
1540
        identifiable_format = weaverepo.RepositoryFormat7()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1541
        try:
1542
            found_transport = dir.get_repository_transport(anonymous_format)
1543
            self.assertRaises(errors.IncompatibleFormat,
1544
                              dir.get_repository_transport,
1545
                              identifiable_format)
1546
        except errors.IncompatibleFormat:
1547
            found_transport = dir.get_repository_transport(identifiable_format)
1548
        self.assertTrue(isinstance(found_transport, transport.Transport))
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
1549
        # and the dir which has been initialized for us must exist.
1550
        found_transport.list_dir('.')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1551
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1552
    def test_get_workingtree_transport(self):
1553
        dir = self.make_bzrdir('.')
1554
        # without a format, get_workingtree_transport gives use a transport
1555
        # which -may- point to an existing dir.
1556
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1557
                                   transport.Transport))
1558
        # with a given format, either the bzr dir supports identifiable
1559
        # trees, or it supports anonymous tree formats, but not both.
1560
        anonymous_format = workingtree.WorkingTreeFormat2()
1561
        identifiable_format = workingtree.WorkingTreeFormat3()
1562
        try:
1563
            found_transport = dir.get_workingtree_transport(anonymous_format)
1564
            self.assertRaises(errors.IncompatibleFormat,
1565
                              dir.get_workingtree_transport,
1566
                              identifiable_format)
1567
        except errors.IncompatibleFormat:
1568
            found_transport = dir.get_workingtree_transport(identifiable_format)
1569
        self.assertTrue(isinstance(found_transport, transport.Transport))
1752.2.43 by Andrew Bennetts
Fix get_{branch,repository,workingtree}_transport.
1570
        # and the dir which has been initialized for us must exist.
1571
        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.
1572
1573
    def test_root_transport(self):
1574
        dir = self.make_bzrdir('.')
1575
        self.assertEqual(dir.root_transport.base,
1576
                         get_transport(self.get_url('.')).base)
1577
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.
1578
    def test_find_repository_no_repo_under_standalone_branch(self):
1579
        # finding a repo stops at standalone branches even if there is a
1580
        # higher repository available.
1581
        try:
1582
            repo = self.make_repository('.', shared=True)
1583
        except errors.IncompatibleFormat:
1584
            # need a shared repository to test this.
1585
            return
1586
        url = self.get_url('intermediate')
1587
        get_transport(self.get_url()).mkdir('intermediate')
1588
        get_transport(self.get_url()).mkdir('intermediate/child')
1589
        made_control = self.bzrdir_format.initialize(url)
1590
        made_control.create_repository()
1591
        innermost_control = self.bzrdir_format.initialize(
1592
            self.get_url('intermediate/child'))
1593
        try:
1594
            child_repo = innermost_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1595
            # 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.
1596
            # code path.
1597
            return
1598
        except errors.NoRepositoryPresent:
1599
            pass
1600
        self.assertRaises(errors.NoRepositoryPresent,
1601
                          innermost_control.find_repository)
1602
1603
    def test_find_repository_containing_shared_repository(self):
1604
        # find repo inside a shared repo with an empty control dir
1605
        # returns the shared repo.
1606
        try:
1607
            repo = self.make_repository('.', shared=True)
1608
        except errors.IncompatibleFormat:
1609
            # need a shared repository to test this.
1610
            return
1611
        url = self.get_url('childbzrdir')
1612
        get_transport(self.get_url()).mkdir('childbzrdir')
1613
        made_control = self.bzrdir_format.initialize(url)
1614
        try:
1615
            child_repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1616
            # 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.
1617
            # code path.
1618
            return
1619
        except errors.NoRepositoryPresent:
1620
            pass
1621
        found_repo = made_control.find_repository()
1622
        self.assertEqual(repo.bzrdir.root_transport.base,
1623
                         found_repo.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1624
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
    def test_find_repository_standalone_with_containing_shared_repository(self):
1626
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1627
        try:
1628
            containing_repo = self.make_repository('.', shared=True)
1629
        except errors.IncompatibleFormat:
1630
            # need a shared repository to test this.
1631
            return
1632
        child_repo = self.make_repository('childrepo')
1633
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1634
        found_repo = opened_control.find_repository()
1635
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1636
                         found_repo.bzrdir.root_transport.base)
1637
1638
    def test_find_repository_shared_within_shared_repository(self):
1639
        # find repo at a shared repo inside a shared repo finds the inner repo
1640
        try:
1641
            containing_repo = self.make_repository('.', shared=True)
1642
        except errors.IncompatibleFormat:
1643
            # need a shared repository to test this.
1644
            return
1645
        url = self.get_url('childrepo')
1646
        get_transport(self.get_url()).mkdir('childrepo')
1647
        child_control = self.bzrdir_format.initialize(url)
1648
        child_repo = child_control.create_repository(shared=True)
1649
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1650
        found_repo = opened_control.find_repository()
1651
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1652
                         found_repo.bzrdir.root_transport.base)
1653
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1654
                            containing_repo.bzrdir.root_transport.base)
1655
1656
    def test_find_repository_with_nested_dirs_works(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1657
        # 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.
1658
        # finds the outer shared repo.
1659
        try:
1660
            repo = self.make_repository('.', shared=True)
1661
        except errors.IncompatibleFormat:
1662
            # need a shared repository to test this.
1663
            return
1664
        url = self.get_url('intermediate')
1665
        get_transport(self.get_url()).mkdir('intermediate')
1666
        get_transport(self.get_url()).mkdir('intermediate/child')
1667
        made_control = self.bzrdir_format.initialize(url)
1668
        try:
1669
            child_repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1670
            # 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.
1671
            # code path.
1672
            return
1673
        except errors.NoRepositoryPresent:
1674
            pass
1675
        innermost_control = self.bzrdir_format.initialize(
1676
            self.get_url('intermediate/child'))
1677
        try:
1678
            child_repo = innermost_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1679
            # 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.
1680
            # code path.
1681
            return
1682
        except errors.NoRepositoryPresent:
1683
            pass
1684
        found_repo = innermost_control.find_repository()
1685
        self.assertEqual(repo.bzrdir.root_transport.base,
1686
                         found_repo.bzrdir.root_transport.base)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1687
1534.5.16 by Robert Collins
Review feedback.
1688
    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.
1689
        # check that we can ask an instance if its upgradable
1690
        dir = self.make_bzrdir('.')
1534.5.16 by Robert Collins
Review feedback.
1691
        if dir.can_convert_format():
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1692
            # if its default updatable there must be an updater
2204.4.14 by Aaron Bentley
lastest -> latest
1693
            # (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
1694
            # available
1695
            self.assertTrue(isinstance(dir._format.get_converter(
1696
                format=dir._format), bzrdir.Converter))
3943.2.5 by Martin Pool
deprecate needs_format_conversion(format=None)
1697
        dir.needs_format_conversion(
1698
            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.
1699
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1700
    def test_backup_copies_existing(self):
1701
        tree = self.make_branch_and_tree('test')
1702
        self.build_tree(['test/a'])
1703
        tree.add(['a'], ['a-id'])
1704
        tree.commit('some data to be copied.')
1705
        old_url, new_url = tree.bzrdir.backup_bzrdir()
1706
        old_path = urlutils.local_path_from_url(old_url)
1707
        new_path = urlutils.local_path_from_url(new_url)
1708
        self.failUnlessExists(old_path)
1709
        self.failUnlessExists(new_path)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1710
        for (((dir_relpath1, _), entries1),
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1711
             ((dir_relpath2, _), entries2)) in izip(
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1712
                osutils.walkdirs(old_path),
3872.3.3 by Jelmer Vernooij
Add test for backup_bzrdir.
1713
                osutils.walkdirs(new_path)):
1714
            self.assertEquals(dir_relpath1, dir_relpath2)
1715
            for f1, f2 in zip(entries1, entries2):
1716
                self.assertEquals(f1[0], f2[0])
1717
                self.assertEquals(f1[2], f2[2])
1718
                if f1[2] == "file":
1719
                    osutils.compare_files(open(f1[4]), open(f2[4]))
1720
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1721
    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.
1722
        """Does an available updater work?"""
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1723
        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.
1724
        # 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.
1725
        dir.create_repository()
1726
        dir.create_branch()
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1727
        self.createWorkingTreeOrSkip(dir)
1534.5.16 by Robert Collins
Review feedback.
1728
        if dir.can_convert_format():
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1729
            # if its default updatable there must be an updater
2204.4.14 by Aaron Bentley
lastest -> latest
1730
            # (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
1731
            # available
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1732
            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.
1733
            try:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1734
                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.
1735
            finally:
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1736
                pb.finished()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1737
            # and it should pass 'check' now.
3015.3.7 by Daniel Watkins
Fixed failing tests.
1738
            check_branch(bzrdir.BzrDir.open(self.get_url('.')).open_branch(),
1739
                         False)
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1740
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1741
    def test_format_description(self):
1742
        dir = self.make_bzrdir('.')
1743
        text = dir._format.get_format_description()
1744
        self.failUnless(len(text))
1745
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1746
    def test_retire_bzrdir(self):
1747
        bd = self.make_bzrdir('.')
2018.5.107 by Andrew Bennetts
Fix test_retire_bzrdir to cope with transports that aren't backed by disk.
1748
        transport = bd.root_transport
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1749
        # 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.
1750
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1751
            transport=transport)
1752
        self.failUnless(transport.has('.bzr'))
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1753
        bd.retire_bzrdir()
2018.5.107 by Andrew Bennetts
Fix test_retire_bzrdir to cope with transports that aren't backed by disk.
1754
        self.failIf(transport.has('.bzr'))
1755
        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.
1756
2830.1.3 by Ian Clatworthy
test that bzrdir retiring fails as expected once limit reached
1757
    def test_retire_bzrdir_limited(self):
1758
        bd = self.make_bzrdir('.')
1759
        transport = bd.root_transport
1760
        # must not overwrite existing directories
1761
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',],
1762
            transport=transport)
1763
        self.failUnless(transport.has('.bzr'))
2830.1.4 by Ian Clatworthy
review tweaks
1764
        self.assertRaises((errors.FileExists, errors.DirectoryNotEmpty),
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1765
            bd.retire_bzrdir, limit=0)
2830.1.3 by Ian Clatworthy
test that bzrdir retiring fails as expected once limit reached
1766
1767
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1768
class TestBreakLock(TestCaseWithBzrDir):
1769
1770
    def setUp(self):
1771
        super(TestBreakLock, self).setUp()
1772
        # we want a UI factory that accepts canned input for the tests:
1773
        # while SilentUIFactory still accepts stdin, we need to customise
1774
        # ours
1775
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
1776
        self.addCleanup(self.restoreFactory)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1777
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1778
1687.1.15 by Robert Collins
Review comments.
1779
    def restoreFactory(self):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1780
        bzrlib.ui.ui_factory = self.old_factory
1781
1782
    def test_break_lock_empty(self):
1783
        # break lock on an empty bzrdir should work silently.
1784
        dir = self.make_bzrdir('.')
1785
        try:
1786
            dir.break_lock()
1787
        except NotImplementedError:
1788
            pass
1789
1790
    def test_break_lock_repository(self):
1791
        # break lock with just a repo should unlock the repo.
1792
        repo = self.make_repository('.')
1793
        repo.lock_write()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1794
        lock_repo = repo.bzrdir.open_repository()
1795
        if not lock_repo.get_physical_lock_status():
1796
            # This bzrdir's default repository does not physically lock things
1797
            # and thus this interaction cannot be tested at the interface
1798
            # level.
1799
            repo.unlock()
1800
            return
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1801
        # only one yes needed here: it should only be unlocking
1802
        # the repo
1803
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1804
        try:
1805
            repo.bzrdir.break_lock()
1806
        except NotImplementedError:
1807
            # this bzrdir does not implement break_lock - so we cant test it.
1808
            repo.unlock()
1809
            return
1810
        lock_repo.lock_write()
1811
        lock_repo.unlock()
1812
        self.assertRaises(errors.LockBroken, repo.unlock)
1813
1814
    def test_break_lock_branch(self):
1815
        # break lock with just a repo should unlock the branch.
1816
        # and not directly try the repository.
1817
        # we test this by making a branch reference to a branch
1818
        # and repository in another bzrdir
1819
        # for pre-metadir formats this will fail, thats ok.
1820
        master = self.make_branch('branch')
1821
        thisdir = self.make_bzrdir('this')
1822
        try:
1823
            bzrlib.branch.BranchReferenceFormat().initialize(
1824
                thisdir, master)
1825
        except errors.IncompatibleFormat:
1826
            return
1827
        unused_repo = thisdir.create_repository()
1828
        master.lock_write()
1829
        unused_repo.lock_write()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1830
        try:
1831
            # two yes's : branch and repository. If the repo in this
1832
            # dir is inappropriately accessed, 3 will be needed, and
1833
            # we'll see that because the stream will be fully consumed
1834
            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.
1835
            # determine if the repository will have been locked;
1836
            this_repo_locked = \
1837
                thisdir.open_repository().get_physical_lock_status()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1838
            master.bzrdir.break_lock()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1839
            if this_repo_locked:
1840
                # only two ys should have been read
1841
                self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1842
            else:
1843
                # only one y should have been read
1844
                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.
1845
            # we should be able to lock a newly opened branch now
1846
            branch = master.bzrdir.open_branch()
1847
            branch.lock_write()
1848
            branch.unlock()
3015.2.2 by Robert Collins
Make test_bzrdir work with packs - which always change the pack value during clone.
1849
            if this_repo_locked:
1850
                # we should not be able to lock the repository in thisdir as
1851
                # its still held by the explicit lock we took, and the break
1852
                # lock should not have touched it.
1853
                repo = thisdir.open_repository()
3287.4.2 by Martin Pool
Change more tests to use reduceLockdirTimeout
1854
                self.assertRaises(errors.LockContention, repo.lock_write)
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1855
        finally:
1856
            unused_repo.unlock()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1857
        self.assertRaises(errors.LockBroken, master.unlock)
1858
1859
    def test_break_lock_tree(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1860
        # break lock with a tree should unlock the tree but not try the
1861
        # branch explicitly. However this is very hard to test for as we
1862
        # dont have a tree reference class, nor is one needed;
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1863
        # the worst case if this code unlocks twice is an extra question
1864
        # being asked.
1865
        tree = self.make_branch_and_tree('.')
1866
        tree.lock_write()
1867
        # three yes's : tree, branch and repository.
1868
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1869
        try:
1870
            tree.bzrdir.break_lock()
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1871
        except (NotImplementedError, errors.LockActive):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1872
            # bzrdir does not support break_lock
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1873
            # or one of the locked objects (currently only tree does this)
1874
            # raised a LockActive because we do still have a live locked
1875
            # object.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1876
            tree.unlock()
1877
            return
1878
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1879
        lock_tree = tree.bzrdir.open_workingtree()
1880
        lock_tree.lock_write()
1881
        lock_tree.unlock()
1882
        self.assertRaises(errors.LockBroken, tree.unlock)
1883
1884
3242.1.2 by Aaron Bentley
Turn BzrDirConfig into TransportConfig, reduce code duplication
1885
class TestTransportConfig(TestCaseWithBzrDir):
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
1886
1887
    def test_get_config(self):
1888
        my_dir = self.make_bzrdir('.')
1889
        config = my_dir.get_config()
4288.1.6 by Robert Collins
Fix bzrdir implementation tests to handle read only bzrdir configs.
1890
        try:
1891
            config.set_default_stack_on('http://example.com')
1892
        except errors.BzrError, e:
1893
            if 'Cannot set config' in str(e):
1894
                self.assertFalse(
1895
                    isinstance(my_dir, (bzrdir.BzrDirMeta1, RemoteBzrDir)),
1896
                    "%r should support configs" % my_dir)
1897
                raise TestNotApplicable(
1898
                    'This BzrDir format does not support configs.')
1899
            else:
1900
                raise
3242.3.14 by Aaron Bentley
Make BzrDirConfig use TransportConfig
1901
        self.assertEqual('http://example.com', config.get_default_stack_on())
3567.1.2 by Michael Hudson
fix test some more
1902
        my_dir2 = bzrdir.BzrDir.open(self.get_url('.'))
3242.3.36 by Aaron Bentley
Updates from review comments
1903
        config2 = my_dir2.get_config()
3242.3.14 by Aaron Bentley
Make BzrDirConfig use TransportConfig
1904
        self.assertEqual('http://example.com', config2.get_default_stack_on())
3242.1.1 by Aaron Bentley
Implement BzrDir configuration
1905
1906
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.
1907
class ChrootedBzrDirTests(ChrootedTestCase):
1908
1909
    def test_find_repository_no_repository(self):
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1910
        # 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.
1911
        # share repository correctly.
1912
        if not self.bzrdir_format.is_supported():
1913
            # unsupported formats are not loopback testable
1914
            # because the default open will not open them and
1915
            # they may not be initializable.
1916
            return
1917
        # 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 :).
1918
        # - do the vfs initialisation over the basic vfs transport
1919
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1920
        url = self.get_vfs_only_url('subdir')
1921
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
1922
        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.
1923
        try:
1924
            repo = made_control.open_repository()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
1925
            # 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.
1926
            # code path.
1927
            return
1928
        except errors.NoRepositoryPresent:
1929
            pass
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1930
        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.
1931
        self.assertRaises(errors.NoRepositoryPresent,
2018.5.42 by Robert Collins
Various hopefully improvements, but wsgi is broken, handing over to spiv :).
1932
                          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.
1933