/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
1910.2.1 by Aaron Bentley
Ensure root entry always has a revision
427
    def test_root_entry_has_revision(self):
428
        tree = self.make_branch_and_tree('.')
429
        tree.commit('message', rev_id='rev_id')
2255.7.65 by Robert Collins
Split test_root_revision_entry into tree and repository portions.
430
        rev_tree = tree.branch.repository.revision_tree(tree.last_revision())
4253.3.1 by Robert Collins
per_repository/test_repository improvements (Robert Collins)
431
        rev_tree.lock_read()
432
        self.addCleanup(rev_tree.unlock)
5805.1.1 by Jelmer Vernooij
Avoid using inventories in some tests.
433
        root_id = rev_tree.get_root_id()
434
        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
435
1910.2.37 by Aaron Bentley
Handle empty commits, fix test
436
    def test_pointless_commit(self):
437
        tree = self.make_branch_and_tree('.')
438
        self.assertRaises(errors.PointlessCommit, tree.commit, 'pointless',
439
                          allow_pointless=False)
440
        tree.commit('pointless', allow_pointless=True)
441
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
442
    def test_format_attributes(self):
443
        """All repository formats should have some basic attributes."""
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
444
        # create a repository to get a real format instance, not the
3128.1.3 by Vincent Ladeuil
Since we are there s/parameteris.*/parameteriz&/.
445
        # template from the test suite parameterization.
2323.5.17 by Martin Pool
Add supports_tree_reference to all repo formats (robert)
446
        repo = self.make_repository('.')
447
        repo._format.rich_root_data
448
        repo._format.supports_tree_reference
449
2708.1.7 by Aaron Bentley
Rename extract_files_bytes to iter_files_bytes
450
    def test_iter_files_bytes(self):
2708.1.3 by Aaron Bentley
Implement extract_files_bytes on Repository
451
        tree = self.make_branch_and_tree('tree')
452
        self.build_tree_contents([('tree/file1', 'foo'),
453
                                  ('tree/file2', 'bar')])
454
        tree.add(['file1', 'file2'], ['file1-id', 'file2-id'])
455
        tree.commit('rev1', rev_id='rev1')
456
        self.build_tree_contents([('tree/file1', 'baz')])
457
        tree.commit('rev2', rev_id='rev2')
2708.1.11 by Aaron Bentley
Test and tweak error handling
458
        repository = tree.branch.repository
2592.3.214 by Robert Collins
Merge bzr.dev.
459
        repository.lock_read()
460
        self.addCleanup(repository.unlock)
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
461
        extracted = dict((i, ''.join(b)) for i, b in
2708.1.11 by Aaron Bentley
Test and tweak error handling
462
                         repository.iter_files_bytes(
2708.1.6 by Aaron Bentley
Turn extract_files_bytes into an iterator
463
                         [('file1-id', 'rev1', 'file1-old'),
464
                          ('file1-id', 'rev2', 'file1-new'),
465
                          ('file2-id', 'rev1', 'file2'),
466
                         ]))
467
        self.assertEqual('foo', extracted['file1-old'])
468
        self.assertEqual('bar', extracted['file2'])
469
        self.assertEqual('baz', extracted['file1-new'])
