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