/brz/remove-bazaar

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