/brz/remove-bazaar

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