/brz/remove-bazaar

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