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