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