/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
1534.4.39 by Robert Collins
Basic BzrDir support.
21
import os
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
22
from stat import S_ISDIR
1534.4.39 by Robert Collins
Basic BzrDir support.
23
import sys
24
1508.1.25 by Robert Collins
Update per review comments.
25
import bzrlib.branch
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
26
from bzrlib import (
27
    bzrdir,
28
    errors,
29
    lockdir,
30
    repository,
31
    transactions,
32
    transport,
33
    ui,
34
    workingtree,
35
    )
1534.4.39 by Robert Collins
Basic BzrDir support.
36
from bzrlib.branch import Branch, needs_read_lock, needs_write_lock
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
37
from bzrlib.check import check
1534.4.39 by Robert Collins
Basic BzrDir support.
38
from bzrlib.errors import (FileExists,
39
                           NoSuchRevision,
40
                           NoSuchFile,
41
                           UninitializableFormat,
42
                           NotBranchError,
43
                           )
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
44
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.
45
from bzrlib.tests import (
46
                          ChrootedTestCase,
47
                          TestCase,
48
                          TestCaseWithTransport,
49
                          TestSkipped,
50
                          )
1534.4.39 by Robert Collins
Basic BzrDir support.
51
from bzrlib.trace import mutter
52
from bzrlib.transport import get_transport
53
from bzrlib.upgrade import upgrade
2241.1.4 by Martin Pool
Moved old weave-based repository formats into bzrlib.repofmt.weaverepo.
54
from bzrlib.repofmt import weaverepo
1534.4.39 by Robert Collins
Basic BzrDir support.
55
56
57
class TestCaseWithBzrDir(TestCaseWithTransport):
58
59
    def setUp(self):
60
        super(TestCaseWithBzrDir, self).setUp()
61
        self.bzrdir = None
62
63
    def get_bzrdir(self):
64
        if self.bzrdir is None:
65
            self.bzrdir = self.make_bzrdir(None)
66
        return self.bzrdir
67
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
68
    def make_bzrdir(self, relpath, format=None):
69
        return super(TestCaseWithBzrDir, self).make_bzrdir(
70
            relpath, format=self.bzrdir_format)
71
1534.4.39 by Robert Collins
Basic BzrDir support.
72
73
74
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.
75
    # Many of these tests test for disk equality rather than checking
76
    # for semantic equivalence. This works well for some tests but
77
    # is not good at handling changes in representation or the addition
78
    # or removal of control data. It would be nice to for instance:
79
    # sprout a new branch, check that the nickname has been reset by hand
80
    # and then set the nickname to match the source branch, at which point
81
    # a semantic equivalence should pass
82
83
    def assertDirectoriesEqual(self, source, target, ignore_list=[]):
84
        """Assert that the content of source and target are identical.
85
86
        paths in ignore list will be completely ignored.
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
87
        
88
        We ignore paths that represent data which is allowed to change during
89
        a clone or sprout: for instance, inventory.knit contains gzip fragements
90
        which have timestamps in them, and as we have read the inventory from 
91
        the source knit, the already-read data is recompressed rather than
92
        reading it again, which leads to changed timestamps. This is ok though,
93
        because the inventory.kndx file is not ignored, and the integrity of
94
        knit joins is tested by test_knit and test_versionedfile.
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
95
        """
96
        files = []
97
        directories = ['.']
98
        while directories:
99
            dir = directories.pop()
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
100
            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.
101
                path = dir + '/' + path
102
                if path in ignore_list:
103
                    continue
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
104
                try:
105
                    stat = source.stat(path)
2230.3.30 by Aaron Bentley
Fix whitespace issues
106
                except errors.NoSuchFile:
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
107
                    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.
108
                if S_ISDIR(stat.st_mode):
109
                    self.assertTrue(S_ISDIR(target.stat(path).st_mode))
110
                    directories.append(path)
111
                else:
112
                    self.assertEqualDiff(source.get(path).read(),
113
                                         target.get(path).read(),
114
                                         "text for file %r differs:\n" % path)
115
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
116
    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.
117
        """Raises TestSkipped if a_bzrdir doesn't have a working tree.
118
        
119
        If the bzrdir does have a workingtree, this is a no-op.
120
        """
121
        try:
122
            a_bzrdir.open_workingtree()
123
        except (errors.NotLocalUrl, errors.NoWorkingTree):
124
            raise TestSkipped("bzrdir on transport %r has no working tree"
125
                              % a_bzrdir.transport)
126
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
127
    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.
128
        """Create a working tree on a_bzrdir, or raise TestSkipped.
129
        
130
        A simple wrapper for create_workingtree that translates NotLocalUrl into
131
        TestSkipped.  Returns the newly created working tree.
132
        """
133
        try:
134
            return a_bzrdir.create_workingtree()
135
        except errors.NotLocalUrl:
136
            raise TestSkipped("cannot make working tree with transport %r"
137
                              % a_bzrdir.transport)
138
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
139
    def sproutOrSkip(self, from_bzrdir, to_url, revision_id=None, basis=None,
140
                     force_new_repo=False):
141
        """Sprout from_bzrdir into to_url, or raise TestSkipped.
142
        
143
        A simple wrapper for from_bzrdir.sprout that translates NotLocalUrl into
144
        TestSkipped.  Returns the newly sprouted bzrdir.
145
        """
146
        try:
147
            target = from_bzrdir.sprout(to_url, revision_id=revision_id,
148
                                        basis=basis,
149
                                        force_new_repo=force_new_repo)
150
        except errors.NotLocalUrl:
151
            raise TestSkipped('Cannot sprout to remote bzrdirs.')
152
        return target
153
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
154
    def test_create_null_workingtree(self):
155
        dir = self.make_bzrdir('dir1')
156
        dir.create_repository()
157
        dir.create_branch()
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
158
        try:
159
            wt = dir.create_workingtree(revision_id=bzrlib.revision.NULL_REVISION)
160
        except errors.NotLocalUrl:
161
            raise TestSkipped("cannot make working tree with transport %r"
162
                              % dir.transport)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
163
        self.assertEqual([], wt.get_parent_ids())
1551.8.20 by Aaron Bentley
Fix BzrDir.create_workingtree for NULL_REVISION
164
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
165
    def test_destroy_workingtree(self):
166
        tree = self.make_branch_and_tree('tree')
167
        self.build_tree(['tree/file'])
168
        tree.add('file')
169
        tree.commit('first commit')
170
        bzrdir = tree.bzrdir
171
        try:
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
172
            bzrdir.destroy_workingtree()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
173
        except errors.UnsupportedOperation:
174
            raise TestSkipped('Format does not support destroying tree')
175
        self.failIfExists('tree/file')
176
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
177
        bzrdir.create_workingtree()
178
        self.failUnlessExists('tree/file')
1551.8.37 by Aaron Bentley
Cleaner implementation of destroy_working_tree
179
        bzrdir.destroy_workingtree_metadata()
1551.8.36 by Aaron Bentley
Introduce BzrDir.destroy_workingtree
180
        self.failUnlessExists('tree/file')
181
        self.assertRaises(errors.NoWorkingTree, bzrdir.open_workingtree)
182
            
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
183
    def test_clone_bzrdir_empty(self):
184
        dir = self.make_bzrdir('source')
185
        target = dir.clone(self.get_url('target'))
186
        self.assertNotEqual(dir.transport.base, target.transport.base)
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
187
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
188
                                    ['./.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.
189
    
1534.6.8 by Robert Collins
Test the use of clone on empty bzrdir with force_new_repo.
190
    def test_clone_bzrdir_empty_force_new_ignored(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
191
        # 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.
192
        # bzrdir's clone logic
193
        dir = self.make_bzrdir('source')
194
        target = dir.clone(self.get_url('target'), force_new_repo=True)
195
        self.assertNotEqual(dir.transport.base, target.transport.base)
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
196
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
197
                                    ['./.bzr/merge-hashes'])
1534.6.8 by Robert Collins
Test the use of clone on empty bzrdir with force_new_repo.
198
    
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
199
    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.
200
        tree = self.make_branch_and_tree('commit_tree')
201
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
202
        tree.add('foo')
203
        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.
204
        dir = self.make_bzrdir('source')
205
        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.
206
        repo.fetch(tree.branch.repository)
207
        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.
208
        target = dir.clone(self.get_url('target'))
209
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
210
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
211
                                    [
212
                                     './.bzr/merge-hashes',
213
                                     './.bzr/repository/inventory.knit',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
214
                                     ])
