/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5557.1.15 by John Arbash Meinel
Merge bzr.dev 5597 to resolve NEWS, aka bzr-2.3.txt
1
# Copyright (C) 2006-2011 Canonical Ltd
1887.1.1 by Adeodato Simó
Do not separate paragraphs in the copyright statement with blank lines,
2
#
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
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.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
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.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
16
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
17
"""Tests for repository implementations - tests a repository format."""
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
18
1666.1.6 by Robert Collins
Make knit the default format.
19
import re
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
20
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
21
from ... import (
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
22
    branch as _mod_branch,
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
23
    controldir,
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
24
    delta as _mod_delta,
1752.2.87 by Andrew Bennetts
Make tests pass.
25
    errors,
3735.2.100 by Vincent Ladeuil
Fix 3 failing tests due to an amazing typo.
26
    gpg,
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
27
    info,
1752.2.87 by Andrew Bennetts
Make tests pass.
28
    repository,
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
29
    revision as _mod_revision,
30
    tests,
31
    transport,
32
    upgrade,
33
    workingtree,
1752.2.87 by Andrew Bennetts
Make tests pass.
34
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
35
from ...bzr import (
36
    branch as _mod_bzrbranch,
37
    inventory,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
38
    remote,
6670.4.3 by Jelmer Vernooij
Fix more imports.
39
    repository as bzrrepository,
40
    )
6670.4.5 by Jelmer Vernooij
Move breezy.repofmt contents to breezy.bzr.
41
from ...bzr import (
5757.1.5 by Jelmer Vernooij
Fix import.
42
    knitpack_repo,
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
43
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
44
from ...sixish import (
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
45
    BytesIO,
46
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
47
from .. import (
5017.3.42 by Vincent Ladeuil
-s bt.per_repository.test_repo passing
48
    per_repository,
49
    test_server,
50
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
51
from ..matchers import *
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
52
53
54
class TestRepositoryMakeBranchAndTree(per_repository.TestCaseWithRepository):
2018.5.66 by Wouter van Heyst
Fix repository test parameterization for RemoteRepository.
55
56
    def test_repository_format(self):
2018.5.119 by Robert Collins
Unbreak TestRepositoryMakeBranchAndTree.
57
        # make sure the repository on tree.branch is of the desired format,
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
58
        # because developers use this api to setup the tree, branch and
2018.5.119 by Robert Collins
Unbreak TestRepositoryMakeBranchAndTree.
59
        # repository for their tests: having it now give the right repository
60
        # type would invalidate the tests.
2018.5.66 by Wouter van Heyst
Fix repository test parameterization for RemoteRepository.
61
        tree = self.make_branch_and_tree('repo')
62
        self.assertIsInstance(tree.branch.repository._format,
63
            self.repository_format.__class__)
2381.1.1 by Robert Collins
Split out hpss test fixes which dont depend on new or altered API's.
64
65
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
66
class TestRepository(per_repository.TestCaseWithRepository):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
67
4431.3.7 by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts.
68
    def assertFormatAttribute(self, attribute, allowed_values):
69
        """Assert that the format has an attribute 'attribute'."""
70
        repo = self.make_repository('repo')
71
        self.assertSubset([getattr(repo._format, attribute)], allowed_values)
72
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
73
    def test_attribute_fast_deltas(self):
74
        """Test the format.fast_deltas attribute."""
4431.3.7 by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts.
75
        self.assertFormatAttribute('fast_deltas', (True, False))
4183.5.1 by Robert Collins
Add RepositoryFormat.fast_deltas to signal fast delta creation.
76
6145.2.2 by Jelmer Vernooij
Set supports_nesting_repositories.
77
    def test_attribute_supports_nesting_repositories(self):
78
        """Test the format.supports_nesting_repositories."""
79
        self.assertFormatAttribute('supports_nesting_repositories',
80
            (True, False))
81
6217.4.2 by Jelmer Vernooij
s/invisible/unreferenced.
82
    def test_attribute_supports_unreferenced_revisions(self):
83
        """Test the format.supports_unreferenced_revisions."""
84
        self.assertFormatAttribute('supports_unreferenced_revisions',
6217.4.1 by Jelmer Vernooij
Add RepositoryFormat.supports_invisible_revisions.
85
            (True, False))
86
3565.3.4 by Robert Collins
Defer decision to reconcile to the repository being fetched into.
87
    def test_attribute__fetch_reconcile(self):
4775.1.1 by Martin Pool
Remove several 'the the' typos
88
        """Test the _fetch_reconcile attribute."""
4431.3.7 by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts.
89
        self.assertFormatAttribute('_fetch_reconcile', (True, False))
90
4988.9.1 by Jelmer Vernooij
Add experimental flag to RepositoryFormat.
91
    def test_attribute_format_experimental(self):
92
        self.assertFormatAttribute('experimental', (True, False))
93
4431.3.7 by Jonathan Lange
Cherrypick bzr.dev 4470, resolving conflicts.
94
    def test_attribute_format_pack_compresses(self):
95
        self.assertFormatAttribute('pack_compresses', (True, False))
3565.3.4 by Robert Collins
Defer decision to reconcile to the repository being fetched into.
96
5684.2.1 by Jelmer Vernooij
Add bzrlib.tests.per_repository_vf.
97
    def test_attribute_format_supports_full_versioned_files(self):
98
        self.assertFormatAttribute('supports_full_versioned_files',
99
            (True, False))
100
101
    def test_attribute_format_supports_funky_characters(self):
102
        self.assertFormatAttribute('supports_funky_characters',
103
            (True, False))
104
105
    def test_attribute_format_supports_leaving_lock(self):
106
        self.assertFormatAttribute('supports_leaving_lock',
107
            (True, False))
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
108
5993.3.2 by Jelmer Vernooij
Add Repository.supports_versioned_directories.
109
    def test_attribute_format_versioned_directories(self):
110
        self.assertFormatAttribute('supports_versioned_directories', (True, False))
111
5766.1.1 by Jelmer Vernooij
Make revision-graph-can-have-wrong-parents a repository format attribute rather than a repository method.
112
    def test_attribute_format_revision_graph_can_have_wrong_parents(self):
113
        self.assertFormatAttribute('revision_graph_can_have_wrong_parents',
114
            (True, False))
115
5675.2.5 by Jelmer Vernooij
add tests for repository attributes.
116
    def test_format_is_deprecated(self):
117
        repo = self.make_repository('repo')
5675.2.6 by Jelmer Vernooij
Fix some tests.
118
        self.assertSubset([repo._format.is_deprecated()], (True, False))
5675.2.5 by Jelmer Vernooij
add tests for repository attributes.
119
120
    def test_format_is_supported(self):
121
        repo = self.make_repository('repo')
5675.2.6 by Jelmer Vernooij
Fix some tests.
122
        self.assertSubset([repo._format.is_supported()], (True, False))
5675.2.5 by Jelmer Vernooij
add tests for repository attributes.
123
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
124
    def test_clone_to_default_format(self):
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
125
        #TODO: Test that cloning a repository preserves all the information
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
126
        # such as signatures[not tested yet] etc etc.
127
        # when changing to the current default format.
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
128
        tree_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
129
        self.build_tree(['a/foo'])
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
130
        tree_a.add('foo', 'file1')
131
        tree_a.commit('rev1', rev_id='rev1')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
132
        bzrdirb = self.make_controldir('b')
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
133
        repo_b = tree_a.branch.repository.clone(bzrdirb)
134
        tree_b = repo_b.revision_tree('rev1')
2592.3.214 by Robert Collins
Merge bzr.dev.
135
        tree_b.lock_read()
136
        self.addCleanup(tree_b.unlock)
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
137
        tree_b.get_file_text('file1')
138
        rev1 = repo_b.get_revision('rev1')
139
1910.2.63 by Aaron Bentley
Add supports_rich_root member to repository
140
    def test_supports_rich_root(self):
141
        tree = self.make_branch_and_tree('a')
142
        tree.commit('')
143
        second_revision = tree.commit('')
4253.3.1 by Robert Collins
per_repository/test_repository improvements (Robert Collins)
144
        rev_tree = tree.branch.repository.revision_tree(second_revision)
145
        rev_tree.lock_read()
146
        self.addCleanup(rev_tree.unlock)
5805.1.1 by Jelmer Vernooij
Avoid using inventories in some tests.
147
        root_revision = rev_tree.get_file_revision(rev_tree.get_root_id())
148
        rich_root = (root_revision != second_revision)
2018.5.113 by Robert Collins
Test only fixes from the ported-to-bzr.dev test-correctness branch.
149
        self.assertEqual(rich_root,
1910.2.63 by Aaron Bentley
Add supports_rich_root member to repository
150
                         tree.branch.repository.supports_rich_root())
151
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
152
    def test_clone_specific_format(self):
153
        """todo"""
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
154
155
    def test_format_initialize_find_open(self):
156
        # loopback test to check the current format initializes to itself.
157
        if not self.repository_format.is_supported():
158
            # unsupported formats are not loopback testable
159
            # because the default open will not open them and
160
            # they may not be initializable.
161
            return
162
        # supported formats must be able to init and open
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
163
        t = self.get_transport()
164
        readonly_t = self.get_readonly_transport()
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
165
        made_control = self.bzrdir_format.initialize(t.base)
166
        made_repo = self.repository_format.initialize(made_control)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
167
        self.assertEqual(made_control, made_repo.controldir)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
168
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
169
        # find it via controldir opening:
170
        opened_control = controldir.ControlDir.open(readonly_t.base)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
171
        direct_opened_repo = opened_control.open_repository()
172
        self.assertEqual(direct_opened_repo.__class__, made_repo.__class__)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
173
        self.assertEqual(opened_control, direct_opened_repo.controldir)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
174
1752.2.52 by Andrew Bennetts
Flesh out more Remote* methods needed to open and initialise remote branches/trees/repositories.
175
        self.assertIsInstance(direct_opened_repo._format,
176
                              self.repository_format.__class__)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
177
        # find it via Repository.open
178
        opened_repo = repository.Repository.open(readonly_t.base)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
179
        self.assertIsInstance(opened_repo, made_repo.__class__)
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
180
        self.assertEqual(made_repo._format.__class__,
181
                         opened_repo._format.__class__)
182
        # if it has a unique id string, can we probe for it ?
183
        try:
184
            self.repository_format.get_format_string()
185
        except NotImplementedError:
186
            return
187
        self.assertEqual(self.repository_format,
6653.2.1 by Jelmer Vernooij
Move bzr-specific repository code out of breezy.bzrrepository.
188
             bzrrepository.RepositoryFormatMetaDir.find_format(opened_control))
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
189
3845.1.1 by John Arbash Meinel
Ensure that RepositoryFormat._matchingbzrdir.repository_format matches.
190
    def test_format_matchingbzrdir(self):
191
        self.assertEqual(self.repository_format,
192
            self.repository_format._matchingbzrdir.repository_format)
193
        self.assertEqual(self.repository_format,
194
            self.bzrdir_format.repository_format)
195
3990.5.1 by Andrew Bennetts
Add network_name() to RepositoryFormat.
196
    def test_format_network_name(self):
197
        repo = self.make_repository('r')
198
        format = repo._format
199
        network_name = format.network_name()
200
        self.assertIsInstance(network_name, str)
201
        # We want to test that the network_name matches the actual format on
202
        # disk.  For local repositories, that means that using network_name as
203
        # a key in the registry gives back the same format.  For remote
204
        # repositories, that means that the network_name of the
205
        # RemoteRepositoryFormat we have locally matches the actual format
206
        # present on the remote side.
207
        if isinstance(format, remote.RemoteRepositoryFormat):
208
            repo._ensure_real()
209
            real_repo = repo._real_repository
210
            self.assertEqual(real_repo._format.network_name(), network_name)
211
        else:
212
            registry = repository.network_format_registry
213
            looked_up_format = registry.get(network_name)
214
            self.assertEqual(format.__class__, looked_up_format.__class__)
215
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
216
    def test_create_repository(self):
1534.6.1 by Robert Collins
allow API creation of shared repositories
217
        # bzrdir can construct a repository for itself.
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
218
        if not self.bzrdir_format.is_supported():
219
            # unsupported formats are not loopback testable
220
            # because the default open will not open them and
221
            # they may not be initializable.
222
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
223
        t = self.get_transport()
1534.4.40 by Robert Collins
Add RepositoryFormats and allow bzrdir.open or create _repository to be used.
224
        made_control = self.bzrdir_format.initialize(t.base)
225
        made_repo = made_control.create_repository()
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
226
        # Check that we have a repository object.
227
        made_repo.has_revision('foo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
228
        self.assertEqual(made_control, made_repo.controldir)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
229
1534.6.1 by Robert Collins
allow API creation of shared repositories
230
    def test_create_repository_shared(self):
231
        # bzrdir can construct a shared repository.
232
        if not self.bzrdir_format.is_supported():
233
            # unsupported formats are not loopback testable
234
            # because the default open will not open them and
235
            # they may not be initializable.
236
            return
5609.9.4 by Vincent Ladeuil
Use self.get_transport instead of transport.get_transport where possible.
237
        t = self.get_transport()
1534.6.1 by Robert Collins
allow API creation of shared repositories
238
        made_control = self.bzrdir_format.initialize(t.base)
239
        try:
240
            made_repo = made_control.create_repository(shared=True)
241
        except errors.IncompatibleFormat:
242
            # not all repository formats understand being shared, or
243
            # may only be shared in some circumstances.
244
            return
1752.2.50 by Andrew Bennetts
Implement RemoteBzrDir.create_{branch,workingtree}
245
        # Check that we have a repository object.
246
        made_repo.has_revision('foo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
247
        self.assertEqual(made_control, made_repo.controldir)
1534.6.3 by Robert Collins
find_repository sufficiently robust.
248
        self.assertTrue(made_repo.is_shared())
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
249
250
    def test_revision_tree(self):
251
        wt = self.make_branch_and_tree('.')
1731.1.33 by Aaron Bentley
Revert no-special-root changes
252
        wt.set_root_id('fixed-root')
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
253
        wt.commit('lala!', rev_id='revision-1', allow_pointless=True)
254
        tree = wt.branch.repository.revision_tree('revision-1')
4253.3.1 by Robert Collins
per_repository/test_repository improvements (Robert Collins)
255
        tree.lock_read()
256
        try:
5819.2.5 by Jelmer Vernooij
Use tree methods rather than inventory methods.
257
            self.assertEqual('revision-1',
258
                tree.get_file_revision(tree.get_root_id()))
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
259
            expected = inventory.InventoryDirectory('fixed-root', '', None)
4253.3.1 by Robert Collins
per_repository/test_repository improvements (Robert Collins)
260
            expected.revision = 'revision-1'
261
            self.assertEqual([('', 'V', 'directory', 'fixed-root', expected)],
262
                             list(tree.list_files(include_root=True)))
263
        finally:
264
            tree.unlock()
6630.1.1 by Jelmer Vernooij
Remove deprecated functionality.
265
        self.assertRaises(ValueError, wt.branch.repository.revision_tree, None)
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
266
        tree = wt.branch.repository.revision_tree(_mod_revision.NULL_REVISION)
4253.3.1 by Robert Collins
per_repository/test_repository improvements (Robert Collins)
267
        tree.lock_read()
268
        try:
269
            self.assertEqual([], list(tree.list_files(include_root=True)))
270
        finally:
271
            tree.unlock()
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
272
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
273
    def test_get_revision_delta(self):
274
        tree_a = self.make_branch_and_tree('a')
2381.1.3 by Robert Collins
Review feedback.
275
        self.build_tree(['a/foo'])
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
276
        tree_a.add('foo', 'file1')
277
        tree_a.commit('rev1', rev_id='rev1')
2381.1.3 by Robert Collins
Review feedback.
278
        self.build_tree(['a/vla'])
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
279
        tree_a.add('vla', 'file2')
280
        tree_a.commit('rev2', rev_id='rev2')
281
282
        delta = tree_a.branch.repository.get_revision_delta('rev1')
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
283
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
284
        self.assertEqual([('foo', 'file1', 'file')], delta.added)
285
        delta = tree_a.branch.repository.get_revision_delta('rev2')
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
286
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
1770.3.3 by Jelmer Vernooij
Add tests for Branch.get_revision_delta() and Repository.get_revision_delta().
287
        self.assertEqual([('vla', 'file2', 'file')], delta.added)
288
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
289
    def test_clone_bzrdir_repository_revision(self):
290
        # make a repository with some revisions,
291
        # and clone it, this should not have unreferenced revisions.
292
        # also: test cloning with a revision id of NULL_REVISION -> empty repo.
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
293
        raise tests.TestSkipped('revision limiting is not implemented yet.')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
294
295
    def test_clone_repository_basis_revision(self):
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
296
        raise tests.TestSkipped(
297
            'the use of a basis should not add noise data to the result.')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
298
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
299
    def test_clone_shared_no_tree(self):
300
        # cloning a shared repository keeps it shared
301
        # and preserves the make_working_tree setting.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
302
        made_control = self.make_controldir('source')
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
303
        try:
304
            made_repo = made_control.create_repository(shared=True)
305
        except errors.IncompatibleFormat:
306
            # not all repository formats understand being shared, or
307
            # may only be shared in some circumstances.
308
            return
2018.14.2 by Andrew Bennetts
All but one repository_implementation tests for RemoteRepository passing.
309
        try:
310
            made_repo.set_make_working_trees(False)
6104.2.2 by Jelmer Vernooij
Expect UnsupportedOperation when set_make_working_trees is not available.
311
        except errors.UnsupportedOperation:
2018.5.120 by Robert Collins
The Repository API ``make_working_trees`` is now permitted to return
312
            # the repository does not support having its tree-making flag
313
            # toggled.
314
            return
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
315
        result = made_control.clone(self.get_url('target'))
1752.2.55 by Andrew Bennetts
Replace another isinstance(made_repo, Repository) check.
316
        # Check that we have a repository object.
317
        made_repo.has_revision('foo')
318
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
319
        self.assertEqual(made_control, made_repo.controldir)
1534.6.5 by Robert Collins
Cloning of repos preserves shared and make-working-tree attributes.
320
        self.assertTrue(result.open_repository().is_shared())
321
        self.assertFalse(result.open_repository().make_working_trees())
322
2018.5.90 by Andrew Bennetts
Fix test_upgrade_preserves_signatures; it incorrectly assumed that upgrade(wt, ...) would necessarily affect the repository.
323
    def test_upgrade_preserves_signatures(self):
6257.2.1 by Jelmer Vernooij
Cope with repositories that don't support revision signatures.
324
        if not self.repository_format.supports_revision_signatures:
325
            raise tests.TestNotApplicable(
326
                "repository does not support signing revisions")
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.
327
        wt = self.make_branch_and_tree('source')
328
        wt.commit('A', allow_pointless=True, rev_id='A')
2018.5.90 by Andrew Bennetts
Fix test_upgrade_preserves_signatures; it incorrectly assumed that upgrade(wt, ...) would necessarily affect the repository.
329
        repo = wt.branch.repository
2592.3.39 by Robert Collins
Fugly version to remove signatures.kndx
330
        repo.lock_write()
331
        repo.start_write_group()
5751.2.3 by Jelmer Vernooij
More tests
332
        try:
333
            repo.sign_revision('A', gpg.LoopbackGPGStrategy(None))
334
        except errors.UnsupportedOperation:
335
            self.assertFalse(repo._format.supports_revision_signatures)
6113.1.2 by Jelmer Vernooij
Fix an import.
336
            raise tests.TestNotApplicable("signatures not supported by repository format")
2592.3.39 by Robert Collins
Fugly version to remove signatures.kndx
337
        repo.commit_write_group()
338
        repo.unlock()
2018.5.90 by Andrew Bennetts
Fix test_upgrade_preserves_signatures; it incorrectly assumed that upgrade(wt, ...) would necessarily affect the repository.
339
        old_signature = repo.get_signature_text('A')
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.
340
        try:
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
341
            old_format = controldir.ControlDirFormat.get_default_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.
342
            # This gives metadir branches something they can convert to.
343
            # it would be nice to have a 'latest' vs 'default' concept.
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
344
            format = controldir.format_registry.make_controldir(
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
345
                'development-subtree')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
346
            upgrade.upgrade(repo.controldir.root_transport.base, format=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.
347
        except errors.UpToDateFormat:
348
            # this is in the most current format already.
349
            return
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
350
        except errors.BadConversionTarget as e:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
351
            raise tests.TestSkipped(str(e))
352
        wt = workingtree.WorkingTree.open(wt.basedir)
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
353
        new_signature = wt.branch.repository.get_signature_text('A')
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.
354
        self.assertEqual(old_signature, new_signature)
355
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
356
    def test_format_description(self):
357
        repo = self.make_repository('.')
358
        text = repo._format.get_format_description()
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
359
        self.assertTrue(len(text))
1624.3.19 by Olaf Conradi
New call get_format_description to give a user-friendly description of a
360
3221.3.1 by Robert Collins
* Repository formats have a new supported-feature attribute
361
    def test_format_supports_external_lookups(self):
362
        repo = self.make_repository('.')
363
        self.assertSubset(
364
            [repo._format.supports_external_lookups], (True, False))
365
1666.1.6 by Robert Collins
Make knit the default format.
366
    def assertMessageRoundtrips(self, message):
367
        """Assert that message roundtrips to a repository and back intact."""
368
        tree = self.make_branch_and_tree('.')
369
        tree.commit(message, rev_id='a', allow_pointless=True)
370
        rev = tree.branch.repository.get_revision('a')
5815.4.13 by Jelmer Vernooij
Move corruption tests to bt.per_repository_vf.
371
        serializer = getattr(tree.branch.repository, "_serializer", None)
372
        if serializer is not None and serializer.squashes_xml_invalid_characters:
4416.5.1 by Jelmer Vernooij
Move squashing of XML-invalid characters to XMLSerializer.
373
            # we have to manually escape this as we dont try to
4443.1.2 by Jelmer Vernooij
Fix comment about XML escaping in tests.
374
            # roundtrip xml invalid characters in the xml-based serializers.
4416.5.1 by Jelmer Vernooij
Move squashing of XML-invalid characters to XMLSerializer.
375
            escaped_message, escape_count = re.subn(
376
                u'[^\x09\x0A\x0D\u0020-\uD7FF\uE000-\uFFFD]+',
377
                lambda match: match.group(0).encode('unicode_escape'),
378
                message)
379
            self.assertEqual(rev.message, escaped_message)
380
        else:
381
            self.assertEqual(rev.message, message)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
382
        # insist the class is unicode no matter what came in for
1666.1.6 by Robert Collins
Make knit the default format.
383
        # consistency.
384
        self.assertIsInstance(rev.message, unicode)
385
386
    def test_commit_unicode_message(self):
387
        # a siple unicode message should be preserved
388
        self.assertMessageRoundtrips(u'foo bar gamm\xae plop')
389
390
    def test_commit_unicode_control_characters(self):
391
        # a unicode message with control characters should roundtrip too.
3831.1.4 by John Arbash Meinel
Update the per-repository unicode commit test.
392
        unichars = [unichr(x) for x in range(256)]
393
        # '\r' is not directly allowed anymore, as it used to be translated
394
        # into '\n' anyway
395
        unichars[ord('\r')] = u'\n'
1666.1.6 by Robert Collins
Make knit the default format.
396
        self.assertMessageRoundtrips(
3831.1.4 by John Arbash Meinel
Update the per-repository unicode commit test.
397
            u"All 8-bit chars: " +  ''.join(unichars))
1534.4.41 by Robert Collins
Branch now uses BzrDir reasonably sanely.
398
1732.2.4 by Martin Pool
Split check into Branch.check and Repository.check
399
    def test_check_repository(self):
400
        """Check a fairly simple repository's history"""
401
        tree = self.make_branch_and_tree('.')
402
        tree.commit('initial empty commit', rev_id='a-rev',
403
                    allow_pointless=True)
2745.6.39 by Andrew Bennetts
Use scenario in test_check too, and make check actually report inconsistent parents to the end user.
404
        result = tree.branch.repository.check()
1732.2.4 by Martin Pool
Split check into Branch.check and Repository.check
405
        # writes to log; should accept both verbose or non-verbose
406
        result.report_results(verbose=True)
407
        result.report_results(verbose=False)
408
1756.1.5 by Aaron Bentley
Test get_revisions with all repository types (and fix bug...)
409
    def test_get_revisions(self):
410
        tree = self.make_branch_and_tree('.')
411
        tree.commit('initial empty commit', rev_id='a-rev',
412
                    allow_pointless=True)
413
        tree.commit('second empty commit', rev_id='b-rev',
414
                    allow_pointless=True)
415
        tree.commit('third empty commit', rev_id='c-rev',
416
                    allow_pointless=True)
417
        repo = tree.branch.repository
418
        revision_ids = ['a-rev', 'b-rev', 'c-rev']
419
        revisions = repo.get_revisions(revision_ids)
3376.2.4 by Martin Pool
Remove every assert statement from bzrlib!
420
        self.assertEqual(len(revisions), 3)
6631.2.1 by Martin
Run 2to3 zip fixer and refactor
421
        zipped = list(zip(revisions, revision_ids))
1756.1.5 by Aaron Bentley
Test get_revisions with all repository types (and fix bug...)
422
        self.assertEqual(len(zipped), 3)
423
        for revision, revision_id in zipped:
424
            self.assertEqual(revision.revision_id, revision_id)
425
            self.assertEqual(revision, repo.get_revision(revision_id))
1732.2.4 by Martin Pool
Split check into Branch.check and Repository.check
426
6714.1.3 by Jelmer Vernooij
Add Repository.iter_revisions.
427
    def test_iter_revisions(self):
428
        tree = self.make_branch_and_tree('.')
429
        tree.commit('initial empty commit', rev_id='a-rev',
430
                    allow_pointless=True)
431
        tree.commit('second empty commit', rev_id='b-rev',
432
                    allow_pointless=True)
433
        tree.commit('third empty commit', rev_id='c-rev',
434
                    allow_pointless=True)
435
        repo = tree.branch.repository
436
        revision_ids = ['a-rev', 'c-rev', 'b-rev', 'd-rev']
437
        revid_with_rev = repo.iter_revisions(revision_ids)
438
        self.assertEqual(
439
            set((revid, rev.revision_id if rev is not None else None)
440
                for (revid, rev) in revid_with_rev),
441
            {('a-rev', 'a-rev'),
442
             ('b-rev', 'b-rev'),
443
             ('c-rev', 'c-rev'),
444
             ('d-rev', None)})
445
1910.2.1 by Aaron Bentley
Ensure root entry always has a revision
446
    def test_root_entry_has_revision(self):
447
        tree = self.make_branch_and_tree('.')
448
        tree.commit('message', rev_id='rev_id')
2255.7.65 by Robert Collins
Split test_root_revision_entry into tree and repository portions.
449
        rev_tree = tree.branch.repository.revision_tree(tree.last_revision())
4253.3.1 by Robert Collins
per_repository/test_repository improvements (Robert Collins)
450
        rev_tree.lock_read()
451
        self.addCleanup(rev_tree.unlock)
5805.1.1 by Jelmer Vernooij
Avoid using inventories in some tests.
452
        root_id = rev_tree.get_root_id()
453
        self.assertEqual('rev_id', rev_tree.get_file_revision(root_id))
1910.2.36 by Aaron Bentley
Get upgrade from format4 under test and fixed for all formats
454
1910.2.37 by Aaron Bentley
Handle empty commits, fix test
455
    def test_pointless_commit(self):
456
        tree = self.make_branch_and_tree('.')
457
        self.assertRaises(errors.PointlessCommit, tree.commit, 'pointless',
458
                          allow_pointless=False)
459
        tree.commit('pointless', allow_pointless=True)
460
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
461
    def test_format_attributes(self):
462
        """All repository formats should have some basic attributes."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
463
        # create a repository to get a real format instance, not the
3128.1.3 by Vincent Ladeuil
Since we are there s/parameteris.*/parameteriz&/.
464
        # template from the test suite parameterization.
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
465
        repo = self.make_repository('.')
466
        repo._format.rich_root_data
467
        repo._format.supports_tree_reference
468
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
469
    def test_iter_files_bytes(self):
2708.1.3 by Aaron Bentley
Implement extract_files_bytes on Repository
470
        tree = self.make_branch_and_tree('tree')
471
        self.build_tree_contents([('tree/file1', 'foo'),
472
                                  ('tree/file2', 'bar')])
473
        tree.add(['file1', 'file2'], ['file1-id', 'file2-id'])
474
        tree.commit('rev1', rev_id='rev1')
475
        self.build_tree_contents([('tree/file1', 'baz')])
476
        tree.commit('rev2', rev_id='rev2')
2708.1.11 by Aaron Bentley
Test and tweak error handling
477
        repository = tree.branch.repository
2592.3.214 by Robert Collins
Merge bzr.dev.
478
        repository.lock_read()
479
        self.addCleanup(repository.unlock)
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
480
        extracted = dict((i, ''.join(b)) for i, b in
2708.1.11 by Aaron Bentley
Test and tweak error handling
481
                         repository.iter_files_bytes(
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
482
                         [('file1-id', 'rev1', 'file1-old'),
483
                          ('file1-id', 'rev2', 'file1-new'),
484
                          ('file2-id', 'rev1', 'file2'),
485
                         ]))
486
        self.assertEqual('foo', extracted['file1-old'])
487
        self.assertEqual('bar', extracted['file2'])
488
        self.assertEqual('baz', extracted['file1-new'])
2708.1.11 by Aaron Bentley
Test and tweak error handling
489
        self.assertRaises(errors.RevisionNotPresent, list,
490
                          repository.iter_files_bytes(
491
                          [('file1-id', 'rev3', 'file1-notpresent')]))
2592.3.102 by Robert Collins
Change the iter_files_bytes error to allow either RevisionNotPresent or NoSuchId when requesting a file that was not in the repository at all.
492
        self.assertRaises((errors.RevisionNotPresent, errors.NoSuchId), list,
2708.1.11 by Aaron Bentley
Test and tweak error handling
493
                          repository.iter_files_bytes(
494
                          [('file3-id', 'rev3', 'file1-notpresent')]))
2708.1.3 by Aaron Bentley
Implement extract_files_bytes on Repository
495
2850.4.1 by Andrew Bennetts
Add smoketest for repo.get_graph, and fix bug in RemoteRepository.get_graph that it reveals.
496
    def test_get_graph(self):
497
        """Bare-bones smoketest that all repositories implement get_graph."""
498
        repo = self.make_repository('repo')
2592.3.214 by Robert Collins
Merge bzr.dev.
499
        repo.lock_read()
500
        self.addCleanup(repo.unlock)
2850.4.1 by Andrew Bennetts
Add smoketest for repo.get_graph, and fix bug in RemoteRepository.get_graph that it reveals.
501
        repo.get_graph()
502
3146.1.1 by Aaron Bentley
Fix bad ghost handling in KnitParentsProvider
503
    def test_graph_ghost_handling(self):
504
        tree = self.make_branch_and_tree('here')
505
        tree.lock_write()
506
        self.addCleanup(tree.unlock)
507
        tree.commit('initial commit', rev_id='rev1')
508
        tree.add_parent_tree_id('ghost')
509
        tree.commit('commit-with-ghost', rev_id='rev2')
510
        graph = tree.branch.repository.get_graph()
511
        parents = graph.get_parent_map(['ghost', 'rev2'])
512
        self.assertTrue('ghost' not in parents)
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
513
        self.assertEqual(parents['rev2'], ('rev1', 'ghost'))
514
4913.4.4 by Jelmer Vernooij
Add test for Repository.get_known_graph_ancestry().
515
    def test_get_known_graph_ancestry(self):
516
        tree = self.make_branch_and_tree('here')
517
        tree.lock_write()
518
        self.addCleanup(tree.unlock)
519
        # A
520
        # |\
521
        # | B
522
        # |/
523
        # C
524
        tree.commit('initial commit', rev_id='A')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
525
        tree_other = tree.controldir.sprout('there').open_workingtree()
4913.4.4 by Jelmer Vernooij
Add test for Repository.get_known_graph_ancestry().
526
        tree_other.commit('another', rev_id='B')
527
        tree.merge_from_branch(tree_other.branch)
528
        tree.commit('another', rev_id='C')
529
        kg = tree.branch.repository.get_known_graph_ancestry(
530
            ['C'])
531
        self.assertEqual(['C'], list(kg.heads(['A', 'B', 'C'])))
532
        self.assertEqual(['A', 'B', 'C'], list(kg.topo_sort()))
533
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
534
    def test_parent_map_type(self):
535
        tree = self.make_branch_and_tree('here')
536
        tree.lock_write()
537
        self.addCleanup(tree.unlock)
538
        tree.commit('initial commit', rev_id='rev1')
539
        tree.commit('next commit', rev_id='rev2')
540
        graph = tree.branch.repository.get_graph()
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
541
        parents = graph.get_parent_map(
542
            [_mod_revision.NULL_REVISION, 'rev1', 'rev2'])
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
543
        for value in parents.values():
544
            self.assertIsInstance(value, tuple)
3146.1.1 by Aaron Bentley
Fix bad ghost handling in KnitParentsProvider
545
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
546
    def test_implements_revision_graph_can_have_wrong_parents(self):
547
        """All repositories should implement
548
        revision_graph_can_have_wrong_parents, so that check and reconcile can
549
        work correctly.
550
        """
551
        repo = self.make_repository('.')
552
        # This should work, not raise NotImplementedError:
5766.1.2 by Jelmer Vernooij
Fix two more references to old method.
553
        if not repo._format.revision_graph_can_have_wrong_parents:
2592.3.214 by Robert Collins
Merge bzr.dev.
554
            return
555
        repo.lock_read()
556
        self.addCleanup(repo.unlock)
557
        # This repo must also implement
558
        # _find_inconsistent_revision_parents and
559
        # _check_for_inconsistent_revision_parents.  So calling these
560
        # should not raise NotImplementedError.
561
        list(repo._find_inconsistent_revision_parents())
562
        repo._check_for_inconsistent_revision_parents()
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
563
2996.2.4 by Aaron Bentley
Rename function to add_signature_text
564
    def test_add_signature_text(self):
5751.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_revision_signatures.
565
        builder = self.make_branch_builder('.')
566
        builder.start_series()
567
        builder.build_snapshot('A', None, [
568
            ('add', ('', 'root-id', 'directory', None))])
5751.2.2 by Jelmer Vernooij
Fix tests.
569
        builder.finish_series()
5751.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_revision_signatures.
570
        b = builder.get_branch()
5751.2.2 by Jelmer Vernooij
Fix tests.
571
        b.lock_write()
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
572
        self.addCleanup(b.unlock)
573
        if b.repository._format.supports_revision_signatures:
6263.3.11 by Jelmer Vernooij
Fix get_signature_text test.
574
            b.repository.start_write_group()
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
575
            b.repository.add_signature_text('A', 'This might be a signature')
6263.3.11 by Jelmer Vernooij
Fix get_signature_text test.
576
            b.repository.commit_write_group()
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
577
            self.assertEqual('This might be a signature',
578
                             b.repository.get_signature_text('A'))
579
        else:
6263.3.11 by Jelmer Vernooij
Fix get_signature_text test.
580
            b.repository.start_write_group()
581
            self.addCleanup(b.repository.abort_write_group)
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
582
            self.assertRaises(errors.UnsupportedOperation,
583
                b.repository.add_signature_text, 'A',
584
                'This might be a signature')
2996.2.3 by Aaron Bentley
Add tests for install_revisions and add_signature
585
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
586
    # XXX: this helper duplicated from tests.test_repository
6164.2.2 by Jelmer Vernooij
Make shared argument default to 'None'.
587
    def make_remote_repository(self, path, shared=None):
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
588
        """Make a RemoteRepository object backed by a real repository that will
589
        be created at the given path."""
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
590
        repo = self.make_repository(path, shared=shared)
5017.3.42 by Vincent Ladeuil
-s bt.per_repository.test_repo passing
591
        smart_server = test_server.SmartTCPServer_for_testing()
4659.1.2 by Robert Collins
Refactor creation and shutdown of test servers to use a common helper,
592
        self.start_server(smart_server, self.get_server())
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
593
        remote_transport = transport.get_transport_from_url(
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
594
            smart_server.get_url()).clone(path)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
595
        if not repo.controldir._format.supports_transport(remote_transport):
6205.3.2 by Jelmer Vernooij
Use supports_transport in per_repository.test_repository.
596
            raise tests.TestNotApplicable(
597
                "format does not support transport")
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
598
        remote_bzrdir = controldir.ControlDir.open_from_transport(
599
            remote_transport)
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
600
        remote_repo = remote_bzrdir.open_repository()
601
        return remote_repo
602
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
603
    def test_sprout_from_hpss_preserves_format(self):
604
        """repo.sprout from a smart server preserves the repository format."""
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
605
        remote_repo = self.make_remote_repository('remote')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
606
        local_bzrdir = self.make_controldir('local')
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
607
        try:
608
            local_repo = remote_repo.sprout(local_bzrdir)
609
        except errors.TransportNotPossible:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
610
            raise tests.TestNotApplicable(
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
611
                "Cannot lock_read old formats like AllInOne over HPSS.")
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
612
        remote_backing_repo = controldir.ControlDir.open(
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
613
            self.get_vfs_only_url('remote')).open_repository()
6267.1.4 by Jelmer Vernooij
Fix test
614
        self.assertEqual(
615
            remote_backing_repo._format.network_name(),
616
            local_repo._format.network_name())
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
617
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
618
    def test_sprout_branch_from_hpss_preserves_repo_format(self):
619
        """branch.sprout from a smart server preserves the repository format.
620
        """
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
621
        if not self.repository_format.supports_leaving_lock:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
622
            raise tests.TestNotApplicable(
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
623
                "Format can not be used over HPSS")
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
624
        remote_repo = self.make_remote_repository('remote')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
625
        remote_branch = remote_repo.controldir.create_branch()
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
626
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
627
            local_bzrdir = remote_branch.controldir.sprout('local')
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
628
        except errors.TransportNotPossible:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
629
            raise tests.TestNotApplicable(
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
630
                "Cannot lock_read old formats like AllInOne over HPSS.")
631
        local_repo = local_bzrdir.open_repository()
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
632
        remote_backing_repo = controldir.ControlDir.open(
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
633
            self.get_vfs_only_url('remote')).open_repository()
634
        self.assertEqual(remote_backing_repo._format, local_repo._format)
635
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
636
    def test_sprout_branch_from_hpss_preserves_shared_repo_format(self):
637
        """branch.sprout from a smart server preserves the repository format of
638
        a branch from a shared repository.
639
        """
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
640
        if not self.repository_format.supports_leaving_lock:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
641
            raise tests.TestNotApplicable(
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
642
                "Format can not be used over HPSS")
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
643
        # Make a shared repo
644
        remote_repo = self.make_remote_repository('remote', shared=True)
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
645
        remote_backing_repo = controldir.ControlDir.open(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
646
            self.get_vfs_only_url('remote')).open_repository()
647
        # Make a branch in that repo in an old format that isn't the default
648
        # branch format for the repo.
6670.4.1 by Jelmer Vernooij
Update imports.
649
        from breezy.bzr.fullhistory import BzrBranchFormat5
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
650
        format = remote_backing_repo.controldir.cloning_metadir()
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
651
        format._branch_format = BzrBranchFormat5()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
652
        remote_transport = remote_repo.controldir.root_transport.clone('branch')
6207.3.3 by jelmer at samba
Fix tests and the like.
653
        controldir.ControlDir.create_branch_convenience(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
654
            remote_transport.base, force_new_repo=False, format=format)
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
655
        remote_branch = controldir.ControlDir.open_from_transport(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
656
            remote_transport).open_branch()
657
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
658
            local_bzrdir = remote_branch.controldir.sprout('local')
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
659
        except errors.TransportNotPossible:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
660
            raise tests.TestNotApplicable(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
661
                "Cannot lock_read old formats like AllInOne over HPSS.")
662
        local_repo = local_bzrdir.open_repository()
663
        self.assertEqual(remote_backing_repo._format, local_repo._format)
664
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
665
    def test_clone_to_hpss(self):
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
666
        if not self.repository_format.supports_leaving_lock:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
667
            raise tests.TestNotApplicable(
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
668
                "Cannot lock pre_metadir_formats remotely.")
669
        remote_transport = self.make_smart_server('remote')
670
        local_branch = self.make_branch('local')
671
        remote_branch = local_branch.create_clone_on_transport(remote_transport)
672
        self.assertEqual(
673
            local_branch.repository._format.supports_external_lookups,
674
            remote_branch.repository._format.supports_external_lookups)
675
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
676
    def test_clone_stacking_policy_upgrades(self):
677
        """Cloning an unstackable branch format to somewhere with a default
678
        stack-on branch upgrades branch and repo to match the target and honour
679
        the policy.
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
680
        """
681
        try:
682
            repo = self.make_repository('repo', shared=True)
683
        except errors.IncompatibleFormat:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
684
            raise tests.TestNotApplicable('Cannot make a shared repository')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
685
        if repo.controldir._format.fixed_components:
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
686
            self.knownFailure(
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
687
                "pre metadir branches do not upgrade on push "
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
688
                "with stacking policy")
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
689
        if isinstance(repo._format,
5757.1.5 by Jelmer Vernooij
Fix import.
690
                      knitpack_repo.RepositoryFormatKnitPack5RichRootBroken):
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
691
            raise tests.TestNotApplicable("unsupported format")
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
692
        # Make a source branch in 'repo' in an unstackable branch format
693
        bzrdir_format = self.repository_format._matchingbzrdir
694
        transport = self.get_transport('repo/branch')
695
        transport.mkdir('.')
696
        target_bzrdir = bzrdir_format.initialize_on_transport(transport)
6653.1.2 by Jelmer Vernooij
Fix imports.
697
        branch = _mod_bzrbranch.BzrBranchFormat6().initialize(target_bzrdir)
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
698
        # Ensure that stack_on will be stackable and match the serializer of
699
        # repo.
700
        if isinstance(repo, remote.RemoteRepository):
701
            repo._ensure_real()
702
            info_repo = repo._real_repository
4599.4.40 by Robert Collins
Fix formats for per_repository upgrade-to-stacking test.
703
        else:
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
704
            info_repo = repo
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
705
        format_description = info.describe_format(info_repo.controldir,
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
706
            info_repo, None, None)
707
        formats = format_description.split(' or ')
708
        stack_on_format = formats[0]
709
        if stack_on_format in ["pack-0.92", "dirstate", "metaweave"]:
710
            stack_on_format = "1.9"
711
        elif stack_on_format in ["dirstate-with-subtree", "rich-root",
712
            "rich-root-pack", "pack-0.92-subtree"]:
713
            stack_on_format = "1.9-rich-root"
714
        # formats not tested for above are already stackable, so we can use the
715
        # format as-is.
716
        stack_on = self.make_branch('stack-on-me', format=stack_on_format)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
717
        self.make_controldir('.').get_config().set_default_stack_on('stack-on-me')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
718
        target = branch.controldir.clone(self.get_url('target'))
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
719
        # The target branch supports stacking.
720
        self.assertTrue(target.open_branch()._format.supports_stacking())
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
721
        if isinstance(repo, remote.RemoteRepository):
722
            repo._ensure_real()
723
            repo = repo._real_repository
4005.2.1 by Robert Collins
Fix RemoteBranch to be used correctly in tests using bzr+ssh, to fire off Branch hooks correctly, and improve the branch_implementations tests to check that making a branch gets the right format under test.
724
        target_repo = target.open_repository()
725
        if isinstance(target_repo, remote.RemoteRepository):
726
            target_repo._ensure_real()
727
            target_repo = target_repo._real_repository
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
728
        # The repository format is unchanged if it could already stack, or the
729
        # same as the stack on.
730
        if repo._format.supports_external_lookups:
731
            self.assertEqual(repo._format, target_repo._format)
732
        else:
733
            self.assertEqual(stack_on.repository._format, target_repo._format)
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
734
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
735
    def test__make_parents_provider(self):
736
        """Repositories must have a _make_parents_provider method that returns
3099.3.5 by John Arbash Meinel
Update the last couple of places that referred to Provider.get_parents() directly.
737
        an object with a get_parent_map method.
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
738
        """
739
        repo = self.make_repository('repo')
3099.3.5 by John Arbash Meinel
Update the last couple of places that referred to Provider.get_parents() directly.
740
        repo._make_parents_provider().get_parent_map
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
741
6150.2.2 by Jelmer Vernooij
Make various make_repository methods default their shared setting to None.
742
    def make_repository_and_foo_bar(self, shared=None):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
743
        made_control = self.make_controldir('repository')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
744
        repo = made_control.create_repository(shared=shared)
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
745
        if not repo._format.supports_nesting_repositories:
746
            raise tests.TestNotApplicable("repository does not support "
747
                "nesting repositories")
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
748
        controldir.ControlDir.create_branch_convenience(
749
            self.get_url('repository/foo'), force_new_repo=False)
750
        controldir.ControlDir.create_branch_convenience(
751
            self.get_url('repository/bar'), force_new_repo=True)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
752
        baz = self.make_controldir('repository/baz')
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
753
        qux = self.make_branch('repository/baz/qux')
3140.1.6 by Aaron Bentley
Add test that nested branches are returned
754
        quxx = self.make_branch('repository/baz/qux/quxx')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
755
        return repo
756
757
    def test_find_branches(self):
6150.2.2 by Jelmer Vernooij
Make various make_repository methods default their shared setting to None.
758
        repo = self.make_repository_and_foo_bar()
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
759
        branches = repo.find_branches()
760
        self.assertContainsRe(branches[-1].base, 'repository/foo/$')
3140.1.6 by Aaron Bentley
Add test that nested branches are returned
761
        self.assertContainsRe(branches[-3].base, 'repository/baz/qux/$')
762
        self.assertContainsRe(branches[-2].base, 'repository/baz/qux/quxx/$')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
763
        # in some formats, creating a repo creates a branch
3140.1.6 by Aaron Bentley
Add test that nested branches are returned
764
        if len(branches) == 6:
765
            self.assertContainsRe(branches[-4].base, 'repository/baz/$')
766
            self.assertContainsRe(branches[-5].base, 'repository/bar/$')
767
            self.assertContainsRe(branches[-6].base, 'repository/$')
768
        else:
769
            self.assertEqual(4, len(branches))
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
770
            self.assertContainsRe(branches[-4].base, 'repository/bar/$')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
771
772
    def test_find_branches_using(self):
773
        try:
774
            repo = self.make_repository_and_foo_bar(shared=True)
775
        except errors.IncompatibleFormat:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
776
            raise tests.TestNotApplicable
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
777
        branches = repo.find_branches(using=True)
778
        self.assertContainsRe(branches[-1].base, 'repository/foo/$')
779
        # in some formats, creating a repo creates a branch
780
        if len(branches) == 2:
781
            self.assertContainsRe(branches[-2].base, 'repository/$')
782
        else:
783
            self.assertEqual(1, len(branches))
784
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
785
    def test_find_branches_using_standalone(self):
786
        branch = self.make_branch('branch')
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
787
        if not branch.repository._format.supports_nesting_repositories:
788
            raise tests.TestNotApplicable("format does not support nesting "
789
                "repositories")
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
790
        contained = self.make_branch('branch/contained')
791
        branches = branch.repository.find_branches(using=True)
792
        self.assertEqual([branch.base], [b.base for b in branches])
793
        branches = branch.repository.find_branches(using=False)
794
        self.assertEqual([branch.base, contained.base],
795
                         [b.base for b in branches])
796
797
    def test_find_branches_using_empty_standalone_repo(self):
6164.2.2 by Jelmer Vernooij
Make shared argument default to 'None'.
798
        try:
799
            repo = self.make_repository('repo', shared=False)
800
        except errors.IncompatibleFormat:
801
            raise tests.TestNotApplicable("format does not support standalone "
802
                "repositories")
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
803
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
804
            repo.controldir.open_branch()
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
805
        except errors.NotBranchError:
806
            self.assertEqual([], repo.find_branches(using=True))
807
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
808
            self.assertEqual([repo.controldir.root_transport.base],
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
809
                             [b.base for b in repo.find_branches(using=True)])
810
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
811
    def test_set_get_make_working_trees_true(self):
812
        repo = self.make_repository('repo')
3349.1.2 by Aaron Bentley
Change ValueError to RepositoryUpgradeRequired
813
        try:
814
            repo.set_make_working_trees(True)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
815
        except (errors.RepositoryUpgradeRequired, errors.UnsupportedOperation) as e:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
816
            raise tests.TestNotApplicable('Format does not support this flag.')
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
817
        self.assertTrue(repo.make_working_trees())
818
819
    def test_set_get_make_working_trees_false(self):
820
        repo = self.make_repository('repo')
821
        try:
822
            repo.set_make_working_trees(False)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
823
        except (errors.RepositoryUpgradeRequired, errors.UnsupportedOperation) as e:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
824
            raise tests.TestNotApplicable('Format does not support this flag.')
3349.1.2 by Aaron Bentley
Change ValueError to RepositoryUpgradeRequired
825
        self.assertFalse(repo.make_working_trees())
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
826
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
827
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
828
class TestRepositoryLocking(per_repository.TestCaseWithRepository):
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
829
830
    def test_leave_lock_in_place(self):
831
        repo = self.make_repository('r')
832
        # Lock the repository, then use leave_lock_in_place so that when we
833
        # unlock the repository the lock is still held on disk.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
834
        token = repo.lock_write().repository_token
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
835
        try:
2018.5.76 by Andrew Bennetts
Testing that repository.{dont_,}leave_lock_in_place raises NotImplementedError if lock_write returns None.
836
            if token is None:
837
                # This test does not apply, because this repository refuses lock
838
                # tokens.
839
                self.assertRaises(NotImplementedError, repo.leave_lock_in_place)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
840
                return
2018.5.76 by Andrew Bennetts
Testing that repository.{dont_,}leave_lock_in_place raises NotImplementedError if lock_write returns None.
841
            repo.leave_lock_in_place()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
842
        finally:
843
            repo.unlock()
844
        # We should be unable to relock the repo.
845
        self.assertRaises(errors.LockContention, repo.lock_write)
4327.1.8 by Vincent Ladeuil
Fix 4 more lock-related test failures.
846
        # Cleanup
847
        repo.lock_write(token)
848
        repo.dont_leave_lock_in_place()
849
        repo.unlock()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
850
851
    def test_dont_leave_lock_in_place(self):
852
        repo = self.make_repository('r')
853
        # Create a lock on disk.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
854
        token = repo.lock_write().repository_token
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
855
        try:
856
            if token is None:
857
                # This test does not apply, because this repository refuses lock
858
                # tokens.
2018.5.76 by Andrew Bennetts
Testing that repository.{dont_,}leave_lock_in_place raises NotImplementedError if lock_write returns None.
859
                self.assertRaises(NotImplementedError,
860
                                  repo.dont_leave_lock_in_place)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
861
                return
862
            try:
863
                repo.leave_lock_in_place()
864
            except NotImplementedError:
865
                # This repository doesn't support this API.
866
                return
867
        finally:
868
            repo.unlock()
869
        # Reacquire the lock (with a different repository object) by using the
870
        # token.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
871
        new_repo = repo.controldir.open_repository()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
872
        new_repo.lock_write(token=token)
873
        # Call dont_leave_lock_in_place, so that the lock will be released by
874
        # this instance, even though the lock wasn't originally acquired by it.
875
        new_repo.dont_leave_lock_in_place()
876
        new_repo.unlock()
877
        # Now the repository is unlocked.  Test this by locking it (without a
878
        # token).
879
        repo.lock_write()
880
        repo.unlock()
881
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
882
    def test_lock_read_then_unlock(self):
883
        # Calling lock_read then unlocking should work without errors.
884
        repo = self.make_repository('r')
885
        repo.lock_read()
886
        repo.unlock()
887
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
888
    def test_lock_read_returns_unlockable(self):
889
        repo = self.make_repository('r')
890
        self.assertThat(repo.lock_read, ReturnsUnlockable(repo))
891
892
    def test_lock_write_returns_unlockable(self):
893
        repo = self.make_repository('r')
894
        self.assertThat(repo.lock_write, ReturnsUnlockable(repo))
895
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
896
2018.5.29 by Robert Collins
Dont run the vfat repository test on RemoteRepositories as there is no point.
897
# FIXME: document why this is a TestCaseWithTransport rather than a
898
#        TestCaseWithRepository
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
899
class TestEscaping(tests.TestCaseWithTransport):
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
900
    """Test that repositories can be stored correctly on VFAT transports.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
901
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
902
    Makes sure we have proper escaping of invalid characters, etc.
903
904
    It'd be better to test all operations on the FakeVFATTransportDecorator,
905
    but working trees go straight to the os not through the Transport layer.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
906
    Therefore we build some history first in the regular way and then
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
907
    check it's safe to access for vfat.
908
    """
909
910
    def test_on_vfat(self):
2018.5.29 by Robert Collins
Dont run the vfat repository test on RemoteRepositories as there is no point.
911
        # dont bother with remote repository testing, because this test is
912
        # about local disk layout/support.
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
913
        if isinstance(self.repository_format, remote.RemoteRepositoryFormat):
2018.5.29 by Robert Collins
Dont run the vfat repository test on RemoteRepositories as there is no point.
914
            return
5017.3.42 by Vincent Ladeuil
-s bt.per_repository.test_repo passing
915
        self.transport_server = test_server.FakeVFATServer
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
916
        FOO_ID = 'foo<:>ID'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
917
        REV_ID = 'revid-1'
918
        # this makes a default format repository always, which is wrong:
919
        # it should be a TestCaseWithRepository in order to get the
2018.5.29 by Robert Collins
Dont run the vfat repository test on RemoteRepositories as there is no point.
920
        # default format.
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
921
        wt = self.make_branch_and_tree('repo')
2052.2.1 by Alexander Belchenko
test_on_vfat win32 fix: use binary line-endings
922
        self.build_tree(["repo/foo"], line_endings='binary')
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
923
        # add file with id containing wierd characters
924
        wt.add(['foo'], [FOO_ID])
925
        wt.commit('this is my new commit', rev_id=REV_ID)
926
        # now access over vfat; should be safe
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
927
        branch = controldir.ControlDir.open(self.get_url('repo')).open_branch()
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
928
        revtree = branch.repository.revision_tree(REV_ID)
3015.2.13 by Robert Collins
More lock correctness for the use of get_file_text in repository_implementations.
929
        revtree.lock_read()
930
        self.addCleanup(revtree.unlock)
1986.1.1 by Robert Collins
Move test_branch_on_vfat into a repository implementation test, to ensure that all repository formats are safe on vfat.
931
        contents = revtree.get_file_text(FOO_ID)
932
        self.assertEqual(contents, 'contents of repo/foo\n')
2520.4.54 by Aaron Bentley
Hang a create_bundle method off repository
933
934
    def test_create_bundle(self):
935
        wt = self.make_branch_and_tree('repo')
936
        self.build_tree(['repo/file1'])
937
        wt.add('file1')
938
        wt.commit('file1', rev_id='rev1')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
939
        fileobj = BytesIO()
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
940
        wt.branch.repository.create_bundle(
941
            'rev1', _mod_revision.NULL_REVISION, fileobj)
5158.6.4 by Martin Pool
Repository implements ControlComponent too
942
943
944
class TestRepositoryControlComponent(per_repository.TestCaseWithRepository):
945
    """Repository implementations adequately implement ControlComponent."""
5673.1.1 by Jelmer Vernooij
Add flexible_components boolean to ControlDir if the
946
5158.6.4 by Martin Pool
Repository implements ControlComponent too
947
    def test_urls(self):
948
        repo = self.make_repository('repo')
949
        self.assertIsInstance(repo.user_url, str)
950
        self.assertEqual(repo.user_url, repo.user_transport.base)
6227.1.1 by Jelmer Vernooij
Add knownFailure for incorrect behaviour in Repository.get_revision_delta().
951
        # for all current bzrdir implementations the user dir must be
5158.6.4 by Martin Pool
Repository implements ControlComponent too
952
        # above the control dir but we might need to relax that?
953
        self.assertEqual(repo.control_url.find(repo.user_url), 0)
954
        self.assertEqual(repo.control_url, repo.control_transport.base)
6227.1.1 by Jelmer Vernooij
Add knownFailure for incorrect behaviour in Repository.get_revision_delta().
955
956
957
class TestDeltaRevisionFiltered(per_repository.TestCaseWithRepository):
958
959
    def setUp(self):
960
        super(TestDeltaRevisionFiltered, self).setUp()
961
        tree_a = self.make_branch_and_tree('a')
962
        self.build_tree(['a/foo', 'a/bar/', 'a/bar/b1', 'a/bar/b2', 'a/baz'])
963
        tree_a.add(['foo', 'bar', 'bar/b1', 'bar/b2', 'baz'],
964
                   ['foo-id', 'bar-id', 'b1-id', 'b2-id', 'baz-id'])
965
        tree_a.commit('rev1', rev_id='rev1')
966
        self.build_tree(['a/bar/b3'])
967
        tree_a.add('bar/b3', 'b3-id')
968
        tree_a.commit('rev2', rev_id='rev2')
969
        self.repository = tree_a.branch.repository
970
971
    def test_multiple_files(self):
972
        # Test multiple files
973
        delta = self.repository.get_revision_delta('rev1',
974
            specific_fileids=['foo-id', 'baz-id'])
975
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
976
        self.assertEqual([
977
            ('baz', 'baz-id', 'file'),
978
            ('foo', 'foo-id', 'file'),
979
            ], delta.added)
980
981
    def test_directory(self):
982
        # Test a directory
983
        delta = self.repository.get_revision_delta('rev1',
984
            specific_fileids=['bar-id'])
985
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
986
        self.assertEqual([
987
            ('bar', 'bar-id', 'directory'),
988
            ('bar/b1', 'b1-id', 'file'),
989
            ('bar/b2', 'b2-id', 'file'),
990
            ], delta.added)
991
992
    def test_unrelated(self):
993
        # Try another revision
994
        delta = self.repository.get_revision_delta('rev2',
995
                specific_fileids=['foo-id'])
996
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
997
        self.assertEqual([], delta.added)
998
999
    def test_file_in_directory(self):
1000
        # Test a file in a directory, both of which were added
1001
        delta = self.repository.get_revision_delta('rev1',
1002
            specific_fileids=['b2-id'])
1003
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
1004
        self.assertEqual([
1005
            ('bar', 'bar-id', 'directory'),
1006
            ('bar/b2', 'b2-id', 'file'),
1007
            ], delta.added)
1008
1009
    def test_file_in_unchanged_directory(self):
1010
        delta = self.repository.get_revision_delta('rev2',
1011
            specific_fileids=['b3-id'])
1012
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
1013
        if delta.added == [
1014
            ('bar', 'bar-id', 'directory'),
1015
            ('bar/b3', 'b3-id', 'file')]:
1016
            self.knownFailure("bzr incorrectly reports 'bar' as added - "
1017
                              "bug 878217")
1018
        self.assertEqual([
1019
            ('bar/b3', 'b3-id', 'file'),
1020
            ], delta.added)