~bzr-pqm/bzr/bzr.dev

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