2708.1.11 by Aaron Bentley
Test and tweak error handling
470
        self.assertRaises(errors.RevisionNotPresent, list,
471
                          repository.iter_files_bytes(
472
                          [('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.
473
        self.assertRaises((errors.RevisionNotPresent, errors.NoSuchId), list,
2708.1.11 by Aaron Bentley
Test and tweak error handling
474
                          repository.iter_files_bytes(
475
                          [('file3-id', 'rev3', 'file1-notpresent')]))
2708.1.3 by Aaron Bentley
Implement extract_files_bytes on Repository
476
2850.4.1 by Andrew Bennetts
Add smoketest for repo.get_graph, and fix bug in RemoteRepository.get_graph that it reveals.
477
    def test_get_graph(self):
478
        """Bare-bones smoketest that all repositories implement get_graph."""
479
        repo = self.make_repository('repo')
2592.3.214 by Robert Collins
Merge bzr.dev.
480
        repo.lock_read()
481
        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.
482
        repo.get_graph()
483
3146.1.1 by Aaron Bentley
Fix bad ghost handling in KnitParentsProvider
484
    def test_graph_ghost_handling(self):
485
        tree = self.make_branch_and_tree('here')
486
        tree.lock_write()
487
        self.addCleanup(tree.unlock)
488
        tree.commit('initial commit', rev_id='rev1')
489
        tree.add_parent_tree_id('ghost')
490
        tree.commit('commit-with-ghost', rev_id='rev2')
491
        graph = tree.branch.repository.get_graph()
492
        parents = graph.get_parent_map(['ghost', 'rev2'])
493
        self.assertTrue('ghost' not in parents)
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
494
        self.assertEqual(parents['rev2'], ('rev1', 'ghost'))
495
4913.4.4 by Jelmer Vernooij
Add test for Repository.get_known_graph_ancestry().
496
    def test_get_known_graph_ancestry(self):
497
        tree = self.make_branch_and_tree('here')
498
        tree.lock_write()
499
        self.addCleanup(tree.unlock)
500
        # A
501
        # |\
502
        # | B
503
        # |/
504
        # C
505
        tree.commit('initial commit', rev_id='A')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
506
        tree_other = tree.controldir.sprout('there').open_workingtree()
4913.4.4 by Jelmer Vernooij
Add test for Repository.get_known_graph_ancestry().
507
        tree_other.commit('another', rev_id='B')
508
        tree.merge_from_branch(tree_other.branch)
509
        tree.commit('another', rev_id='C')
510
        kg = tree.branch.repository.get_known_graph_ancestry(
511
            ['C'])
512
        self.assertEqual(['C'], list(kg.heads(['A', 'B', 'C'])))
513
        self.assertEqual(['A', 'B', 'C'], list(kg.topo_sort()))
514
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
515
    def test_parent_map_type(self):
516
        tree = self.make_branch_and_tree('here')
517
        tree.lock_write()
518
        self.addCleanup(tree.unlock)
519
        tree.commit('initial commit', rev_id='rev1')
520
        tree.commit('next commit', rev_id='rev2')
521
        graph = tree.branch.repository.get_graph()
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
522
        parents = graph.get_parent_map(
523
            [_mod_revision.NULL_REVISION, 'rev1', 'rev2'])
3146.1.2 by Aaron Bentley
ParentsProviders now provide tuples of parents, never lists
524
        for value in parents.values():
525
            self.assertIsInstance(value, tuple)
3146.1.1 by Aaron Bentley
Fix bad ghost handling in KnitParentsProvider
526
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
527
    def test_implements_revision_graph_can_have_wrong_parents(self):
528
        """All repositories should implement
529
        revision_graph_can_have_wrong_parents, so that check and reconcile can
530
        work correctly.
531
        """
532
        repo = self.make_repository('.')
533
        # This should work, not raise NotImplementedError:
5766.1.2 by Jelmer Vernooij
Fix two more references to old method.
534
        if not repo._format.revision_graph_can_have_wrong_parents:
2592.3.214 by Robert Collins
Merge bzr.dev.
535
            return
536
        repo.lock_read()
537
        self.addCleanup(repo.unlock)
538
        # This repo must also implement
539
        # _find_inconsistent_revision_parents and
540
        # _check_for_inconsistent_revision_parents.  So calling these
541
        # should not raise NotImplementedError.
542
        list(repo._find_inconsistent_revision_parents())
543
        repo._check_for_inconsistent_revision_parents()
2819.2.4 by Andrew Bennetts
Add a 'revision_graph_can_have_wrong_parents' method to repository.
544
2996.2.4 by Aaron Bentley
Rename function to add_signature_text
545
    def test_add_signature_text(self):
5751.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_revision_signatures.
546
        builder = self.make_branch_builder('.')
547
        builder.start_series()
548
        builder.build_snapshot('A', None, [
549
            ('add', ('', 'root-id', 'directory', None))])
5751.2.2 by Jelmer Vernooij
Fix tests.
550
        builder.finish_series()
5751.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_revision_signatures.
551
        b = builder.get_branch()
5751.2.2 by Jelmer Vernooij
Fix tests.
552
        b.lock_write()
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
553
        self.addCleanup(b.unlock)
554
        if b.repository._format.supports_revision_signatures:
6263.3.11 by Jelmer Vernooij
Fix get_signature_text test.
555
            b.repository.start_write_group()
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
556
            b.repository.add_signature_text('A', 'This might be a signature')
6263.3.11 by Jelmer Vernooij
Fix get_signature_text test.
557
            b.repository.commit_write_group()
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
558
            self.assertEqual('This might be a signature',
559
                             b.repository.get_signature_text('A'))
560
        else:
6263.3.11 by Jelmer Vernooij
Fix get_signature_text test.
561
            b.repository.start_write_group()
562
            self.addCleanup(b.repository.abort_write_group)
5751.2.4 by Jelmer Vernooij
Use addCleanup to call abort_write_group rather than try/finally.
563
            self.assertRaises(errors.UnsupportedOperation,
564
                b.repository.add_signature_text, 'A',
565
                'This might be a signature')
2996.2.3 by Aaron Bentley
Add tests for install_revisions and add_signature
566
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
567
    # XXX: this helper duplicated from tests.test_repository
6164.2.2 by Jelmer Vernooij
Make shared argument default to 'None'.
568
    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.
569
        """Make a RemoteRepository object backed by a real repository that will
570
        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.
571
        repo = self.make_repository(path, shared=shared)
5017.3.42 by Vincent Ladeuil
-s bt.per_repository.test_repo passing
572
        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,
573
        self.start_server(smart_server, self.get_server())
6083.1.1 by Jelmer Vernooij
Use get_transport_from_{url,path} in more places.
574
        remote_transport = transport.get_transport_from_url(
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
575
            smart_server.get_url()).clone(path)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
576
        if not repo.controldir._format.supports_transport(remote_transport):
6205.3.2 by Jelmer Vernooij
Use supports_transport in per_repository.test_repository.
577
            raise tests.TestNotApplicable(
578
                "format does not support transport")
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
579
        remote_bzrdir = controldir.ControlDir.open_from_transport(
580
            remote_transport)
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
581
        remote_repo = remote_bzrdir.open_repository()
582
        return remote_repo
583
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
584
    def test_sprout_from_hpss_preserves_format(self):
585
        """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.
586
        remote_repo = self.make_remote_repository('remote')
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
587
        local_bzrdir = self.make_controldir('local')
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
588
        try:
589
            local_repo = remote_repo.sprout(local_bzrdir)
590
        except errors.TransportNotPossible:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
591
            raise tests.TestNotApplicable(
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
592
                "Cannot lock_read old formats like AllInOne over HPSS.")
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
593
        remote_backing_repo = controldir.ControlDir.open(
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
594
            self.get_vfs_only_url('remote')).open_repository()
6267.1.4 by Jelmer Vernooij
Fix test
595
        self.assertEqual(
596
            remote_backing_repo._format.network_name(),
597
            local_repo._format.network_name())
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
598
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
599
    def test_sprout_branch_from_hpss_preserves_repo_format(self):
600
        """branch.sprout from a smart server preserves the repository format.
601
        """
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
602
        if not self.repository_format.supports_leaving_lock:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
603
            raise tests.TestNotApplicable(
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
604
                "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.
605
        remote_repo = self.make_remote_repository('remote')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
606
        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.
607
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
608
            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.
609
        except errors.TransportNotPossible:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
610
            raise tests.TestNotApplicable(
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
611
                "Cannot lock_read old formats like AllInOne over HPSS.")
612
        local_repo = local_bzrdir.open_repository()
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
613
        remote_backing_repo = controldir.ControlDir.open(
3047.1.2 by Andrew Bennetts
Directly test that sprouting branches from a HPSS preserves the repository format.
614
            self.get_vfs_only_url('remote')).open_repository()
615
        self.assertEqual(remote_backing_repo._format, local_repo._format)
616
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
617
    def test_sprout_branch_from_hpss_preserves_shared_repo_format(self):
618
        """branch.sprout from a smart server preserves the repository format of
619
        a branch from a shared repository.
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")
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
624
        # Make a shared repo
625
        remote_repo = self.make_remote_repository('remote', shared=True)
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
626
        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.
627
            self.get_vfs_only_url('remote')).open_repository()
628
        # Make a branch in that repo in an old format that isn't the default
629
        # branch format for the repo.
6670.4.1 by Jelmer Vernooij
Update imports.
630
        from breezy.bzr.fullhistory import BzrBranchFormat5
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
631
        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.
632
        format._branch_format = BzrBranchFormat5()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
633
        remote_transport = remote_repo.controldir.root_transport.clone('branch')
6207.3.3 by jelmer at samba
Fix tests and the like.
634
        controldir.ControlDir.create_branch_convenience(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
635
            remote_transport.base, force_new_repo=False, format=format)
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
636
        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.
637
            remote_transport).open_branch()
638
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
639
            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.
640
        except errors.TransportNotPossible:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
641
            raise tests.TestNotApplicable(
3697.6.2 by Andrew Bennetts
Add test for preserving shared repository format when sprouting from a smart server.
642
                "Cannot lock_read old formats like AllInOne over HPSS.")
643
        local_repo = local_bzrdir.open_repository()
644
        self.assertEqual(remote_backing_repo._format, local_repo._format)
645
4118.1.1 by Andrew Bennetts
Fix performance regression (many small round-trips) when pushing to a remote pack, and tidy the tests.
646
    def test_clone_to_hpss(self):
5674.1.1 by Jelmer Vernooij
Add supports_leave_lock flag to BranchFormat and RepositoryFormat.
647
        if not self.repository_format.supports_leaving_lock:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
648
            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.
649
                "Cannot lock pre_metadir_formats remotely.")
650
        remote_transport = self.make_smart_server('remote')
651
        local_branch = self.make_branch('local')
652
        remote_branch = local_branch.create_clone_on_transport(remote_transport)
653
        self.assertEqual(
654
            local_branch.repository._format.supports_external_lookups,
655
            remote_branch.repository._format.supports_external_lookups)
656
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
657
    def test_clone_stacking_policy_upgrades(self):
658
        """Cloning an unstackable branch format to somewhere with a default
659
        stack-on branch upgrades branch and repo to match the target and honour
660
        the policy.
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
661
        """
662
        try:
663
            repo = self.make_repository('repo', shared=True)
664
        except errors.IncompatibleFormat:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
665
            raise tests.TestNotApplicable('Cannot make a shared repository')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
666
        if repo.controldir._format.fixed_components:
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
667
            self.knownFailure(
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
668
                "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.
669
                "with stacking policy")
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
670
        if isinstance(repo._format,
5757.1.5 by Jelmer Vernooij
Fix import.
671
                      knitpack_repo.RepositoryFormatKnitPack5RichRootBroken):
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
672
            raise tests.TestNotApplicable("unsupported format")
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
673
        # Make a source branch in 'repo' in an unstackable branch format
674
        bzrdir_format = self.repository_format._matchingbzrdir
675
        transport = self.get_transport('repo/branch')
676
        transport.mkdir('.')
677
        target_bzrdir = bzrdir_format.initialize_on_transport(transport)
6653.1.2 by Jelmer Vernooij
Fix imports.
678
        branch = _mod_bzrbranch.BzrBranchFormat6().initialize(target_bzrdir)
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
679
        # Ensure that stack_on will be stackable and match the serializer of
680
        # repo.
681
        if isinstance(repo, remote.RemoteRepository):
682
            repo._ensure_real()
683
            info_repo = repo._real_repository
4599.4.40 by Robert Collins
Fix formats for per_repository upgrade-to-stacking test.
684
        else:
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
685
            info_repo = repo
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
686
        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.
687
            info_repo, None, None)
688
        formats = format_description.split(' or ')
689
        stack_on_format = formats[0]
690
        if stack_on_format in ["pack-0.92", "dirstate", "metaweave"]:
691
            stack_on_format = "1.9"
692
        elif stack_on_format in ["dirstate-with-subtree", "rich-root",
693
            "rich-root-pack", "pack-0.92-subtree"]:
694
            stack_on_format = "1.9-rich-root"
695
        # formats not tested for above are already stackable, so we can use the
696
        # format as-is.
697
        stack_on = self.make_branch('stack-on-me', format=stack_on_format)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
698
        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.
699
        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.
700
        # The target branch supports stacking.
701
        self.assertTrue(target.open_branch()._format.supports_stacking())
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
702
        if isinstance(repo, remote.RemoteRepository):
703
            repo._ensure_real()
704
            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.
705
        target_repo = target.open_repository()
706
        if isinstance(target_repo, remote.RemoteRepository):
707
            target_repo._ensure_real()
708
            target_repo = target_repo._real_repository
4599.4.45 by Robert Collins
Fix a final failure in stacking upgrade of branch/repository tests.
709
        # The repository format is unchanged if it could already stack, or the
710
        # same as the stack on.
711
        if repo._format.supports_external_lookups:
712
            self.assertEqual(repo._format, target_repo._format)
713
        else:
714
            self.assertEqual(stack_on.repository._format, target_repo._format)
3904.3.8 by Andrew Bennetts
Add test requested by John, and fix whitespace nit.
715
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
716
    def test__make_parents_provider(self):
717
        """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.
718
        an object with a get_parent_map method.
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
719
        """
720
        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.
721
        repo._make_parents_provider().get_parent_map
3089.2.1 by Andrew Bennetts
Implement RemoteRepository._make_parents_provider.
722
6150.2.2 by Jelmer Vernooij
Make various make_repository methods default their shared setting to None.
723
    def make_repository_and_foo_bar(self, shared=None):
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
724
        made_control = self.make_controldir('repository')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
725
        repo = made_control.create_repository(shared=shared)
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
726
        if not repo._format.supports_nesting_repositories:
727
            raise tests.TestNotApplicable("repository does not support "
728
                "nesting repositories")
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
729
        controldir.ControlDir.create_branch_convenience(
730
            self.get_url('repository/foo'), force_new_repo=False)
731
        controldir.ControlDir.create_branch_convenience(
732
            self.get_url('repository/bar'), force_new_repo=True)
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
733
        baz = self.make_controldir('repository/baz')
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
734
        qux = self.make_branch('repository/baz/qux')
3140.1.6 by Aaron Bentley
Add test that nested branches are returned
735
        quxx = self.make_branch('repository/baz/qux/quxx')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
736
        return repo
737
738
    def test_find_branches(self):
6150.2.2 by Jelmer Vernooij
Make various make_repository methods default their shared setting to None.
739
        repo = self.make_repository_and_foo_bar()
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
740
        branches = repo.find_branches()
741
        self.assertContainsRe(branches[-1].base, 'repository/foo/$')
3140.1.6 by Aaron Bentley
Add test that nested branches are returned
742
        self.assertContainsRe(branches[-3].base, 'repository/baz/qux/$')
743
        self.assertContainsRe(branches[-2].base, 'repository/baz/qux/quxx/$')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
744
        # in some formats, creating a repo creates a branch
3140.1.6 by Aaron Bentley
Add test that nested branches are returned
745
        if len(branches) == 6:
746
            self.assertContainsRe(branches[-4].base, 'repository/baz/$')
747
            self.assertContainsRe(branches[-5].base, 'repository/bar/$')
748
            self.assertContainsRe(branches[-6].base, 'repository/$')
749
        else:
750
            self.assertEqual(4, len(branches))
3140.1.3 by Aaron Bentley
Add support for finding branches to BzrDir
751
            self.assertContainsRe(branches[-4].base, 'repository/bar/$')
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
752
753
    def test_find_branches_using(self):
754
        try:
755
            repo = self.make_repository_and_foo_bar(shared=True)
756
        except errors.IncompatibleFormat:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
757
            raise tests.TestNotApplicable
3140.1.2 by Aaron Bentley
Add ability to find branches inside repositories
758
        branches = repo.find_branches(using=True)
759
        self.assertContainsRe(branches[-1].base, 'repository/foo/$')
760
        # in some formats, creating a repo creates a branch
761
        if len(branches) == 2:
762
            self.assertContainsRe(branches[-2].base, 'repository/$')
763
        else:
764
            self.assertEqual(1, len(branches))
765
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
766
    def test_find_branches_using_standalone(self):
767
        branch = self.make_branch('branch')
6145.2.1 by Jelmer Vernooij
Add RepositoryFormat.supports_nesting_repositories.
768
        if not branch.repository._format.supports_nesting_repositories:
769
            raise tests.TestNotApplicable("format does not support nesting "
770
                "repositories")
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
771
        contained = self.make_branch('branch/contained')
772
        branches = branch.repository.find_branches(using=True)
773
        self.assertEqual([branch.base], [b.base for b in branches])
774
        branches = branch.repository.find_branches(using=False)
775
        self.assertEqual([branch.base, contained.base],
776
                         [b.base for b in branches])
777
778
    def test_find_branches_using_empty_standalone_repo(self):
6164.2.2 by Jelmer Vernooij
Make shared argument default to 'None'.
779
        try:
780
            repo = self.make_repository('repo', shared=False)
781
        except errors.IncompatibleFormat:
782
            raise tests.TestNotApplicable("format does not support standalone "
783
                "repositories")
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
784
        try:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
785
            repo.controldir.open_branch()
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
786
        except errors.NotBranchError:
787
            self.assertEqual([], repo.find_branches(using=True))
788
        else:
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
789
            self.assertEqual([repo.controldir.root_transport.base],
3140.1.9 by Aaron Bentley
Optimize find_branches for standalone repositories
790
                             [b.base for b in repo.find_branches(using=True)])
791
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
792
    def test_set_get_make_working_trees_true(self):
793
        repo = self.make_repository('repo')
3349.1.2 by Aaron Bentley
Change ValueError to RepositoryUpgradeRequired
794
        try:
795
            repo.set_make_working_trees(True)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
796
        except (errors.RepositoryUpgradeRequired, errors.UnsupportedOperation) as e:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
797
            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
798
        self.assertTrue(repo.make_working_trees())
799
800
    def test_set_get_make_working_trees_false(self):
801
        repo = self.make_repository('repo')
802
        try:
803
            repo.set_make_working_trees(False)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
804
        except (errors.RepositoryUpgradeRequired, errors.UnsupportedOperation) as e:
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
805
            raise tests.TestNotApplicable('Format does not support this flag.')
3349.1.2 by Aaron Bentley
Change ValueError to RepositoryUpgradeRequired
806
        self.assertFalse(repo.make_working_trees())
3349.1.1 by Aaron Bentley
Enable setting and getting make_working_trees for all repositories
807
3047.1.1 by Andrew Bennetts
Fix for bug 164626, add test that Repository.sprout preserves format.
808
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
809
class TestRepositoryLocking(per_repository.TestCaseWithRepository):
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
810
811
    def test_leave_lock_in_place(self):
812
        repo = self.make_repository('r')
813
        # Lock the repository, then use leave_lock_in_place so that when we
814
        # 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
815
        token = repo.lock_write().repository_token
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
816
        try:
2018.5.76 by Andrew Bennetts
Testing that repository.{dont_,}leave_lock_in_place raises NotImplementedError if lock_write returns None.
817
            if token is None:
818
                # This test does not apply, because this repository refuses lock
819
                # tokens.
820
                self.assertRaises(NotImplementedError, repo.leave_lock_in_place)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
821
                return
2018.5.76 by Andrew Bennetts
Testing that repository.{dont_,}leave_lock_in_place raises NotImplementedError if lock_write returns None.
822
            repo.leave_lock_in_place()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
823
        finally:
824
            repo.unlock()
825
        # We should be unable to relock the repo.
826
        self.assertRaises(errors.LockContention, repo.lock_write)
4327.1.8 by Vincent Ladeuil
Fix 4 more lock-related test failures.
827
        # Cleanup
828
        repo.lock_write(token)
829
        repo.dont_leave_lock_in_place()
830
        repo.unlock()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
831
832
    def test_dont_leave_lock_in_place(self):
833
        repo = self.make_repository('r')
834
        # Create a lock on disk.
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
835
        token = repo.lock_write().repository_token
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
836
        try:
837
            if token is None:
838
                # This test does not apply, because this repository refuses lock
839
                # tokens.
2018.5.76 by Andrew Bennetts
Testing that repository.{dont_,}leave_lock_in_place raises NotImplementedError if lock_write returns None.
840
                self.assertRaises(NotImplementedError,
841
                                  repo.dont_leave_lock_in_place)
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
842
                return
843
            try:
844
                repo.leave_lock_in_place()
845
            except NotImplementedError:
846
                # This repository doesn't support this API.
847
                return
848
        finally:
849
            repo.unlock()
850
        # Reacquire the lock (with a different repository object) by using the
851
        # token.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
852
        new_repo = repo.controldir.open_repository()
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
853
        new_repo.lock_write(token=token)
854
        # Call dont_leave_lock_in_place, so that the lock will be released by
855
        # this instance, even though the lock wasn't originally acquired by it.
856
        new_repo.dont_leave_lock_in_place()
857
        new_repo.unlock()
858
        # Now the repository is unlocked.  Test this by locking it (without a
859
        # token).
860
        repo.lock_write()
861
        repo.unlock()
862
2018.5.78 by Andrew Bennetts
Implement RemoteRepository.lock_write/unlock to expect and send tokens over the
863
    def test_lock_read_then_unlock(self):
864
        # Calling lock_read then unlocking should work without errors.
865
        repo = self.make_repository('r')
866
        repo.lock_read()
867
        repo.unlock()
868
5200.3.3 by Robert Collins
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
869
    def test_lock_read_returns_unlockable(self):
870
        repo = self.make_repository('r')
871
        self.assertThat(repo.lock_read, ReturnsUnlockable(repo))
872
873
    def test_lock_write_returns_unlockable(self):
874
        repo = self.make_repository('r')
875
        self.assertThat(repo.lock_write, ReturnsUnlockable(repo))
876
2018.5.75 by Andrew Bennetts
Add Repository.{dont_,}leave_lock_in_place.
877
2018.5.29 by Robert Collins
Dont run the vfat repository test on RemoteRepositories as there is no point.
878
# FIXME: document why this is a TestCaseWithTransport rather than a
879
#        TestCaseWithRepository
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
880
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.
881
    """Test that repositories can be stored correctly on VFAT transports.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
882
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.
883
    Makes sure we have proper escaping of invalid characters, etc.
884
885
    It'd be better to test all operations on the FakeVFATTransportDecorator,
886
    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
887
    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.
888
    check it's safe to access for vfat.
889
    """
890
891
    def test_on_vfat(self):
2018.5.29 by Robert Collins
Dont run the vfat repository test on RemoteRepositories as there is no point.
892
        # dont bother with remote repository testing, because this test is
893
        # about local disk layout/support.
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
894
        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.
895
            return
5017.3.42 by Vincent Ladeuil
-s bt.per_repository.test_repo passing
896
        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.
897
        FOO_ID = 'foo<:>ID'
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
898
        REV_ID = 'revid-1'
899
        # this makes a default format repository always, which is wrong:
900
        # 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.
901
        # 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.
902
        wt = self.make_branch_and_tree('repo')
2052.2.1 by Alexander Belchenko
test_on_vfat win32 fix: use binary line-endings
903
        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.
904
        # add file with id containing wierd characters
905
        wt.add(['foo'], [FOO_ID])
906
        wt.commit('this is my new commit', rev_id=REV_ID)
907
        # now access over vfat; should be safe
6207.3.8 by Jelmer Vernooij
Fix a bunch of tests.
908
        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.
909
        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.
910
        revtree.lock_read()
911
        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.
912
        contents = revtree.get_file_text(FOO_ID)
913
        self.assertEqual(contents, 'contents of repo/foo\n')
2520.4.54 by Aaron Bentley
Hang a create_bundle method off repository
914
915
    def test_create_bundle(self):
916
        wt = self.make_branch_and_tree('repo')
917
        self.build_tree(['repo/file1'])
918
        wt.add('file1')
919
        wt.commit('file1', rev_id='rev1')
6621.22.2 by Martin
Use BytesIO or StringIO from bzrlib.sixish
920
        fileobj = BytesIO()
5010.2.6 by Vincent Ladeuil
Fix per_repository/test_repository.py imports.
921
        wt.branch.repository.create_bundle(
922
            'rev1', _mod_revision.NULL_REVISION, fileobj)
5158.6.4 by Martin Pool
Repository implements ControlComponent too
923
924
925
class TestRepositoryControlComponent(per_repository.TestCaseWithRepository):
926
    """Repository implementations adequately implement ControlComponent."""
5673.1.1 by Jelmer Vernooij
Add flexible_components boolean to ControlDir if the
927
5158.6.4 by Martin Pool
Repository implements ControlComponent too
928
    def test_urls(self):
929
        repo = self.make_repository('repo')
930
        self.assertIsInstance(repo.user_url, str)
931
        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().
932
        # for all current bzrdir implementations the user dir must be
5158.6.4 by Martin Pool
Repository implements ControlComponent too
933
        # above the control dir but we might need to relax that?
934
        self.assertEqual(repo.control_url.find(repo.user_url), 0)
935
        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().
936
937
938
class TestDeltaRevisionFiltered(per_repository.TestCaseWithRepository):
939
940
    def setUp(self):
941
        super(TestDeltaRevisionFiltered, self).setUp()
942
        tree_a = self.make_branch_and_tree('a')
943
        self.build_tree(['a/foo', 'a/bar/', 'a/bar/b1', 'a/bar/b2', 'a/baz'])
944
        tree_a.add(['foo', 'bar', 'bar/b1', 'bar/b2', 'baz'],
945
                   ['foo-id', 'bar-id', 'b1-id', 'b2-id', 'baz-id'])
946
        tree_a.commit('rev1', rev_id='rev1')
947
        self.build_tree(['a/bar/b3'])
948
        tree_a.add('bar/b3', 'b3-id')
949
        tree_a.commit('rev2', rev_id='rev2')
950
        self.repository = tree_a.branch.repository
951
952
    def test_multiple_files(self):
953
        # Test multiple files
954
        delta = self.repository.get_revision_delta('rev1',
955
            specific_fileids=['foo-id', 'baz-id'])
956
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
957
        self.assertEqual([
958
            ('baz', 'baz-id', 'file'),
959
            ('foo', 'foo-id', 'file'),
960
            ], delta.added)
961
962
    def test_directory(self):
963
        # Test a directory
964
        delta = self.repository.get_revision_delta('rev1',
965
            specific_fileids=['bar-id'])
966
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
967
        self.assertEqual([
968
            ('bar', 'bar-id', 'directory'),
969
            ('bar/b1', 'b1-id', 'file'),
970
            ('bar/b2', 'b2-id', 'file'),
971
            ], delta.added)
972
973
    def test_unrelated(self):
974
        # Try another revision
975
        delta = self.repository.get_revision_delta('rev2',
976
                specific_fileids=['foo-id'])
977
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
978
        self.assertEqual([], delta.added)
979
980
    def test_file_in_directory(self):
981
        # Test a file in a directory, both of which were added
982
        delta = self.repository.get_revision_delta('rev1',
983
            specific_fileids=['b2-id'])
984
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
985
        self.assertEqual([
986
            ('bar', 'bar-id', 'directory'),
987
            ('bar/b2', 'b2-id', 'file'),
988
            ], delta.added)
989
990
    def test_file_in_unchanged_directory(self):
991
        delta = self.repository.get_revision_delta('rev2',
992
            specific_fileids=['b3-id'])
993
        self.assertIsInstance(delta, _mod_delta.TreeDelta)
994
        if delta.added == [
995
            ('bar', 'bar-id', 'directory'),
996
            ('bar/b3', 'b3-id', 'file')]:
997
            self.knownFailure("bzr incorrectly reports 'bar' as added - "
998
                              "bug 878217")
999
        self.assertEqual([
1000
            ('bar/b3', 'b3-id', 'file'),
1001
            ], delta.added)