215
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
216
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.
217
    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.
218
        tree = self.make_branch_and_tree('commit_tree')
219
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
220
        tree.add('foo')
221
        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.
222
        dir = self.make_bzrdir('source')
223
        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.
224
        repo.fetch(tree.branch.repository)
225
        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.
226
        try:
227
            self.make_repository('target', shared=True)
228
        except errors.IncompatibleFormat:
229
            return
230
        target = dir.clone(self.get_url('target/child'))
231
        self.assertNotEqual(dir.transport.base, target.transport.base)
232
        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.
233
234
    def test_clone_bzrdir_repository_branch_both_under_shared(self):
235
        try:
236
            shared_repo = self.make_repository('shared', shared=True)
237
        except errors.IncompatibleFormat:
238
            return
239
        tree = self.make_branch_and_tree('commit_tree')
240
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
241
        tree.add('foo')
242
        tree.commit('revision 1', rev_id='1')
243
        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.
244
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
245
        tree.commit('revision 2', rev_id='2')
246
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
247
        dir = self.make_bzrdir('shared/source')
248
        dir.create_branch()
249
        target = dir.clone(self.get_url('shared/target'))
250
        self.assertNotEqual(dir.transport.base, target.transport.base)
251
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
252
        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
253
254
    def test_clone_bzrdir_repository_branch_only_source_under_shared(self):
255
        try:
256
            shared_repo = self.make_repository('shared', shared=True)
257
        except errors.IncompatibleFormat:
258
            return
259
        tree = self.make_branch_and_tree('commit_tree')
260
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
261
        tree.add('foo')
262
        tree.commit('revision 1', rev_id='1')
263
        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.
264
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
265
        tree.commit('revision 2', rev_id='2')
266
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
267
        shared_repo.set_make_working_trees(False)
268
        self.assertFalse(shared_repo.make_working_trees())
269
        self.assertTrue(shared_repo.has_revision('1'))
270
        dir = self.make_bzrdir('shared/source')
271
        dir.create_branch()
272
        target = dir.clone(self.get_url('target'))
273
        self.assertNotEqual(dir.transport.base, target.transport.base)
274
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
275
        branch = target.open_branch()
276
        self.assertTrue(branch.repository.has_revision('1'))
277
        self.assertFalse(branch.repository.make_working_trees())
278
        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.
279
        
1534.6.9 by Robert Collins
sprouting into shared repositories
280
    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.
281
        tree = self.make_branch_and_tree('commit_tree')
282
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
283
        tree.add('foo')
284
        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.
285
        dir = self.make_bzrdir('source')
286
        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.
287
        repo.fetch(tree.branch.repository)
288
        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.
289
        try:
290
            self.make_repository('target', shared=True)
291
        except errors.IncompatibleFormat:
292
            return
293
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
294
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
295
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
296
                                    ['./.bzr/repository/inventory.knit',
297
                                     ])
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.
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_revision(self):
300
        # test for revision limiting, [smoke test, not corner case checks].
301
        # make a repository with some revisions,
302
        # and clone it with a revision limit.
303
        # 
304
        tree = self.make_branch_and_tree('commit_tree')
305
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
306
        tree.add('foo')
307
        tree.commit('revision 1', rev_id='1')
308
        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.
309
        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.
310
        tree.commit('revision 2', rev_id='2')
311
        source = self.make_repository('source')
312
        tree.bzrdir.open_repository().copy_content_into(source)
313
        dir = source.bzrdir
314
        target = dir.clone(self.get_url('target'), revision_id='2')
315
        raise TestSkipped('revision limiting not strict yet')
316
317
    def test_clone_bzrdir_branch_and_repo(self):
318
        tree = self.make_branch_and_tree('commit_tree')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
319
        self.build_tree(['foo'], transport=tree.bzrdir.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.
320
        tree.add('foo')
321
        tree.commit('revision 1')
322
        source = self.make_branch('source')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
323
        tree.branch.repository.copy_content_into(source.repository)
324
        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.
325
        dir = source.bzrdir
326
        target = dir.clone(self.get_url('target'))
327
        self.assertNotEqual(dir.transport.base, target.transport.base)
1508.1.24 by Robert Collins
Add update command for use with checkouts.
328
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
329
                                    [
330
                                     './.bzr/basis-inventory-cache',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
331
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
332
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
333
                                     './.bzr/repository/inventory.knit',
2230.3.30 by Aaron Bentley
Fix whitespace issues
334
                                     './.bzr/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
335
                                    ])
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.
336
337
    def test_clone_bzrdir_branch_and_repo_into_shared_repo(self):
338
        # by default cloning into a shared repo uses the shared repo.
339
        tree = self.make_branch_and_tree('commit_tree')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
340
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
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.
341
        tree.add('foo')
342
        tree.commit('revision 1')
343
        source = self.make_branch('source')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
344
        tree.branch.repository.copy_content_into(source.repository)
345
        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.
346
        try:
347
            self.make_repository('target', shared=True)
348
        except errors.IncompatibleFormat:
349
            return
350
        dir = source.bzrdir
351
        target = dir.clone(self.get_url('target/child'))
352
        self.assertNotEqual(dir.transport.base, target.transport.base)
353
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
354
        self.assertEqual(source.revision_history(),
355
                         target.open_branch().revision_history())
356
357
    def test_clone_bzrdir_branch_and_repo_into_shared_repo_force_new_repo(self):
358
        # by default cloning into a shared repo uses the shared repo.
359
        tree = self.make_branch_and_tree('commit_tree')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
360
        self.build_tree(['foo'], transport=tree.bzrdir.root_transport)
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.
361
        tree.add('foo')
362
        tree.commit('revision 1')
363
        source = self.make_branch('source')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
364
        tree.branch.repository.copy_content_into(source.repository)
365
        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.
366
        try:
367
            self.make_repository('target', shared=True)
368
        except errors.IncompatibleFormat:
369
            return
370
        dir = source.bzrdir
371
        target = dir.clone(self.get_url('target/child'), force_new_repo=True)
372
        self.assertNotEqual(dir.transport.base, target.transport.base)
373
        target.open_repository()
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
374
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
375
                                    ['./.bzr/repository/inventory.knit',
376
                                     ])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
377
378
    def test_clone_bzrdir_branch_reference(self):
379
        # cloning should preserve the reference status of the branch in a bzrdir
380
        referenced_branch = self.make_branch('referencced')
381
        dir = self.make_bzrdir('source')
382
        try:
1508.1.25 by Robert Collins
Update per review comments.
383
            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.
384
                referenced_branch)
385
        except errors.IncompatibleFormat:
386
            # this is ok too, not all formats have to support references.
387
            return
388
        target = dir.clone(self.get_url('target'))
389
        self.assertNotEqual(dir.transport.base, target.transport.base)
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
390
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
391
                                    ['./.bzr/repository/inventory.knit',
392
                                     ])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
393
394
    def test_clone_bzrdir_branch_revision(self):
395
        # test for revision limiting, [smoke test, not corner case checks].
396
        # make a branch with some revisions,
397
        # and clone it with a revision limit.
398
        # 
399
        tree = self.make_branch_and_tree('commit_tree')
400
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
401
        tree.add('foo')
402
        tree.commit('revision 1', rev_id='1')
403
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
404
        source = self.make_branch('source')
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
405
        tree.branch.repository.copy_content_into(source.repository)
406
        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.
407
        dir = source.bzrdir
408
        target = dir.clone(self.get_url('target'), revision_id='1')
409
        self.assertEqual('1', target.open_branch().last_revision())
410
        
411
    def test_clone_bzrdir_tree_branch_repo(self):
412
        tree = self.make_branch_and_tree('sourcce')
413
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
414
        tree.add('foo')
415
        tree.commit('revision 1')
416
        dir = tree.bzrdir
417
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
418
        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.
419
        self.assertNotEqual(dir.transport.base, target.transport.base)
420
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
421
                                    ['./.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.
422
                                     './.bzr/checkout/dirstate',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
423
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
424
                                     './.bzr/checkout/merge-hashes',
425
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
426
                                     './.bzr/repository/inventory.knit',
427
                                     ])
