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