/brz/remove-bazaar

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