/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
4988.10.3 by John Arbash Meinel
Merge bzr.dev 5007, resolve conflict, update NEWS
1
# Copyright (C) 2008, 2009, 2010 Canonical Ltd
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
2
#
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.
7
#
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.
12
#
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
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
16
17
18
import sys
19
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
20
from breezy import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
21
    errors,
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
22
    osutils,
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
23
    repository,
6670.4.3 by Jelmer Vernooij
Fix more imports.
24
    )
25
from breezy.bzr import (
26
    inventory,
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
27
    versionedfile,
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
28
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
29
from breezy.errors import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
30
    NoSuchRevision,
31
    )
6670.4.3 by Jelmer Vernooij
Fix more imports.
32
from breezy.bzr.vf_search import (
4476.3.11 by Andrew Bennetts
All fetch and interrepo tests passing.
33
    SearchResult,
34
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
35
from breezy.revision import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
36
    NULL_REVISION,
37
    Revision,
38
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
39
from breezy.tests import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
40
    TestNotApplicable,
41
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
42
from breezy.tests.per_interrepository import (
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
43
    TestCaseWithInterRepository,
44
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
45
from breezy.tests.per_interrepository.test_interrepository import (
3616.2.3 by Mark Hammond
Fix test failures due to missing check_repo_format_for_funky_id_on_win32
46
    check_repo_format_for_funky_id_on_win32
47
    )
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
48
49
50
class TestInterRepository(TestCaseWithInterRepository):
51
4634.35.22 by Andrew Bennetts
Use monkey patching to avoid skipping (mostly) tests that try to create damaged repos on 2a.
52
    def disable_commit_write_group_paranoia(self, repo):
53
        pack_coll = getattr(repo, '_pack_collection', None)
54
        if pack_coll is not None:
55
            # Monkey-patch the pack collection instance to allow storing
56
            # incomplete revisions.
57
            pack_coll._check_new_inventories = lambda: []
58
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
59
    def test_fetch(self):
60
        tree_a = self.make_branch_and_tree('a')
61
        self.build_tree(['a/foo'])
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
62
        tree_a.add('foo')
63
        rev1 = tree_a.commit('rev1')
7143.15.2 by Jelmer Vernooij
Run autopep8.
64
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
65
        def check_push_rev1(repo):
66
            # ensure the revision is missing.
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
67
            self.assertRaises(NoSuchRevision, repo.get_revision, rev1)
4110.2.5 by Martin Pool
Deprecate passing pbs in to fetch()
68
            # fetch with a limit of NULL_REVISION
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
69
            repo.fetch(tree_a.branch.repository,
4110.2.5 by Martin Pool
Deprecate passing pbs in to fetch()
70
                       revision_id=NULL_REVISION)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
71
            # nothing should have been pushed
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
72
            self.assertFalse(repo.has_revision(rev1))
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
73
            # fetch with a default limit (grab everything)
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
74
            try:
75
                repo.fetch(tree_a.branch.repository)
76
            except errors.NoRoundtrippingSupport:
77
                raise TestNotApplicable('roundtripping not supported')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
78
            # check that b now has all the data from a's first commit.
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
79
            rev = repo.get_revision(rev1)
80
            tree = repo.revision_tree(rev1)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
81
            tree.lock_read()
82
            self.addCleanup(tree.unlock)
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
83
            tree.get_file_text('foo')
6825.5.1 by Jelmer Vernooij
Implement Tree.all_versioned_paths.
84
            for path in tree.all_versioned_paths():
85
                if tree.kind(path) == "file":
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
86
                    with tree.get_file(path) as f:
87
                        f.read()
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
88
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
89
        # makes a target version repo
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
90
        repo_b = self.make_to_repository('b')
91
        check_push_rev1(repo_b)
92
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
93
    def test_fetch_inconsistent_last_changed_entries(self):
94
        """If an inventory has odd data we should still get what it references.
3735.31.2 by John Arbash Meinel
Cleanup trailing whitespace, get test_source to pass by removing asserts.
95
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
96
        This test tests that we do fetch a file text created in a revision not
97
        being fetched, but referenced from the revision we are fetching when the
98
        adjacent revisions to the one being fetched do not reference that text.
99
        """
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
100
        if not self.repository_format.supports_full_versioned_files:
101
            raise TestNotApplicable('Need full versioned files')
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
102
        tree = self.make_branch_and_tree('source')
103
        revid = tree.commit('old')
104
        to_repo = self.make_to_repository('to_repo')
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
105
        try:
106
            to_repo.fetch(tree.branch.repository, revid)
107
        except errors.NoRoundtrippingSupport:
108
            raise TestNotApplicable('roundtripping not supported')
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
109
        # Make a broken revision and fetch it.
110
        source = tree.branch.repository
111
        source.lock_write()
112
        self.addCleanup(source.unlock)
113
        source.start_write_group()
114
        try:
115
            # We need two revisions: OLD and NEW. NEW will claim to need a file
116
            # 'FOO' changed in 'OLD'. OLD will not have that file at all.
117
            source.texts.insert_record_stream([
6973.12.1 by Jelmer Vernooij
Fix more tests.
118
                versionedfile.FulltextContentFactory((b'foo', revid), (), None,
7143.15.2 by Jelmer Vernooij
Run autopep8.
119
                                                     b'contents')])
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
120
            basis = source.revision_tree(revid)
121
            parent_id = basis.path2id('')
6973.12.1 by Jelmer Vernooij
Fix more tests.
122
            entry = inventory.make_entry('file', 'foo-path', parent_id, b'foo')
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
123
            entry.revision = revid
124
            entry.text_size = len('contents')
7045.1.1 by Jelmer Vernooij
Fix another 300 tests.
125
            entry.text_sha1 = osutils.sha_string(b'contents')
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
126
            inv_sha1, _ = source.add_inventory_by_delta(revid, [
6973.12.1 by Jelmer Vernooij
Fix more tests.
127
                (None, 'foo-path', b'foo', entry)], b'new', [revid])
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
128
            rev = Revision(timestamp=0,
129
                           timezone=None,
130
                           committer="Foo Bar <foo@example.com>",
131
                           message="Message",
132
                           inventory_sha1=inv_sha1,
6855.4.1 by Jelmer Vernooij
Yet more bees.
133
                           revision_id=b'new',
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
134
                           parent_ids=[revid])
135
            source.add_revision(rev.revision_id, rev)
136
        except:
137
            source.abort_write_group()
138
            raise
139
        else:
140
            source.commit_write_group()
6973.12.1 by Jelmer Vernooij
Fix more tests.
141
        to_repo.fetch(source, b'new')
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
142
        to_repo.lock_read()
143
        self.addCleanup(to_repo.unlock)
6973.12.1 by Jelmer Vernooij
Fix more tests.
144
        self.assertEqual(b'contents',
7143.15.2 by Jelmer Vernooij
Run autopep8.
145
                         next(to_repo.texts.get_record_stream([(b'foo', revid)],
146
                                                              'unordered', True)).get_bytes_as('fulltext'))
3735.2.135 by Robert Collins
Permit fetching bzr.dev [deal with inconsistent inventories.]
147
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
148
    def test_fetch_from_stacked_smart(self):
149
        self.setup_smart_server_with_call_log()
150
        self.test_fetch_from_stacked()
151
152
    def test_fetch_from_stacked_smart_old(self):
153
        self.setup_smart_server_with_call_log()
6963.1.2 by Jelmer Vernooij
Fix some more tests.
154
        self.disable_verb(b'Repository.get_stream_1.19')
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
155
        self.test_fetch_from_stacked()
156
157
    def test_fetch_from_stacked(self):
158
        """Fetch from a stacked branch succeeds."""
159
        if not self.repository_format.supports_external_lookups:
160
            raise TestNotApplicable("Need stacking support in the source.")
161
        builder = self.make_branch_builder('full-branch')
162
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
163
        builder.build_snapshot(None, [
6973.6.2 by Jelmer Vernooij
Fix more tests.
164
            ('add', ('', b'root-id', 'directory', '')),
165
            ('add', ('file', b'file-id', 'file', b'content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
166
            revision_id=b'first')
6973.6.2 by Jelmer Vernooij
Fix more tests.
167
        builder.build_snapshot([b'first'], [
6883.22.11 by Jelmer Vernooij
merge trunk
168
            ('modify', ('file', b'second content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
169
            revision_id=b'second')
6883.22.11 by Jelmer Vernooij
merge trunk
170
        builder.build_snapshot([b'second'], [
171
            ('modify', ('file', b'third content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
172
            revision_id=b'third')
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
173
        builder.finish_series()
174
        branch = builder.get_branch()
175
        repo = self.make_repository('stacking-base')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
176
        trunk = repo.controldir.create_branch()
6973.6.2 by Jelmer Vernooij
Fix more tests.
177
        trunk.repository.fetch(branch.repository, b'second')
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
178
        repo = self.make_repository('stacked')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
179
        stacked_branch = repo.controldir.create_branch()
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
180
        stacked_branch.set_stacked_on_url(trunk.base)
6973.6.2 by Jelmer Vernooij
Fix more tests.
181
        stacked_branch.repository.fetch(branch.repository, b'third')
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
182
        target = self.make_to_repository('target')
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
183
        try:
6996 by Jelmer Vernooij
Merge lp:~jelmer/brz/python3-e
184
            target.fetch(stacked_branch.repository, b'third')
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
185
        except errors.NoRoundtrippingSupport:
186
            raise TestNotApplicable('roundtripping not supported')
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
187
        target.lock_read()
188
        self.addCleanup(target.unlock)
6973.6.2 by Jelmer Vernooij
Fix more tests.
189
        all_revs = {b'first', b'second', b'third'}
4634.61.1 by Andrew Bennetts
Fix cross-format pulls from stacked branches via smart server, add tests for same.
190
        self.assertEqual(all_revs, set(target.get_parent_map(all_revs)))
191
4476.3.15 by Andrew Bennetts
Partially working fallback for pre-1.17 servers.
192
    def test_fetch_parent_inventories_at_stacking_boundary_smart(self):
193
        self.setup_smart_server_with_call_log()
194
        self.test_fetch_parent_inventories_at_stacking_boundary()
195
196
    def test_fetch_parent_inventories_at_stacking_boundary_smart_old(self):
197
        self.setup_smart_server_with_call_log()
6963.1.2 by Jelmer Vernooij
Fix some more tests.
198
        self.disable_verb(b'Repository.insert_stream_1.19')
6437.59.1 by Martin Packman
Mark randomly failing test in per_interrepository using knownFailure when ConnectionReset is raised
199
        try:
200
            self.test_fetch_parent_inventories_at_stacking_boundary()
201
        except errors.ConnectionReset:
202
            self.knownFailure("Random spurious failure, see bug 874153")
4476.3.15 by Andrew Bennetts
Partially working fallback for pre-1.17 servers.
203
4257.3.1 by Andrew Bennetts
Add failing test.
204
    def test_fetch_parent_inventories_at_stacking_boundary(self):
4257.3.9 by Andrew Bennetts
Add fix to InterDifferingSerializer too, although it's pretty ugly.
205
        """Fetch to a stacked branch copies inventories for parents of
206
        revisions at the stacking boundary.
207
208
        This is necessary so that the server is able to determine the file-ids
209
        altered by all revisions it contains, which means that it needs both
210
        the inventory for any revision it has, and the inventories of all that
211
        revision's parents.
4597.1.2 by John Arbash Meinel
Fix the second half of bug #402778
212
213
        However, we should also skip any revisions which are ghosts in the
214
        parents.
4257.3.9 by Andrew Bennetts
Add fix to InterDifferingSerializer too, although it's pretty ugly.
215
        """
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
216
        if not self.repository_format_to.supports_external_lookups:
4257.3.1 by Andrew Bennetts
Add failing test.
217
            raise TestNotApplicable("Need stacking support in the target.")
218
        builder = self.make_branch_builder('branch')
219
        builder.start_series()
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
220
        base = builder.build_snapshot(None, [
221
            ('add', ('', None, 'directory', '')),
6992 by Jelmer Vernooij
Merge lp:~jelmer/brz/python3-c
222
            ('add', ('file', None, 'file', b'content\n'))])
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
223
        left = builder.build_snapshot([base], [
224
            ('modify', ('file', b'left content\n'))])
225
        right = builder.build_snapshot([base], [
226
            ('modify', ('file', b'right content\n'))])
227
        merge = builder.build_snapshot([left, right], [
228
            ('modify', ('file', b'left and right content\n'))])
4257.3.1 by Andrew Bennetts
Add failing test.
229
        builder.finish_series()
230
        branch = builder.get_branch()
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
231
        revtree = branch.repository.revision_tree(merge)
232
        root_id = revtree.path2id('')
233
        file_id = revtree.path2id('file')
234
4257.3.1 by Andrew Bennetts
Add failing test.
235
        repo = self.make_to_repository('trunk')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
236
        trunk = repo.controldir.create_branch()
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
237
        trunk.repository.fetch(branch.repository, left)
238
        trunk.repository.fetch(branch.repository, right)
4257.3.1 by Andrew Bennetts
Add failing test.
239
        repo = self.make_to_repository('stacked')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
240
        stacked_branch = repo.controldir.create_branch()
4257.3.1 by Andrew Bennetts
Add failing test.
241
        stacked_branch.set_stacked_on_url(trunk.base)
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
242
        stacked_branch.repository.fetch(branch.repository, merge)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
243
        unstacked_repo = stacked_branch.controldir.open_repository()
4257.3.1 by Andrew Bennetts
Add failing test.
244
        unstacked_repo.lock_read()
245
        self.addCleanup(unstacked_repo.unlock)
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
246
        self.assertFalse(unstacked_repo.has_revision(left))
247
        self.assertFalse(unstacked_repo.has_revision(right))
4257.3.1 by Andrew Bennetts
Add failing test.
248
        self.assertEqual(
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
249
            {(left,), (right,), (merge,)},
4257.3.1 by Andrew Bennetts
Add failing test.
250
            unstacked_repo.inventories.keys())
4597.1.1 by John Arbash Meinel
fix a critical bug #402778
251
        # And the basis inventories have been copied correctly
252
        trunk.lock_read()
253
        self.addCleanup(trunk.unlock)
254
        left_tree, right_tree = trunk.repository.revision_trees(
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
255
            [left, right])
4597.1.1 by John Arbash Meinel
fix a critical bug #402778
256
        stacked_branch.lock_read()
257
        self.addCleanup(stacked_branch.unlock)
258
        (stacked_left_tree,
259
         stacked_right_tree) = stacked_branch.repository.revision_trees(
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
260
            [left, right])
6405.2.7 by Jelmer Vernooij
Fix more tests.
261
        self.assertEqual(
262
            left_tree.root_inventory, stacked_left_tree.root_inventory)
263
        self.assertEqual(
264
            right_tree.root_inventory, stacked_right_tree.root_inventory)
4257.3.1 by Andrew Bennetts
Add failing test.
265
4476.3.81 by Andrew Bennetts
Merge bzr.dev. Fix some minor fallout. per_interrepository/test_fetch.py has some duplicated assertions as a first pass at resolving conflicts.
266
        # Finally, it's not enough to see that the basis inventories are
267
        # present.  The texts introduced in merge (and only those) should be
268
        # present, and also generating a stream should succeed without blowing
269
        # up.
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
270
        self.assertTrue(unstacked_repo.has_revision(merge))
271
        expected_texts = {(file_id, merge)}
272
        if stacked_branch.repository.texts.get_parent_map([(root_id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
273
                                                            merge)]):
4476.3.81 by Andrew Bennetts
Merge bzr.dev. Fix some minor fallout. per_interrepository/test_fetch.py has some duplicated assertions as a first pass at resolving conflicts.
274
            # If a (root-id,merge) text exists, it should be in the stacked
275
            # repo.
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
276
            expected_texts.add((root_id, merge))
4476.3.81 by Andrew Bennetts
Merge bzr.dev. Fix some minor fallout. per_interrepository/test_fetch.py has some duplicated assertions as a first pass at resolving conflicts.
277
        self.assertEqual(expected_texts, unstacked_repo.texts.keys())
6989.2.1 by Jelmer Vernooij
Avoid using custom file ids/revids.
278
        self.assertCanStreamRevision(unstacked_repo, merge)
4476.3.11 by Andrew Bennetts
All fetch and interrepo tests passing.
279
280
    def assertCanStreamRevision(self, repo, revision_id):
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
281
        exclude_keys = set(repo.all_revision_ids()) - {revision_id}
4476.3.11 by Andrew Bennetts
All fetch and interrepo tests passing.
282
        search = SearchResult([revision_id], exclude_keys, 1, [revision_id])
283
        source = repo._get_source(repo._format)
284
        for substream_kind, substream in source.get_stream(search):
285
            # Consume the substream
286
            list(substream)
4257.3.1 by Andrew Bennetts
Add failing test.
287
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
288
    def test_fetch_across_stacking_boundary_ignores_ghost(self):
289
        if not self.repository_format_to.supports_external_lookups:
290
            raise TestNotApplicable("Need stacking support in the target.")
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
291
        if not self.repository_format.supports_ghosts:
292
            raise TestNotApplicable("Need ghost support in the source.")
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
293
        to_repo = self.make_to_repository('to')
294
        builder = self.make_branch_builder('branch')
295
        builder.start_series()
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
296
        base = builder.build_snapshot(None, [
297
            ('add', ('', None, 'directory', '')),
298
            ('add', ('file', None, 'file', b'content\n'))])
299
        second = builder.build_snapshot([base], [
300
            ('modify', ('file', b'second content\n'))])
301
        third = builder.build_snapshot([second, b'ghost'], [
302
            ('modify', ('file', b'third content\n'))])
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
303
        builder.finish_series()
304
        branch = builder.get_branch()
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
305
        revtree = branch.repository.revision_tree(base)
306
        root_id = revtree.path2id('')
307
        file_id = revtree.path2id('file')
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
308
        repo = self.make_to_repository('trunk')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
309
        trunk = repo.controldir.create_branch()
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
310
        trunk.repository.fetch(branch.repository, second)
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
311
        repo = self.make_to_repository('stacked')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
312
        stacked_branch = repo.controldir.create_branch()
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
313
        stacked_branch.set_stacked_on_url(trunk.base)
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
314
        stacked_branch.repository.fetch(branch.repository, third)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
315
        unstacked_repo = stacked_branch.controldir.open_repository()
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
316
        unstacked_repo.lock_read()
317
        self.addCleanup(unstacked_repo.unlock)
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
318
        self.assertFalse(unstacked_repo.has_revision(second))
6973.5.2 by Jelmer Vernooij
Add more bees.
319
        self.assertFalse(unstacked_repo.has_revision(b'ghost'))
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
320
        self.assertEqual(
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
321
            {(second,), (third,)},
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
322
            unstacked_repo.inventories.keys())
323
        # And the basis inventories have been copied correctly
324
        trunk.lock_read()
325
        self.addCleanup(trunk.unlock)
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
326
        second_tree = trunk.repository.revision_tree(second)
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
327
        stacked_branch.lock_read()
328
        self.addCleanup(stacked_branch.unlock)
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
329
        stacked_second_tree = stacked_branch.repository.revision_tree(second)
6471.1.5 by Jelmer Vernooij
Compare trees rather than inventories.
330
        self.assertEqual(second_tree, stacked_second_tree)
4476.3.81 by Andrew Bennetts
Merge bzr.dev. Fix some minor fallout. per_interrepository/test_fetch.py has some duplicated assertions as a first pass at resolving conflicts.
331
        # Finally, it's not enough to see that the basis inventories are
332
        # present.  The texts introduced in merge (and only those) should be
333
        # present, and also generating a stream should succeed without blowing
334
        # up.
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
335
        self.assertTrue(unstacked_repo.has_revision(third))
336
        expected_texts = {(file_id, third)}
337
        if stacked_branch.repository.texts.get_parent_map([(root_id,
7143.15.2 by Jelmer Vernooij
Run autopep8.
338
                                                            third)]):
4476.3.81 by Andrew Bennetts
Merge bzr.dev. Fix some minor fallout. per_interrepository/test_fetch.py has some duplicated assertions as a first pass at resolving conflicts.
339
            # If a (root-id,third) text exists, it should be in the stacked
340
            # repo.
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
341
            expected_texts.add((root_id, third))
4476.3.81 by Andrew Bennetts
Merge bzr.dev. Fix some minor fallout. per_interrepository/test_fetch.py has some duplicated assertions as a first pass at resolving conflicts.
342
        self.assertEqual(expected_texts, unstacked_repo.texts.keys())
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
343
        self.assertCanStreamRevision(unstacked_repo, third)
4597.1.5 by John Arbash Meinel
Split the 'ghost' test into a second test.
344
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
345
    def test_fetch_from_stacked_to_stacked_copies_parent_inventories(self):
346
        """Fetch from a stacked branch copies inventories for parents of
347
        revisions at the stacking boundary.
348
349
        Specifically, fetch will copy the parent inventories from the
350
        source for which the corresponding revisions are not present.  This
351
        will happen even when the source repository has no fallbacks configured
352
        (as is the case during upgrade).
353
        """
354
        if not self.repository_format.supports_external_lookups:
355
            raise TestNotApplicable("Need stacking support in the source.")
356
        if not self.repository_format_to.supports_external_lookups:
357
            raise TestNotApplicable("Need stacking support in the target.")
358
        builder = self.make_branch_builder('branch')
359
        builder.start_series()
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
360
        builder.build_snapshot(None, [
6973.5.2 by Jelmer Vernooij
Add more bees.
361
            ('add', ('', b'root-id', 'directory', '')),
362
            ('add', ('file', b'file-id', 'file', b'content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
363
            revision_id=b'base')
6883.22.11 by Jelmer Vernooij
merge trunk
364
        builder.build_snapshot([b'base'], [
365
            ('modify', ('file', b'left content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
366
            revision_id=b'left')
6883.22.11 by Jelmer Vernooij
merge trunk
367
        builder.build_snapshot([b'base'], [
368
            ('modify', ('file', b'right content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
369
            revision_id=b'right')
6883.22.11 by Jelmer Vernooij
merge trunk
370
        builder.build_snapshot([b'left', b'right'], [
371
            ('modify', ('file', b'left and right content\n'))],
6855.4.1 by Jelmer Vernooij
Yet more bees.
372
            revision_id=b'merge')
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
373
        builder.finish_series()
374
        branch = builder.get_branch()
375
        repo = self.make_repository('old-trunk')
376
        # Make a pair of equivalent trunk repos in the from and to formats.
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
377
        old_trunk = repo.controldir.create_branch()
6973.5.2 by Jelmer Vernooij
Add more bees.
378
        old_trunk.repository.fetch(branch.repository, b'left')
379
        old_trunk.repository.fetch(branch.repository, b'right')
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
380
        repo = self.make_to_repository('new-trunk')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
381
        new_trunk = repo.controldir.create_branch()
6973.5.10 by Jelmer Vernooij
Random bunch of python3 bee-improvements.
382
        new_trunk.repository.fetch(branch.repository, b'left')
383
        new_trunk.repository.fetch(branch.repository, b'right')
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
384
        # Make the source; a repo stacked on old_trunk contained just the data
385
        # for 'merge'.
386
        repo = self.make_repository('old-stacked')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
387
        old_stacked_branch = repo.controldir.create_branch()
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
388
        old_stacked_branch.set_stacked_on_url(old_trunk.base)
6973.5.2 by Jelmer Vernooij
Add more bees.
389
        old_stacked_branch.repository.fetch(branch.repository, b'merge')
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
390
        # Make the target, a repo stacked on new_trunk.
391
        repo = self.make_to_repository('new-stacked')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
392
        new_stacked_branch = repo.controldir.create_branch()
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
393
        new_stacked_branch.set_stacked_on_url(new_trunk.base)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
394
        old_unstacked_repo = old_stacked_branch.controldir.open_repository()
395
        new_unstacked_repo = new_stacked_branch.controldir.open_repository()
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
396
        # Reopen the source and target repos without any fallbacks, and fetch
397
        # 'merge'.
6973.5.2 by Jelmer Vernooij
Add more bees.
398
        new_unstacked_repo.fetch(old_unstacked_repo, b'merge')
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
399
        # Now check the results.  new_unstacked_repo should contain all the
400
        # data necessary to stream 'merge' (i.e. the parent inventories).
401
        new_unstacked_repo.lock_read()
402
        self.addCleanup(new_unstacked_repo.unlock)
6973.5.2 by Jelmer Vernooij
Add more bees.
403
        self.assertFalse(new_unstacked_repo.has_revision(b'left'))
404
        self.assertFalse(new_unstacked_repo.has_revision(b'right'))
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
405
        self.assertEqual(
6973.5.2 by Jelmer Vernooij
Add more bees.
406
            {(b'left',), (b'right',), (b'merge',)},
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
407
            new_unstacked_repo.inventories.keys())
408
        # And the basis inventories have been copied correctly
409
        new_trunk.lock_read()
410
        self.addCleanup(new_trunk.unlock)
411
        left_tree, right_tree = new_trunk.repository.revision_trees(
6973.5.2 by Jelmer Vernooij
Add more bees.
412
            [b'left', b'right'])
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
413
        new_stacked_branch.lock_read()
414
        self.addCleanup(new_stacked_branch.unlock)
415
        (stacked_left_tree,
416
         stacked_right_tree) = new_stacked_branch.repository.revision_trees(
6973.5.2 by Jelmer Vernooij
Add more bees.
417
            [b'left', b'right'])
6470.1.1 by Jelmer Vernooij
Use inventories directly in fewer places.
418
        self.assertEqual(left_tree, stacked_left_tree)
419
        self.assertEqual(right_tree, stacked_right_tree)
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
420
        # Finally, it's not enough to see that the basis inventories are
421
        # present.  The texts introduced in merge (and only those) should be
422
        # present, and also generating a stream should succeed without blowing
423
        # up.
6973.5.2 by Jelmer Vernooij
Add more bees.
424
        self.assertTrue(new_unstacked_repo.has_revision(b'merge'))
425
        expected_texts = {(b'file-id', b'merge')}
426
        if new_stacked_branch.repository.texts.get_parent_map([(b'root-id',
7143.15.2 by Jelmer Vernooij
Run autopep8.
427
                                                                b'merge')]):
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
428
            # If a (root-id,merge) text exists, it should be in the stacked
429
            # repo.
6973.5.2 by Jelmer Vernooij
Add more bees.
430
            expected_texts.add((b'root-id', b'merge'))
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
431
        self.assertEqual(expected_texts, new_unstacked_repo.texts.keys())
6973.5.2 by Jelmer Vernooij
Add more bees.
432
        self.assertCanStreamRevision(new_unstacked_repo, b'merge')
4627.3.4 by Andrew Bennetts
Add a (long) test that fails without the fix.
433
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
434
    def test_fetch_missing_basis_text(self):
435
        """If fetching a delta, we should die if a basis is not present."""
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
436
        if not self.repository_format.supports_full_versioned_files:
437
            raise TestNotApplicable('Need full versioned files support')
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
438
        if not self.repository_format_to.supports_full_versioned_files:
439
            raise TestNotApplicable('Need full versioned files support')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
440
        tree = self.make_branch_and_tree('tree')
441
        self.build_tree(['tree/a'])
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
442
        tree.add(['a'])
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
443
        rev1 = tree.commit('one')
6855.4.1 by Jelmer Vernooij
Yet more bees.
444
        self.build_tree_contents([('tree/a', b'new contents\n')])
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
445
        rev2 = tree.commit('two')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
446
447
        to_repo = self.make_to_repository('to_repo')
448
        # We build a broken revision so that we can test the fetch code dies
449
        # properly. So copy the inventory and revision, but not the text.
6973.5.2 by Jelmer Vernooij
Add more bees.
450
        with to_repo.lock_write():
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
451
            to_repo.start_write_group()
4634.35.13 by Andrew Bennetts
Fix test_fetch_missing_basis_text to skip if commit_write_group on the target repo prevents making a broken revision.
452
            try:
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
453
                inv = tree.branch.repository.get_inventory(rev1)
454
                to_repo.add_inventory(rev1, inv, [])
455
                rev = tree.branch.repository.get_revision(rev1)
456
                to_repo.add_revision(rev1, rev, inv=inv)
4634.35.22 by Andrew Bennetts
Use monkey patching to avoid skipping (mostly) tests that try to create damaged repos on 2a.
457
                self.disable_commit_write_group_paranoia(to_repo)
458
                to_repo.commit_write_group()
4634.35.13 by Andrew Bennetts
Fix test_fetch_missing_basis_text to skip if commit_write_group on the target repo prevents making a broken revision.
459
            except:
460
                to_repo.abort_write_group(suppress_errors=True)
461
                raise
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
462
3350.3.21 by Robert Collins
Merge bzr.dev.
463
        # Implementations can either ensure that the target of the delta is
464
        # reconstructable, or raise an exception (which stream based copies
465
        # generally do).
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
466
        try:
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
467
            to_repo.fetch(tree.branch.repository, rev2)
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
468
        except (errors.BzrCheckError, errors.RevisionNotPresent) as e:
3830.3.12 by Martin Pool
Review cleanups: unify has_key impls, add missing_keys(), clean up exception blocks
469
            # If an exception is raised, the revision should not be in the
470
            # target.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
471
            #
3830.3.9 by Martin Pool
Simplify kvf insert_record_stream; add has_key shorthand methods; update stacking effort tests
472
            # Can also just raise a generic check errors; stream insertion
473
            # does this to include all the missing data
474
            self.assertRaises((errors.NoSuchRevision, errors.RevisionNotPresent),
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
475
                              to_repo.revision_tree, rev2)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
476
        else:
3350.3.21 by Robert Collins
Merge bzr.dev.
477
            # If not exception is raised, then the text should be
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
478
            # available.
6973.7.3 by Jelmer Vernooij
Fix some more tests.
479
            with to_repo.lock_read():
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
480
                rt = to_repo.revision_tree(rev2)
6973.5.2 by Jelmer Vernooij
Add more bees.
481
                self.assertEqual(b'new contents\n',
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
482
                                 rt.get_file_text('a'))
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
483
484
    def test_fetch_missing_revision_same_location_fails(self):
485
        repo_a = self.make_repository('.')
486
        repo_b = repository.Repository.open('.')
5728.3.1 by Martin Pool
Remove apparently no-longer-called check_old_format_lock_error
487
        self.assertRaises(errors.NoSuchRevision,
7143.15.2 by Jelmer Vernooij
Run autopep8.
488
                          repo_b.fetch, repo_a, revision_id=b'XXX')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
489
490
    def test_fetch_same_location_trivial_works(self):
491
        repo_a = self.make_repository('.')
492
        repo_b = repository.Repository.open('.')
5728.3.1 by Martin Pool
Remove apparently no-longer-called check_old_format_lock_error
493
        repo_a.fetch(repo_b)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
494
495
    def test_fetch_missing_text_other_location_fails(self):
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
496
        if not self.repository_format.supports_full_versioned_files:
497
            raise TestNotApplicable('Need full versioned files')
498
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
499
        source_tree = self.make_branch_and_tree('source')
500
        source = source_tree.branch.repository
501
        target = self.make_to_repository('target')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
502
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
503
        # start by adding a file so the data knit for the file exists in
504
        # repositories that have specific files for each fileid.
505
        self.build_tree(['source/id'])
6973.5.2 by Jelmer Vernooij
Add more bees.
506
        source_tree.add(['id'], [b'id'])
6855.4.1 by Jelmer Vernooij
Yet more bees.
507
        source_tree.commit('a', rev_id=b'a')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
508
        # now we manually insert a revision with an inventory referencing
4634.35.14 by Andrew Bennetts
Fix more tests to cope with new commit_write_group strictness.
509
        # file 'id' at revision 'b', but we do not insert revision b.
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
510
        # this should ensure that the new versions of files are being checked
511
        # for during pull operations
6973.5.2 by Jelmer Vernooij
Add more bees.
512
        inv = source.get_inventory(b'a')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
513
        source.lock_write()
3380.1.5 by Aaron Bentley
Merge with make-it-work
514
        self.addCleanup(source.unlock)
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
515
        source.start_write_group()
6973.5.2 by Jelmer Vernooij
Add more bees.
516
        inv.get_entry(b'id').revision = b'b'
517
        inv.revision_id = b'b'
518
        sha1 = source.add_inventory(b'b', inv, [b'a'])
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
519
        rev = Revision(timestamp=0,
520
                       timezone=None,
521
                       committer="Foo Bar <foo@example.com>",
522
                       message="Message",
523
                       inventory_sha1=sha1,
6855.4.1 by Jelmer Vernooij
Yet more bees.
524
                       revision_id=b'b')
6973.5.2 by Jelmer Vernooij
Add more bees.
525
        rev.parent_ids = [b'a']
526
        source.add_revision(b'b', rev)
4634.35.22 by Andrew Bennetts
Use monkey patching to avoid skipping (mostly) tests that try to create damaged repos on 2a.
527
        self.disable_commit_write_group_paranoia(source)
528
        source.commit_write_group()
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
529
        try:
530
            self.assertRaises(errors.RevisionNotPresent, target.fetch, source)
531
        except errors.NoRoundtrippingSupport:
532
            raise TestNotApplicable('roundtripping not supported')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
533
        self.assertFalse(target.has_revision('b'))
534
535
    def test_fetch_funky_file_id(self):
536
        from_tree = self.make_branch_and_tree('tree')
537
        if sys.platform == 'win32':
538
            from_repo = from_tree.branch.repository
539
            check_repo_format_for_funky_id_on_win32(from_repo)
540
        self.build_tree(['tree/filename'])
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
541
        if not from_tree.supports_setting_file_ids():
7143.15.2 by Jelmer Vernooij
Run autopep8.
542
            raise TestNotApplicable(
543
                'from tree format can not create custom file ids')
7045.2.15 by Jelmer Vernooij
Fix some per_pack_repository tests.
544
        from_tree.add('filename', b'funky-chars<>%&;"\'')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
545
        from_tree.commit('commit filename')
546
        to_repo = self.make_to_repository('to')
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
547
        try:
7143.15.2 by Jelmer Vernooij
Run autopep8.
548
            to_repo.fetch(from_tree.branch.repository,
549
                          from_tree.get_parent_ids()[0])
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
550
        except errors.NoRoundtrippingSupport:
551
            raise TestNotApplicable('roundtripping not supported')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
552
3380.1.6 by Aaron Bentley
Ensure fetching munges sha1s
553
    def test_fetch_revision_hash(self):
554
        """Ensure that inventory hashes are updated by fetch"""
6989.2.6 by Jelmer Vernooij
Run tests against brz-git interrepositories.
555
        if not self.repository_format_to.supports_full_versioned_files:
556
            raise TestNotApplicable('Need full versioned files')
3380.1.6 by Aaron Bentley
Ensure fetching munges sha1s
557
        from_tree = self.make_branch_and_tree('tree')
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
558
        revid = from_tree.commit('foo')
3380.1.6 by Aaron Bentley
Ensure fetching munges sha1s
559
        to_repo = self.make_to_repository('to')
6989.2.3 by Jelmer Vernooij
Allow testing interrepo formats that don't support roundtripping.
560
        try:
561
            to_repo.fetch(from_tree.branch.repository)
562
        except errors.NoRoundtrippingSupport:
563
            raise TestNotApplicable('roundtripping not supported')
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
564
        recorded_inv_sha1 = to_repo.get_revision(revid).inventory_sha1
4597.1.4 by John Arbash Meinel
Fix one test that assumed get_inventory_xml worked.
565
        to_repo.lock_read()
566
        self.addCleanup(to_repo.unlock)
6989.2.2 by Jelmer Vernooij
Fix a few tests against git repositories.
567
        stream = to_repo.inventories.get_record_stream([(revid,)],
4597.1.4 by John Arbash Meinel
Fix one test that assumed get_inventory_xml worked.
568
                                                       'unordered', True)
7018.3.10 by Jelmer Vernooij
Consistent return values in PreviewTree.list_files.
569
        bytes = next(stream).get_bytes_as('fulltext')
4597.1.4 by John Arbash Meinel
Fix one test that assumed get_inventory_xml worked.
570
        computed_inv_sha1 = osutils.sha_string(bytes)
3380.1.6 by Aaron Bentley
Ensure fetching munges sha1s
571
        self.assertEqual(computed_inv_sha1, recorded_inv_sha1)
572
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
573
574
class TestFetchDependentData(TestCaseWithInterRepository):
575
576
    def test_reference(self):
577
        from_tree = self.make_branch_and_tree('tree')
578
        to_repo = self.make_to_repository('to')
579
        if (not from_tree.supports_tree_reference() or
580
            not from_tree.branch.repository._format.supports_tree_reference or
7143.15.2 by Jelmer Vernooij
Run autopep8.
581
                not to_repo._format.supports_tree_reference):
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
582
            raise TestNotApplicable("Need subtree support.")
6989.2.6 by Jelmer Vernooij
Run tests against brz-git interrepositories.
583
        if not to_repo._format.supports_full_versioned_files:
584
            raise TestNotApplicable('Need full versioned files support.')
3380.1.4 by Aaron Bentley
Split interrepository fetch tests into their own file
585
        subtree = self.make_branch_and_tree('tree/subtree')
586
        subtree.commit('subrev 1')
587
        from_tree.add_reference(subtree)
588
        tree_rev = from_tree.commit('foo')
589
        # now from_tree has a last-modified of subtree of the rev id of the
590
        # commit for foo, and a reference revision of the rev id of the commit
591
        # for subrev 1
592
        to_repo.fetch(from_tree.branch.repository, tree_rev)
593
        # to_repo should have a file_graph for from_tree.path2id('subtree') and
594
        # revid tree_rev.
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.
595
        file_id = from_tree.path2id('subtree')
6989.2.6 by Jelmer Vernooij
Run tests against brz-git interrepositories.
596
        with to_repo.lock_read():
7143.15.2 by Jelmer Vernooij
Run autopep8.
597
            self.assertEqual({(file_id, tree_rev): ()},
598
                             to_repo.texts.get_parent_map([(file_id, tree_rev)]))