428
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
429
        target.open_workingtree().revert([])
430
431
    def test_revert_inventory(self):
432
        tree = self.make_branch_and_tree('sourcce')
433
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
434
        tree.add('foo')
435
        tree.commit('revision 1')
436
        dir = tree.bzrdir
437
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
438
        self.skipIfNoWorkingTree(target)
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
439
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
440
                                    ['./.bzr/stat-cache',
2255.10.8 by John Arbash Meinel
Fix another tests that was assuming dirstate was identical
441
                                     './.bzr/checkout/dirstate',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
442
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
443
                                     './.bzr/checkout/merge-hashes',
444
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
445
                                     './.bzr/repository/inventory.knit',
446
                                     ])
447
1534.7.175 by Aaron Bentley
Ensured revert writes a normal inventory
448
        target.open_workingtree().revert([])
449
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
450
                                    ['./.bzr/stat-cache',
2255.10.8 by John Arbash Meinel
Fix another tests that was assuming dirstate was identical
451
                                     './.bzr/checkout/dirstate',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
452
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
453
                                     './.bzr/checkout/merge-hashes',
454
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
455
                                     './.bzr/repository/inventory.knit',
456
                                     ])
457
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
458
    def test_clone_bzrdir_tree_branch_reference(self):
459
        # a tree with a branch reference (aka a checkout) 
460
        # should stay a checkout on clone.
461
        referenced_branch = self.make_branch('referencced')
462
        dir = self.make_bzrdir('source')
463
        try:
1508.1.25 by Robert Collins
Update per review comments.
464
            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.
465
                referenced_branch)
466
        except errors.IncompatibleFormat:
467
            # this is ok too, not all formats have to support references.
468
            return
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
469
        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.
470
        target = dir.clone(self.get_url('target'))
1910.4.12 by Andrew Bennetts
Use camelCase for test helpers to be more consistent unittest naming.
471
        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.
472
        self.assertNotEqual(dir.transport.base, target.transport.base)
473
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
474
                                    ['./.bzr/stat-cache',
475
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
476
                                     './.bzr/checkout/merge-hashes',
477
                                     './.bzr/merge-hashes',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
478
                                     './.bzr/repository/inventory.knit',
479
                                     ])
480
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
481
    def test_clone_bzrdir_tree_revision(self):
482
        # test for revision limiting, [smoke test, not corner case checks].
483
        # make a tree with a revision with a last-revision
484
        # and clone it with a revision limit.
485
        # This smoke test just checks the revision-id is right. Tree specific
486
        # tests will check corner cases.
487
        tree = self.make_branch_and_tree('source')
488
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
489
        tree.add('foo')
490
        tree.commit('revision 1', rev_id='1')
491
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
492
        dir = tree.bzrdir
493
        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.
494
        self.skipIfNoWorkingTree(target)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
495
        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.
496
497
    def test_clone_bzrdir_incomplete_source_with_basis(self):
498
        # ensure that basis really does grab from the basis by having incomplete source
499
        tree = self.make_branch_and_tree('commit_tree')
500
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
501
        tree.add('foo')
502
        tree.commit('revision 1', rev_id='1')
503
        source = self.make_branch_and_tree('source')
504
        # this gives us an incomplete repository
505
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
506
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
507
        tree.bzrdir.open_branch().copy_content_into(source.branch)
508
        tree.copy_content_into(source)
509
        self.assertFalse(source.branch.repository.has_revision('2'))
510
        dir = source.bzrdir
511
        target = dir.clone(self.get_url('target'), basis=tree.bzrdir)
512
        self.assertEqual('2', target.open_branch().last_revision())
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.
513
        try:
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
514
            self.assertEqual(['2'], target.open_workingtree().get_parent_ids())
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.
515
        except errors.NoWorkingTree:
516
            # It should have a working tree if it's able to have one, so if
517
            # we're here make sure it really can't have one.
518
            self.assertRaises(errors.NotLocalUrl, target.create_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.
519
        self.assertTrue(target.open_branch().repository.has_revision('2'))
520
521
    def test_sprout_bzrdir_empty(self):
522
        dir = self.make_bzrdir('source')
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
523
        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.
524
        self.assertNotEqual(dir.transport.base, target.transport.base)
525
        # creates a new repository branch and tree
526
        target.open_repository()
527
        target.open_branch()
528
        target.open_workingtree()
1534.6.9 by Robert Collins
sprouting into shared repositories
529
530
    def test_sprout_bzrdir_empty_under_shared_repo(self):
531
        # sprouting an empty dir into a repo uses the repo
532
        dir = self.make_bzrdir('source')
533
        try:
534
            self.make_repository('target', shared=True)
535
        except errors.IncompatibleFormat:
536
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
537
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
538
        self.assertRaises(errors.NoRepositoryPresent, target.open_repository)
539
        target.open_branch()
540
        target.open_workingtree()
541
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.
542
    def test_sprout_bzrdir_empty_under_shared_repo_force_new(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
543
        # the force_new_repo parameter should force use of a new repo in an empty
544
        # bzrdir's sprout logic
545
        dir = self.make_bzrdir('source')
546
        try:
547
            self.make_repository('target', shared=True)
548
        except errors.IncompatibleFormat:
549
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
550
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
551
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
552
        target.open_repository()
553
        target.open_branch()
554
        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.
555
    
556
    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.
557
        tree = self.make_branch_and_tree('commit_tree')
558
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
559
        tree.add('foo')
560
        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.
561
        dir = self.make_bzrdir('source')
562
        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.
563
        repo.fetch(tree.branch.repository)
564
        self.assertTrue(repo.has_revision('1'))
1731.1.33 by Aaron Bentley
Revert no-special-root changes
565
        try:
566
            self.assertIs(dir.open_branch().last_revision(), None)
567
        except errors.NotBranchError:
568
            pass
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
569
        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.
570
        self.assertNotEqual(dir.transport.base, target.transport.base)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
571
        # testing inventory isn't reasonable for repositories
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
572
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
573
                                    [
574
                                     './.bzr/branch',
575
                                     './.bzr/checkout',
576
                                     './.bzr/inventory',
577
                                     './.bzr/parent',
578
                                     './.bzr/repository/inventory.knit',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
579
                                     ])
1731.1.33 by Aaron Bentley
Revert no-special-root changes
580
        try:
581
            # If we happen to have a tree, we'll guarantee everything
582
            # except for the tree root is the same.
583
            inventory_f = file(dir.transport.base+'inventory', 'rb')
584
            self.assertContainsRe(inventory_f.read(), 
585
                                  '<inventory file_id="TREE_ROOT[^"]*"'
586
                                  ' format="5">\n</inventory>\n')
587
            inventory_f.close()
588
        except IOError, e:
589
            if e.errno != errno.ENOENT:
590
                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.
591
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
592
    def test_sprout_bzrdir_with_repository_to_shared(self):
1534.6.9 by Robert Collins
sprouting into shared repositories
593
        tree = self.make_branch_and_tree('commit_tree')
594
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
595
        tree.add('foo')
596
        tree.commit('revision 1', rev_id='1')
597
        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.
598
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
599
        tree.commit('revision 2', rev_id='2')
600
        source = self.make_repository('source')
601
        tree.bzrdir.open_repository().copy_content_into(source)
602
        dir = source.bzrdir
603
        try:
604
            shared_repo = self.make_repository('target', shared=True)
605
        except errors.IncompatibleFormat:
606
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
607
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
608
        self.assertNotEqual(dir.transport.base, target.transport.base)
609
        self.assertTrue(shared_repo.has_revision('1'))
610
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
611
    def test_sprout_bzrdir_repository_branch_both_under_shared(self):
612
        try:
613
            shared_repo = self.make_repository('shared', shared=True)
614
        except errors.IncompatibleFormat:
615
            return
616
        tree = self.make_branch_and_tree('commit_tree')
617
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
618
        tree.add('foo')
619
        tree.commit('revision 1', rev_id='1')
620
        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.
621
        tree.set_parent_trees([])
1534.6.13 by Robert Collins
Allow push/pull and branch between branches in the same shared repository.
622
        tree.commit('revision 2', rev_id='2')
623
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
624
        dir = self.make_bzrdir('shared/source')
625
        dir.create_branch()
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
626
        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.
627
        self.assertNotEqual(dir.transport.base, target.transport.base)
628
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
629
        self.assertTrue(shared_repo.has_revision('1'))
630
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
631
    def test_sprout_bzrdir_repository_branch_only_source_under_shared(self):
632
        try:
633
            shared_repo = self.make_repository('shared', shared=True)
634
        except errors.IncompatibleFormat:
635
            return
636
        tree = self.make_branch_and_tree('commit_tree')
637
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
638
        tree.add('foo')
639
        tree.commit('revision 1', rev_id='1')
640
        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.
641
        tree.set_parent_trees([])
1707.1.1 by Robert Collins
Bugfixes to bzrdir.sprout and clone. Sprout was failing to reset the
642
        tree.commit('revision 2', rev_id='2')
643
        tree.bzrdir.open_repository().copy_content_into(shared_repo)
644
        shared_repo.set_make_working_trees(False)
645
        self.assertFalse(shared_repo.make_working_trees())
646
        self.assertTrue(shared_repo.has_revision('1'))
647
        dir = self.make_bzrdir('shared/source')
648
        dir.create_branch()
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
649
        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
650
        self.assertNotEqual(dir.transport.base, target.transport.base)
651
        self.assertNotEqual(dir.transport.base, shared_repo.bzrdir.transport.base)
652
        branch = target.open_branch()
653
        self.assertTrue(branch.repository.has_revision('1'))
654
        self.assertTrue(branch.repository.make_working_trees())
655
        self.assertFalse(branch.repository.is_shared())
656
1534.6.9 by Robert Collins
sprouting into shared repositories
657
    def test_sprout_bzrdir_repository_under_shared_force_new_repo(self):
658
        tree = self.make_branch_and_tree('commit_tree')
659
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
660
        tree.add('foo')
661
        tree.commit('revision 1', rev_id='1')
662
        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.
663
        tree.set_parent_trees([])
1534.6.9 by Robert Collins
sprouting into shared repositories
664
        tree.commit('revision 2', rev_id='2')
665
        source = self.make_repository('source')
666
        tree.bzrdir.open_repository().copy_content_into(source)
667
        dir = source.bzrdir
668
        try:
669
            shared_repo = self.make_repository('target', shared=True)
670
        except errors.IncompatibleFormat:
671
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
672
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
673
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
674
        self.assertNotEqual(dir.transport.base, target.transport.base)
675
        self.assertFalse(shared_repo.has_revision('1'))
676
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
677
    def test_sprout_bzrdir_repository_revision(self):
678
        # test for revision limiting, [smoke test, not corner case checks].
679
        # make a repository with some revisions,
680
        # and sprout it with a revision limit.
681
        # 
682
        tree = self.make_branch_and_tree('commit_tree')
683
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
684
        tree.add('foo')
685
        tree.commit('revision 1', rev_id='1')
686
        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.
687
        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.
688
        tree.commit('revision 2', rev_id='2')
689
        source = self.make_repository('source')
690
        tree.bzrdir.open_repository().copy_content_into(source)
691
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
692
        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.
693
        raise TestSkipped('revision limiting not strict yet')
694
695
    def test_sprout_bzrdir_branch_and_repo(self):
696
        tree = self.make_branch_and_tree('commit_tree')
697
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
698
        tree.add('foo')
699
        tree.commit('revision 1')
700
        source = self.make_branch('source')
701
        tree.bzrdir.open_repository().copy_content_into(source.repository)
702
        tree.bzrdir.open_branch().copy_content_into(source)
703
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
704
        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.
705
        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.
706
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
707
                                    [
708
                                     './.bzr/basis-inventory-cache',
709
                                     './.bzr/branch/branch.conf',
710
                                     './.bzr/branch/parent',
711
                                     './.bzr/checkout',
712
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
713
                                     './.bzr/checkout/stat-cache',
714
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
715
                                     './.bzr/parent',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
716
                                     './.bzr/repository/inventory.knit',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
717
                                     './.bzr/stat-cache',
718
                                     './foo',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
719
                                     ])
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
720
1534.6.9 by Robert Collins
sprouting into shared repositories
721
    def test_sprout_bzrdir_branch_and_repo_shared(self):
