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