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