722
        # sprouting a branch with a repo into a shared repo uses the shared
723
        # repo
724
        tree = self.make_branch_and_tree('commit_tree')
725
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
726
        tree.add('foo')
727
        tree.commit('revision 1', rev_id='1')
728
        source = self.make_branch('source')
729
        tree.bzrdir.open_repository().copy_content_into(source.repository)
730
        tree.bzrdir.open_branch().copy_content_into(source)
731
        dir = source.bzrdir
732
        try:
733
            shared_repo = self.make_repository('target', shared=True)
734
        except errors.IncompatibleFormat:
735
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
736
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
737
        self.assertTrue(shared_repo.has_revision('1'))
738
739
    def test_sprout_bzrdir_branch_and_repo_shared_force_new_repo(self):
740
        # sprouting a branch with a repo into a shared repo uses the shared
741
        # repo
742
        tree = self.make_branch_and_tree('commit_tree')
743
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
744
        tree.add('foo')
745
        tree.commit('revision 1', rev_id='1')
746
        source = self.make_branch('source')
747
        tree.bzrdir.open_repository().copy_content_into(source.repository)
748
        tree.bzrdir.open_branch().copy_content_into(source)
749
        dir = source.bzrdir
750
        try:
751
            shared_repo = self.make_repository('target', shared=True)
752
        except errors.IncompatibleFormat:
753
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
754
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
755
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
756
        self.assertNotEqual(dir.transport.base, target.transport.base)
757
        self.assertFalse(shared_repo.has_revision('1'))
758
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
759
    def test_sprout_bzrdir_branch_reference(self):
760
        # sprouting should create a repository if needed and a sprouted branch.
761
        referenced_branch = self.make_branch('referencced')
762
        dir = self.make_bzrdir('source')
763
        try:
1508.1.25 by Robert Collins
Update per review comments.
764
            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.
765
                referenced_branch)
766
        except errors.IncompatibleFormat:
767
            # this is ok too, not all formats have to support references.
768
            return
769
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
770
        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.
771
        self.assertNotEqual(dir.transport.base, target.transport.base)
772
        # we want target to have a branch that is in-place.
773
        self.assertEqual(target, target.open_branch().bzrdir)
774
        # and as we dont support repositories being detached yet, a repo in 
775
        # place
776
        target.open_repository()
777
1534.6.9 by Robert Collins
sprouting into shared repositories
778
    def test_sprout_bzrdir_branch_reference_shared(self):
779
        # sprouting should create a repository if needed and a sprouted branch.
780
        referenced_tree = self.make_branch_and_tree('referenced')
781
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
782
        dir = self.make_bzrdir('source')
783
        try:
784
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
785
                referenced_tree.branch)
786
        except errors.IncompatibleFormat:
787
            # this is ok too, not all formats have to support references.
788
            return
789
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
790
        try:
791
            shared_repo = self.make_repository('target', shared=True)
792
        except errors.IncompatibleFormat:
793
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
794
        target = self.sproutOrSkip(dir, self.get_url('target/child'))
1534.6.9 by Robert Collins
sprouting into shared repositories
795
        self.assertNotEqual(dir.transport.base, target.transport.base)
796
        # we want target to have a branch that is in-place.
797
        self.assertEqual(target, target.open_branch().bzrdir)
798
        # and we want no repository as the target is shared
799
        self.assertRaises(errors.NoRepositoryPresent, 
800
                          target.open_repository)
801
        # and we want revision '1' in the shared repo
802
        self.assertTrue(shared_repo.has_revision('1'))
803
804
    def test_sprout_bzrdir_branch_reference_shared_force_new_repo(self):
805
        # sprouting should create a repository if needed and a sprouted branch.
806
        referenced_tree = self.make_branch_and_tree('referenced')
807
        referenced_tree.commit('1', rev_id='1', allow_pointless=True)
808
        dir = self.make_bzrdir('source')
809
        try:
810
            reference = bzrlib.branch.BranchReferenceFormat().initialize(dir,
811
                referenced_tree.branch)
812
        except errors.IncompatibleFormat:
