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