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