813
            # this is ok too, not all formats have to support references.
814
            return
815
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
816
        try:
817
            shared_repo = self.make_repository('target', shared=True)
818
        except errors.IncompatibleFormat:
819
            return
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
820
        target = self.sproutOrSkip(dir, self.get_url('target/child'),
821
                                   force_new_repo=True)
1534.6.9 by Robert Collins
sprouting into shared repositories
822
        self.assertNotEqual(dir.transport.base, target.transport.base)
823
        # we want target to have a branch that is in-place.
824
        self.assertEqual(target, target.open_branch().bzrdir)
825
        # and we want revision '1' in the new repo
826
        self.assertTrue(target.open_repository().has_revision('1'))
827
        # but not the shared one
828
        self.assertFalse(shared_repo.has_revision('1'))
829
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
830
    def test_sprout_bzrdir_branch_revision(self):
831
        # test for revision limiting, [smoke test, not corner case checks].
832
        # make a repository with some revisions,
833
        # and sprout it with a revision limit.
834
        # 
835
        tree = self.make_branch_and_tree('commit_tree')
836
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
837
        tree.add('foo')
838
        tree.commit('revision 1', rev_id='1')
839
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
840
        source = self.make_branch('source')
841
        tree.bzrdir.open_repository().copy_content_into(source.repository)
842
        tree.bzrdir.open_branch().copy_content_into(source)
843
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
844
        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.
845
        self.assertEqual('1', target.open_branch().last_revision())
846
        
847
    def test_sprout_bzrdir_tree_branch_repo(self):
848
        tree = self.make_branch_and_tree('sourcce')
849
        self.build_tree(['foo'], transport=tree.bzrdir.transport.clone('..'))
850
        tree.add('foo')
851
        tree.commit('revision 1')
852
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
853
        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.
854
        self.assertNotEqual(dir.transport.base, target.transport.base)
855
        self.assertDirectoriesEqual(dir.root_transport, target.root_transport,
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
856
                                    [
857
                                     './.bzr/branch/branch.conf',
858
                                     './.bzr/branch/parent',
2255.10.9 by John Arbash Meinel
one more test that needs to ignore dirstate
859
                                     './.bzr/checkout/dirstate',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
860
                                     './.bzr/checkout/stat-cache',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
861
                                     './.bzr/checkout/inventory',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
862
                                     './.bzr/inventory',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
863
                                     './.bzr/parent',
1666.1.16 by Robert Collins
Fix occasional test failuresin bzrdir_implementations.
864
                                     './.bzr/repository/inventory.knit',
2230.3.15 by Aaron Bentley
assertDirectoriesEqual detects missing source, tests handle Branch6
865
                                     './.bzr/stat-cache',
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
866
                                     ])
1534.4.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
868
    def test_sprout_bzrdir_tree_branch_reference(self):
869
        # 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.
870
        # 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.
871
        referenced_branch = self.make_branch('referencced')
872
        dir = self.make_bzrdir('source')
873
        try:
1508.1.25 by Robert Collins
Update per review comments.
874
            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.
875
                referenced_branch)
876
        except errors.IncompatibleFormat:
877
            # this is ok too, not all formats have to support references.
878
            return
879
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
880
        tree = self.createWorkingTreeOrSkip(dir)
2381.1.3 by Robert Collins
Review feedback.
881
        self.build_tree(['source/subdir/'])
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
882
        tree.add('subdir')
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
883
        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.
884
        self.assertNotEqual(dir.transport.base, target.transport.base)
885
        # we want target to have a branch that is in-place.
886
        self.assertEqual(target, target.open_branch().bzrdir)
887
        # and as we dont support repositories being detached yet, a repo in 
888
        # place
889
        target.open_repository()
1587.1.5 by Robert Collins
Put bzr branch behaviour back to the 0.7 ignore-working-tree state.
890
        result_tree = target.open_workingtree()
891
        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.
892
893
    def test_sprout_bzrdir_tree_branch_reference_revision(self):
894
        # 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.
895
        # 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.
896
        # and the likewise the new branch should be truncated too
897
        referenced_branch = self.make_branch('referencced')
898
        dir = self.make_bzrdir('source')
899
        try:
1508.1.25 by Robert Collins
Update per review comments.
900
            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.
901
                referenced_branch)
902
        except errors.IncompatibleFormat:
903
            # this is ok too, not all formats have to support references.
904
            return
905
        self.assertRaises(errors.NoRepositoryPresent, dir.open_repository)
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
906
        tree = self.createWorkingTreeOrSkip(dir)
2381.1.3 by Robert Collins
Review feedback.
907
        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.
908
        tree.add('foo')
909
        tree.commit('revision 1', rev_id='1')
910
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
911
        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.
912
        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.
913
        self.assertNotEqual(dir.transport.base, target.transport.base)
914
        # we want target to have a branch that is in-place.
915
        self.assertEqual(target, target.open_branch().bzrdir)
916
        # and as we dont support repositories being detached yet, a repo in 
917
        # place
918
        target.open_repository()
919
        # we trust that the working tree sprouting works via the other tests.
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
920
        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.
921
        self.assertEqual('1', target.open_branch().last_revision())
922
923
    def test_sprout_bzrdir_tree_revision(self):
924
        # test for revision limiting, [smoke test, not corner case checks].
925
        # make a tree with a revision with a last-revision
926
        # and sprout it with a revision limit.
927
        # This smoke test just checks the revision-id is right. Tree specific
928
        # tests will check corner cases.
929
        tree = self.make_branch_and_tree('source')
2381.1.3 by Robert Collins
Review feedback.
930
        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.
931
        tree.add('foo')
932
        tree.commit('revision 1', rev_id='1')
933
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
934
        dir = tree.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
935
        target = self.sproutOrSkip(dir, self.get_url('target'), revision_id='1')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
936
        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.
937
938
    def test_sprout_bzrdir_incomplete_source_with_basis(self):
939
        # ensure that basis really does grab from the basis by having incomplete source
940
        tree = self.make_branch_and_tree('commit_tree')
2381.1.3 by Robert Collins
Review feedback.
941
        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.
942
        tree.add('foo')
943
        tree.commit('revision 1', rev_id='1')
944
        source = self.make_branch_and_tree('source')
945
        # this gives us an incomplete repository
946
        tree.bzrdir.open_repository().copy_content_into(source.branch.repository)
947
        tree.commit('revision 2', rev_id='2', allow_pointless=True)
948
        tree.bzrdir.open_branch().copy_content_into(source.branch)
949
        tree.copy_content_into(source)
950
        self.assertFalse(source.branch.repository.has_revision('2'))
951
        dir = source.bzrdir
1910.4.14 by Andrew Bennetts
Add a sproutOrSkip test helper.
952
        target = self.sproutOrSkip(dir, self.get_url('target'),
953
                                   basis=tree.bzrdir)
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
954
        self.assertEqual('2', target.open_branch().last_revision())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
