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