955
        self.assertEqual(['2'], 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.
956
        self.assertTrue(target.open_branch().repository.has_revision('2'))
1534.4.39 by Robert Collins
Basic BzrDir support.
957
958
    def test_format_initialize_find_open(self):
959
        # loopback test to check the current format initializes to itself.
960
        if not self.bzrdir_format.is_supported():
961
            # unsupported formats are not loopback testable
962
            # because the default open will not open them and
963
            # they may not be initializable.
964
            return
965
        # supported formats must be able to init and open
966
        t = get_transport(self.get_url())
967
        readonly_t = get_transport(self.get_readonly_url())
968
        made_control = self.bzrdir_format.initialize(t.base)
969
        self.failUnless(isinstance(made_control, bzrdir.BzrDir))
970
        self.assertEqual(self.bzrdir_format,
971
                         bzrdir.BzrDirFormat.find_format(readonly_t))
972
        direct_opened_dir = self.bzrdir_format.open(readonly_t)
973
        opened_dir = bzrdir.BzrDir.open(t.base)
974
        self.assertEqual(made_control._format,
975
                         opened_dir._format)
976
        self.assertEqual(direct_opened_dir._format,
977
                         opened_dir._format)
978
        self.failUnless(isinstance(opened_dir, bzrdir.BzrDir))
979
980
    def test_open_not_bzrdir(self):
981
        # test the formats specific behaviour for no-content or similar dirs.
982
        self.assertRaises(NotBranchError,
983
                          self.bzrdir_format.open,
984
                          get_transport(self.get_readonly_url()))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
985
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
986
    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.
987
        # a bzrdir can construct a branch and repository for itself.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
988
        if not self.bzrdir_format.is_supported():
989
            # unsupported formats are not loopback testable
990
            # because the default open will not open them and
991
            # they may not be initializable.
992
            return
993
        t = get_transport(self.get_url())
994
        made_control = self.bzrdir_format.initialize(t.base)
995
        made_repo = made_control.create_repository()
996
        made_branch = made_control.create_branch()
1508.1.25 by Robert Collins
Update per review comments.
997
        self.failUnless(isinstance(made_branch, bzrlib.branch.Branch))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
998
        self.assertEqual(made_control, made_branch.bzrdir)
999
        
1000
    def test_open_branch(self):
1001
        if not self.bzrdir_format.is_supported():
1002
            # unsupported formats are not loopback testable
1003
            # because the default open will not open them and
1004
            # they may not be initializable.
1005
            return
1006
        t = get_transport(self.get_url())
1007
        made_control = self.bzrdir_format.initialize(t.base)
1008
        made_repo = made_control.create_repository()
1009
        made_branch = made_control.create_branch()
1010
        opened_branch = made_control.open_branch()
1011
        self.assertEqual(made_control, opened_branch.bzrdir)
1012
        self.failUnless(isinstance(opened_branch, made_branch.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1013
        self.failUnless(isinstance(opened_branch._format, made_branch._format.__class__))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
1014
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1015
    def test_create_repository(self):
1016
        # a bzrdir can construct a repository for itself.
1017
        if not self.bzrdir_format.is_supported():
1018
            # unsupported formats are not loopback testable
1019
            # because the default open will not open them and
1020
            # they may not be initializable.
1021
            return
1022
        t = get_transport(self.get_url())
1023
        made_control = self.bzrdir_format.initialize(t.base)
1024
        made_repo = made_control.create_repository()
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
1025
        # Check that we have a repository object.
1026
        made_repo.has_revision('foo')
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1027
        self.assertEqual(made_control, made_repo.bzrdir)
1841.2.2 by Jelmer Vernooij
Add more tests for create_repository().
1028
1029
    def test_create_repository_shared(self):
1030
        # a bzrdir can create a shared repository or 
1031
        # fail appropriately
1032
        if not self.bzrdir_format.is_supported():
1033
            # unsupported formats are not loopback testable
1034
            # because the default open will not open them and
1035
            # they may not be initializable.
1036
            return
1037
        t = get_transport(self.get_url())
1038
        made_control = self.bzrdir_format.initialize(t.base)
1039
        try:
1040
            made_repo = made_control.create_repository(shared=True)
1041
        except errors.IncompatibleFormat:
1042
            # Old bzrdir formats don't support shared repositories
1043
            # and should raise IncompatibleFormat
1044
            return
1045
        self.assertTrue(made_repo.is_shared())
1046
1047
    def test_create_repository_nonshared(self):
1048
        # a bzrdir can create a non-shared repository 
1049
        if not self.bzrdir_format.is_supported():
1050
            # unsupported formats are not loopback testable
1051
            # because the default open will not open them and
1052
            # they may not be initializable.
1053
            return
1054
        t = get_transport(self.get_url())
1055
        made_control = self.bzrdir_format.initialize(t.base)
1056
        made_repo = made_control.create_repository(shared=False)
1057
        self.assertFalse(made_repo.is_shared())
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
1058
        
1059
    def test_open_repository(self):
1060
        if not self.bzrdir_format.is_supported():
1061
            # unsupported formats are not loopback testable
1062
            # because the default open will not open them and
1063
            # they may not be initializable.
1064
            return
1065
        t = get_transport(self.get_url())
1066
        made_control = self.bzrdir_format.initialize(t.base)
1067
        made_repo = made_control.create_repository()
1068
        opened_repo = made_control.open_repository()
1069
        self.assertEqual(made_control, opened_repo.bzrdir)
1070
        self.failUnless(isinstance(opened_repo, made_repo.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1071
        self.failUnless(isinstance(opened_repo._format, made_repo._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1072
1073
    def test_create_workingtree(self):
1074
        # a bzrdir can construct a working tree for itself.
1075
        if not self.bzrdir_format.is_supported():
1076
            # unsupported formats are not loopback testable
1077
            # because the default open will not open them and
1078
            # they may not be initializable.
1079
            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.
1080
        t = self.get_transport()
1910.5.9 by Andrew Bennetts
Move stuff out of a try block that doesn't need to be there.
1081
        made_control = self.bzrdir_format.initialize(t.base)
1082
        made_repo = made_control.create_repository()
1083
        made_branch = made_control.create_branch()
1910.5.11 by Andrew Bennetts
Use createWorkingTreeOrSkip helper in test_create_workingtree.
1084
        made_tree = self.createWorkingTreeOrSkip(made_control)
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1085
        self.failUnless(isinstance(made_tree, workingtree.WorkingTree))
1086
        self.assertEqual(made_control, made_tree.bzrdir)
1087
        
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1088
    def test_create_workingtree_revision(self):
1089
        # 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.
1090
        t = self.get_transport()
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1091
        source = self.make_branch_and_tree('source')
1092
        source.commit('a', rev_id='a', allow_pointless=True)
1093
        source.commit('b', rev_id='b', allow_pointless=True)
1094
        self.build_tree(['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.
1095
        t_new = t.clone('new')
1096
        made_control = self.bzrdir_format.initialize_on_transport(t_new)
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1097
        source.branch.repository.clone(made_control)
1098
        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.
1099
        try:
1100
            made_tree = made_control.create_workingtree(revision_id='a')
1101
        except errors.NotLocalUrl:
1102
            raise TestSkipped("Can't make working tree on transport %r" % t)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
1103
        self.assertEqual(['a'], made_tree.get_parent_ids())
1508.1.21 by Robert Collins
Implement -r limit for checkout command.
1104
        
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1105
    def test_open_workingtree(self):
1106
        if not self.bzrdir_format.is_supported():
1107
            # unsupported formats are not loopback testable
1108
            # because the default open will not open them and
1109
            # they may not be initializable.
1110
            return
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
1111
        # 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.
1112
        # format 6 bzrdirs
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
1113
        t = self.get_transport()
1114
        try:
1115
            made_control = self.bzrdir_format.initialize(t.base)
1116
            made_repo = made_control.create_repository()
1117
            made_branch = made_control.create_branch()
1118
            made_tree = made_control.create_workingtree()
1119
        except errors.NotLocalUrl:
1120
            raise TestSkipped("Can't initialize %r on transport %r"
1121
                              % (self.bzrdir_format, t))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1122
        opened_tree = made_control.open_workingtree()
1123
        self.assertEqual(made_control, opened_tree.bzrdir)
1124
        self.failUnless(isinstance(opened_tree, made_tree.__class__))
1534.4.46 by Robert Collins
Nearly complete .bzr/checkout splitout.
1125
        self.failUnless(isinstance(opened_tree._format, made_tree._format.__class__))
1534.4.42 by Robert Collins
add working tree to the BzrDir facilities.
1126
1534.4.44 by Robert Collins
Make a new BzrDir format that uses a versioned branch format in a branch/ subdirectory.
1127
    def test_get_branch_transport(self):
1128
        dir = self.make_bzrdir('.')
1129
        # without a format, get_branch_transport gives use a transport
1130
        # which -may- point to an existing dir.
1131
        self.assertTrue(isinstance(dir.get_branch_transport(None),
1132
                                   transport.Transport))
1133
        # with a given format, either the bzr dir supports identifiable
1134
        # branches, or it supports anonymous  branch formats, but not both.
1508.1.25 by Robert Collins
Update per review comments.
1135
        anonymous_format = bzrlib.branch.BzrBranchFormat4()
1136
        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.
1137
        try:
1138
            found_transport = dir.get_branch_transport(anonymous_format)
1139
            self.assertRaises(errors.IncompatibleFormat,
1140
                              dir.get_branch_transport,
1141
                              identifiable_format)
1142
        except errors.IncompatibleFormat:
1143
            found_transport = dir.get_branch_transport(identifiable_format)
1144
        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.
1145
        # and the dir which has been initialized for us must exist.
1146
        found_transport.list_dir('.')
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1147
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1148
    def test_get_repository_transport(self):
1149
        dir = self.make_bzrdir('.')
1150
        # without a format, get_repository_transport gives use a transport
1151
        # which -may- point to an existing dir.
1152
        self.assertTrue(isinstance(dir.get_repository_transport(None),
1153
                                   transport.Transport))
1154
        # 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.
1155
        # repositories, or it supports anonymous  repository formats, but not both.
1156
        anonymous_format = weaverepo.RepositoryFormat6()
1157
        identifiable_format = weaverepo.RepositoryFormat7()
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1158
        try:
1159
            found_transport = dir.get_repository_transport(anonymous_format)
1160
            self.assertRaises(errors.IncompatibleFormat,
1161
                              dir.get_repository_transport,
1162
                              identifiable_format)
1163
        except errors.IncompatibleFormat:
1164
            found_transport = dir.get_repository_transport(identifiable_format)
1165
        self.assertTrue(isinstance(found_transport, transport.Transport))
1910.4.2 by Andrew Bennetts
Clearer comment and more precise test for directory existence in test_get_*_transport.
1166
        # and the dir which has been initialized for us must exist.
1167
        found_transport.list_dir('.')
1534.4.47 by Robert Collins
Split out repository into .bzr/repository
1168
1534.4.45 by Robert Collins
Start WorkingTree -> .bzr/checkout transition
1169
    def test_get_workingtree_transport(self):
1170
        dir = self.make_bzrdir('.')
1171
        # without a format, get_workingtree_transport gives use a transport
1172
        # which -may- point to an existing dir.
1173
        self.assertTrue(isinstance(dir.get_workingtree_transport(None),
1174
                                   transport.Transport))
1175
        # with a given format, either the bzr dir supports identifiable
1176
        # trees, or it supports anonymous tree formats, but not both.
1177
        anonymous_format = workingtree.WorkingTreeFormat2()
1178
        identifiable_format = workingtree.WorkingTreeFormat3()
1179
        try:
1180
            found_transport = dir.get_workingtree_transport(anonymous_format)
1181
            self.assertRaises(errors.IncompatibleFormat,
1182
                              dir.get_workingtree_transport,
1183
                              identifiable_format)
1184
        except errors.IncompatibleFormat:
1185
            found_transport = dir.get_workingtree_transport(identifiable_format)
1186
        self.assertTrue(isinstance(found_transport, transport.Transport))
1910.4.2 by Andrew Bennetts
Clearer comment and more precise test for directory existence in test_get_*_transport.
1187
        # and the dir which has been initialized for us must exist.
1188
        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.
1189
1190
    def test_root_transport(self):
1191
        dir = self.make_bzrdir('.')
1192
        self.assertEqual(dir.root_transport.base,
1193
                         get_transport(self.get_url('.')).base)
1194
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.
1195
    def test_find_repository_no_repo_under_standalone_branch(self):
1196
        # finding a repo stops at standalone branches even if there is a
1197
        # higher repository available.
1198
        try:
1199
            repo = self.make_repository('.', shared=True)
1200
        except errors.IncompatibleFormat:
1201
            # need a shared repository to test this.
1202
            return
1203
        url = self.get_url('intermediate')
1204
        get_transport(self.get_url()).mkdir('intermediate')
1205
        get_transport(self.get_url()).mkdir('intermediate/child')
1206
        made_control = self.bzrdir_format.initialize(url)
1207
        made_control.create_repository()
1208
        innermost_control = self.bzrdir_format.initialize(
1209
            self.get_url('intermediate/child'))
1210
        try:
1211
            child_repo = innermost_control.open_repository()
1212
            # if there is a repository, then the format cannot ever hit this 
1213
            # code path.
1214
            return
1215
        except errors.NoRepositoryPresent:
1216
            pass
1217
        self.assertRaises(errors.NoRepositoryPresent,
1218
                          innermost_control.find_repository)
1219
1220
    def test_find_repository_containing_shared_repository(self):
1221
        # find repo inside a shared repo with an empty control dir
1222
        # returns the shared repo.
1223
        try:
1224
            repo = self.make_repository('.', shared=True)
1225
        except errors.IncompatibleFormat:
1226
            # need a shared repository to test this.
1227
            return
1228
        url = self.get_url('childbzrdir')
1229
        get_transport(self.get_url()).mkdir('childbzrdir')
1230
        made_control = self.bzrdir_format.initialize(url)
1231
        try:
1232
            child_repo = made_control.open_repository()
1233
            # if there is a repository, then the format cannot ever hit this 
1234
            # code path.
1235
            return
1236
        except errors.NoRepositoryPresent:
1237
            pass
1238
        found_repo = made_control.find_repository()
1239
        self.assertEqual(repo.bzrdir.root_transport.base,
1240
                         found_repo.bzrdir.root_transport.base)
1241
        
1242
    def test_find_repository_standalone_with_containing_shared_repository(self):
1243
        # find repo inside a standalone repo inside a shared repo finds the standalone repo
1244
        try:
1245
            containing_repo = self.make_repository('.', shared=True)
1246
        except errors.IncompatibleFormat:
1247
            # need a shared repository to test this.
1248
            return
1249
        child_repo = self.make_repository('childrepo')
1250
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1251
        found_repo = opened_control.find_repository()
1252
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1253
                         found_repo.bzrdir.root_transport.base)
1254
1255
    def test_find_repository_shared_within_shared_repository(self):
1256
        # find repo at a shared repo inside a shared repo finds the inner repo
1257
        try:
1258
            containing_repo = self.make_repository('.', shared=True)
1259
        except errors.IncompatibleFormat:
1260
            # need a shared repository to test this.
1261
            return
1262
        url = self.get_url('childrepo')
1263
        get_transport(self.get_url()).mkdir('childrepo')
1264
        child_control = self.bzrdir_format.initialize(url)
1265
        child_repo = child_control.create_repository(shared=True)
1266
        opened_control = bzrdir.BzrDir.open(self.get_url('childrepo'))
1267
        found_repo = opened_control.find_repository()
1268
        self.assertEqual(child_repo.bzrdir.root_transport.base,
1269
                         found_repo.bzrdir.root_transport.base)
1270
        self.assertNotEqual(child_repo.bzrdir.root_transport.base,
1271
                            containing_repo.bzrdir.root_transport.base)
1272
1273
    def test_find_repository_with_nested_dirs_works(self):
1274
        # find repo inside a bzrdir inside a bzrdir inside a shared repo 
1275
        # finds the outer shared repo.
1276
        try:
1277
            repo = self.make_repository('.', shared=True)
1278
        except errors.IncompatibleFormat:
1279
            # need a shared repository to test this.
1280
            return
1281
        url = self.get_url('intermediate')
1282
        get_transport(self.get_url()).mkdir('intermediate')
1283
        get_transport(self.get_url()).mkdir('intermediate/child')
1284
        made_control = self.bzrdir_format.initialize(url)
1285
        try:
1286
            child_repo = made_control.open_repository()
1287
            # if there is a repository, then the format cannot ever hit this 
1288
            # code path.
1289
            return
1290
        except errors.NoRepositoryPresent:
1291
            pass
1292
        innermost_control = self.bzrdir_format.initialize(
1293
            self.get_url('intermediate/child'))
1294
        try:
1295
            child_repo = innermost_control.open_repository()
1296
            # if there is a repository, then the format cannot ever hit this 
1297
            # code path.
1298
            return
1299
        except errors.NoRepositoryPresent:
1300
            pass
1301
        found_repo = innermost_control.find_repository()
1302
        self.assertEqual(repo.bzrdir.root_transport.base,
1303
                         found_repo.bzrdir.root_transport.base)
1304
        
1534.5.16 by Robert Collins
Review feedback.
1305
    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.
1306
        # check that we can ask an instance if its upgradable
1307
        dir = self.make_bzrdir('.')
1534.5.16 by Robert Collins
Review feedback.
1308
        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.
1309
            # if its default updatable there must be an updater 
2204.4.14 by Aaron Bentley
lastest -> latest
1310
            # (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
1311
            # available
1312
            self.assertTrue(isinstance(dir._format.get_converter(
1313
                format=dir._format), bzrdir.Converter))
1534.5.16 by Robert Collins
Review feedback.
1314
        dir.needs_format_conversion(None)
1534.6.6 by Robert Collins
Move find_repository to bzrdir, its not quite ideal there but its simpler and until someone chooses to vary the search by branch type its completely sufficient.
1315
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1316
    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.
1317
        """Does an available updater work?"""
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1318
        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.
1319
        # 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.
1320
        dir.create_repository()
1321
        dir.create_branch()
1910.4.13 by Andrew Bennetts
Slightly more consistent names.
1322
        self.createWorkingTreeOrSkip(dir)
1534.5.16 by Robert Collins
Review feedback.
1323
        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.
1324
            # if its default updatable there must be an updater 
2204.4.14 by Aaron Bentley
lastest -> latest
1325
            # (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
1326
            # available
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1327
            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.
1328
            try:
2204.4.13 by Aaron Bentley
Update all test cases to avoid set_default_format
1329
                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.
1330
            finally:
1594.1.3 by Robert Collins
Fixup pb usage to use nested_progress_bar.
1331
                pb.finished()
1534.5.11 by Robert Collins
Implement upgrades to Metaformat trees.
1332
            # and it should pass 'check' now.
1333
            check(bzrdir.BzrDir.open(self.get_url('.')).open_branch(), False)
1334
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
1335
    def test_format_description(self):
1336
        dir = self.make_bzrdir('.')
1337
        text = dir._format.get_format_description()
1338
        self.failUnless(len(text))
1339
2255.14.1 by Martin Pool
Add BzrDir.retire_bzrdir and partly fix subsume
1340
    def test_retire_bzrdir(self):
1341
        bd = self.make_bzrdir('.')
1342
        # must not overwrite existing directories
1343
        self.build_tree(['.bzr.retired.0/', '.bzr.retired.0/junk',])
1344
        self.failUnlessExists('.bzr')
1345
        bd.retire_bzrdir()
1346
        self.failIfExists('.bzr')
1347
        self.failUnlessExists('.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.
1348
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1349
class TestBreakLock(TestCaseWithBzrDir):
1350
1351
    def setUp(self):
1352
        super(TestBreakLock, self).setUp()
1353
        # we want a UI factory that accepts canned input for the tests:
1354
        # while SilentUIFactory still accepts stdin, we need to customise
1355
        # ours
1356
        self.old_factory = bzrlib.ui.ui_factory
1687.1.15 by Robert Collins
Review comments.
1357
        self.addCleanup(self.restoreFactory)
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1358
        bzrlib.ui.ui_factory = bzrlib.ui.SilentUIFactory()
1359
1687.1.15 by Robert Collins
Review comments.
1360
    def restoreFactory(self):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1361
        bzrlib.ui.ui_factory = self.old_factory
1362
1363
    def test_break_lock_empty(self):
1364
        # break lock on an empty bzrdir should work silently.
1365
        dir = self.make_bzrdir('.')
1366
        try:
1367
            dir.break_lock()
1368
        except NotImplementedError:
1369
            pass
1370
1371
    def test_break_lock_repository(self):
1372
        # break lock with just a repo should unlock the repo.
1373
        repo = self.make_repository('.')
1374
        repo.lock_write()
1375
        # only one yes needed here: it should only be unlocking
1376
        # the repo
1377
        bzrlib.ui.ui_factory.stdin = StringIO("y\n")
1378
        try:
1379
            repo.bzrdir.break_lock()
1380
        except NotImplementedError:
1381
            # this bzrdir does not implement break_lock - so we cant test it.
1382
            repo.unlock()
1383
            return
1384
        lock_repo = repo.bzrdir.open_repository()
1385
        lock_repo.lock_write()
1386
        lock_repo.unlock()
1387
        self.assertRaises(errors.LockBroken, repo.unlock)
1388
1389
    def test_break_lock_branch(self):
1390
        # break lock with just a repo should unlock the branch.
1391
        # and not directly try the repository.
1392
        # we test this by making a branch reference to a branch
1393
        # and repository in another bzrdir
1394
        # for pre-metadir formats this will fail, thats ok.
1395
        master = self.make_branch('branch')
1396
        thisdir = self.make_bzrdir('this')
1397
        try:
1398
            bzrlib.branch.BranchReferenceFormat().initialize(
1399
                thisdir, master)
1400
        except errors.IncompatibleFormat:
1401
            return
1402
        unused_repo = thisdir.create_repository()
1403
        master.lock_write()
1404
        unused_repo.lock_write()
1957.1.17 by John Arbash Meinel
Change tests that expect locking to fail to timeout sooner.
1405
        try:
1406
            # two yes's : branch and repository. If the repo in this
1407
            # dir is inappropriately accessed, 3 will be needed, and
1408
            # we'll see that because the stream will be fully consumed
1409
            bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\n")
1410
            master.bzrdir.break_lock()
1411
            # only two ys should have been read
1412
            self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1413
            # we should be able to lock a newly opened branch now
1414
            branch = master.bzrdir.open_branch()
1415
            branch.lock_write()
1416
            branch.unlock()
1417
            # we should not be able to lock the repository in thisdir as its still
1418
            # held by the explicit lock we took, and the break lock should not have
1419
            # touched it.
1420
            repo = thisdir.open_repository()
1421
            orig_default = lockdir._DEFAULT_TIMEOUT_SECONDS
1422
            try:
1423
                lockdir._DEFAULT_TIMEOUT_SECONDS = 1
1424
                self.assertRaises(errors.LockContention, repo.lock_write)
1425
            finally:
1426
                lockdir._DEFAULT_TIMEOUT_SECONDS = orig_default
1427
        finally:
1428
            unused_repo.unlock()
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1429
        self.assertRaises(errors.LockBroken, master.unlock)
1430
1431
    def test_break_lock_tree(self):
1432
        # break lock with a tree should unlock the tree but not try the 
1433
        # branch explicitly. However this is very hard to test for as we 
1434
        # dont have a tree reference class, nor is one needed; 
1435
        # the worst case if this code unlocks twice is an extra question
1436
        # being asked.
1437
        tree = self.make_branch_and_tree('.')
1438
        tree.lock_write()
1439
        # three yes's : tree, branch and repository.
1440
        bzrlib.ui.ui_factory.stdin = StringIO("y\ny\ny\ny\n")
1441
        try:
1442
            tree.bzrdir.break_lock()
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1443
        except (NotImplementedError, errors.LockActive):
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1444
            # bzrdir does not support break_lock
2255.2.145 by Robert Collins
Support unbreakable locks for trees.
1445
            # or one of the locked objects (currently only tree does this)
1446
            # raised a LockActive because we do still have a live locked
1447
            # object.
1687.1.12 by Robert Collins
Hook in the full break-lock ui.
1448
            tree.unlock()
1449
            return
1450
        self.assertEqual("y\n", bzrlib.ui.ui_factory.stdin.read())
1451
        lock_tree = tree.bzrdir.open_workingtree()
1452
        lock_tree.lock_write()
1453
        lock_tree.unlock()
1454
        self.assertRaises(errors.LockBroken, tree.unlock)
1455
1456
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.
1457
class ChrootedBzrDirTests(ChrootedTestCase):
1458
1459
    def test_find_repository_no_repository(self):
1460
        # loopback test to check the current format fails to find a 
1461
        # share repository correctly.
1462
        if not self.bzrdir_format.is_supported():
1463
            # unsupported formats are not loopback testable
1464
            # because the default open will not open them and
1465
            # they may not be initializable.
1466
            return
1467
        # supported formats must be able to init and open
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
1468
        # - do the vfs initialisation over the basic vfs transport
1469
        # XXX: TODO this should become a 'bzrdirlocation' api call.
1470
        url = self.get_vfs_only_url('subdir')
1471
        get_transport(self.get_vfs_only_url()).mkdir('subdir')
1472
        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.
1473
        try:
1474
            repo = made_control.open_repository()
1475
            # if there is a repository, then the format cannot ever hit this 
1476
            # code path.
1477
            return
1478
        except errors.NoRepositoryPresent:
1479
            pass
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
1480
        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.
1481
        self.assertRaises(errors.NoRepositoryPresent,
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
1482
                          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.
1483