/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
5273.1.7 by Vincent Ladeuil
No more use of the get_transport imported *symbol*, all uses are through
1
# Copyright (C) 2007-2010 Canonical Ltd
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
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
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
16
17
"""Tests for fetch between repositories of the same type."""
18
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
19
from breezy import (
6472.2.1 by Jelmer Vernooij
Use bzrdir.controldir for generic access to control directories.
20
    controldir,
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
21
    errors,
2696.3.10 by Martin Pool
Add missing import
22
    gpg,
6670.4.14 by Jelmer Vernooij
Move remote to breezy.bzr.
23
    repository,
24
    )
25
from breezy.bzr import (
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
26
    remote,
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
27
    )
6670.4.1 by Jelmer Vernooij
Update imports.
28
from breezy.bzr.inventory import ROOT_ID
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
29
from breezy.tests import (
5751.2.3 by Jelmer Vernooij
More tests
30
    TestNotApplicable,
31
    TestSkipped,
32
    )
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
33
from breezy.tests.per_repository import TestCaseWithRepository
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
34
35
36
class TestFetchSameRepository(TestCaseWithRepository):
37
38
    def test_fetch(self):
39
        # smoke test fetch to ensure that the convenience function works.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
40
        # it is defined as a convenience function with the underlying
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
41
        # functionality provided by an InterRepository
42
        tree_a = self.make_branch_and_tree('a')
43
        self.build_tree(['a/foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
44
        tree_a.add('foo')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
45
        rev1 = tree_a.commit('rev1')
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
46
        # fetch with a default limit (grab everything)
2711.2.6 by Martin Pool
Fix up conversion of create_repository to make_repository in test_fetch
47
        repo = self.make_repository('b')
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
48
        if (tree_a.branch.repository.supports_rich_root() and not
49
            repo.supports_rich_root()):
50
            raise TestSkipped('Cannot fetch from model2 to model1')
51
        repo.fetch(tree_a.branch.repository,
52
                   revision_id=None)
53
4145.1.1 by Robert Collins
Explicitly prevent fetching while the target repository is in a write group.
54
    def test_fetch_fails_in_write_group(self):
55
        # fetch() manages a write group itself, fetching within one isn't safe.
56
        repo = self.make_repository('a')
57
        repo.lock_write()
58
        self.addCleanup(repo.unlock)
59
        repo.start_write_group()
60
        self.addCleanup(repo.abort_write_group)
61
        # Don't need a specific class - not expecting flow control based on
62
        # this.
63
        self.assertRaises(errors.BzrError, repo.fetch, repo)
64
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
65
    def test_fetch_to_knit3(self):
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
66
        # create a repository of the sort we are testing.
3242.2.17 by Aaron Bentley
Fix broken tests
67
        tree_a = self.make_branch_and_tree('a')
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
68
        self.build_tree(['a/foo'])
6745.1.1 by Jelmer Vernooij
Avoid explicitly setting file ids or guard it by checking
69
        tree_a.add('foo')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
70
        rev1 = tree_a.commit('rev1')
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
71
        # create a knit-3 based format to fetch into
6653.6.5 by Jelmer Vernooij
Rename make_bzrdir to make_controldir.
72
        f = controldir.format_registry.make_controldir('development-subtree')
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
73
        try:
74
            format = tree_a.branch.repository._format
75
            format.check_conversion_target(f.repository_format)
76
            # if we cannot convert data to knit3, skip the test.
6619.3.2 by Jelmer Vernooij
Apply 2to3 except fix.
77
        except errors.BadConversionTarget as e:
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
78
            raise TestSkipped(str(e))
79
        self.get_transport().mkdir('b')
80
        b_bzrdir = f.initialize(self.get_url('b'))
81
        knit3_repo = b_bzrdir.create_repository()
82
        # fetch with a default limit (grab everything)
83
        knit3_repo.fetch(tree_a.branch.repository, revision_id=None)
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
84
        # Reopen to avoid any in-memory caching - ensure its reading from
85
        # disk.
86
        knit3_repo = b_bzrdir.open_repository()
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
87
        rev1_tree = knit3_repo.revision_tree(rev1)
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.
88
        rev1_tree.lock_read()
89
        try:
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
90
            lines = rev1_tree.get_file_lines(u'', rev1_tree.get_root_id())
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.
91
        finally:
92
            rev1_tree.unlock()
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
93
        self.assertEqual([], lines)
94
        b_branch = b_bzrdir.create_branch()
95
        b_branch.pull(tree_a.branch)
96
        try:
97
            tree_b = b_bzrdir.create_workingtree()
98
        except errors.NotLocalUrl:
4060.1.4 by Robert Collins
Streaming fetch from remote servers.
99
            try:
100
                tree_b = b_branch.create_checkout('b', lightweight=True)
101
            except errors.NotLocalUrl:
102
                raise TestSkipped("cannot make working tree with transport %r"
2696.3.2 by Martin Pool
Move some per-repository tests from big test_repository to test_fetch
103
                              % b_bzrdir.transport)
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
104
        rev2 = tree_b.commit('no change')
105
        rev2_tree = knit3_repo.revision_tree(rev2)
6405.2.7 by Jelmer Vernooij
Fix more tests.
106
        self.assertEqual(
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
107
            rev1,
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
108
            rev2_tree.get_file_revision(u'', rev2_tree.get_root_id()))
2696.3.9 by Martin Pool
merge trunk
109
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
110
    def do_test_fetch_to_rich_root_sets_parents_correctly(self, result,
111
        snapshots, root_id=ROOT_ID, allow_lefthand_ghost=False):
112
        """Assert that result is the parents of 'tip' after fetching snapshots.
113
114
        This helper constructs a 1.9 format source, and a test-format target
115
        and fetches the result of building snapshots in the source, then
116
        asserts that the parents of tip are result.
117
118
        :param result: A parents list for the inventories.get_parent_map call.
119
        :param snapshots: An iterable of snapshot parameters for
120
            BranchBuilder.build_snapshot.
121
        '"""
122
        # This overlaps slightly with the tests for commit builder about graph
123
        # consistency.
124
        # Cases:
125
        repo = self.make_repository('target')
4324.3.3 by Robert Collins
Fix silly typo.
126
        remote_format = isinstance(repo, remote.RemoteRepository)
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
127
        if not repo._format.rich_root_data and not remote_format:
128
            return # not relevant
129
        builder = self.make_branch_builder('source', format='1.9')
130
        builder.start_series()
131
        for revision_id, parent_ids, actions in snapshots:
6816.2.1 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
132
            builder.build_snapshot(parent_ids, actions,
133
            allow_leftmost_as_ghost=allow_lefthand_ghost,
134
            revision_id=revision_id)
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
135
        builder.finish_series()
136
        source = builder.get_branch()
137
        if remote_format and not repo._format.rich_root_data:
138
            # use a manual rich root format to ensure the code path is tested.
139
            repo = self.make_repository('remote-target',
140
                format='1.9-rich-root')
141
        repo.lock_write()
142
        self.addCleanup(repo.unlock)
143
        repo.fetch(source.repository)
5815.5.10 by Jelmer Vernooij
Fix two issues pointed out by John.
144
        graph = repo.get_file_graph()
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
145
        self.assertEqual(result,
5815.5.10 by Jelmer Vernooij
Fix two issues pointed out by John.
146
            graph.get_parent_map([(root_id, 'tip')])[(root_id, 'tip')])
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
147
148
    def test_fetch_to_rich_root_set_parent_no_parents(self):
149
        # No parents rev -> No parents
150
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
151
            [('tip', None, [('add', ('', ROOT_ID, 'directory', ''))]),
152
            ])
153
154
    def test_fetch_to_rich_root_set_parent_1_parent(self):
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
155
        # 1 parent rev -> 1 parent
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
156
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
157
            ((ROOT_ID, 'base'),),
158
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
159
             ('tip', None, []),
160
            ])
161
162
    def test_fetch_to_rich_root_set_parent_1_ghost_parent(self):
163
        # 1 ghost parent -> No parents
6162.2.1 by Jelmer Vernooij
Skip tests that require ghosts on repositories that don't support ghosts.
164
        if not self.repository_format.supports_ghosts:
165
            raise TestNotApplicable("repository format does not support "
166
                 "ghosts")
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
167
        self.do_test_fetch_to_rich_root_sets_parents_correctly((),
168
            [('tip', ['ghost'], [('add', ('', ROOT_ID, 'directory', ''))]),
169
            ], allow_lefthand_ghost=True)
170
171
    def test_fetch_to_rich_root_set_parent_2_head_parents(self):
172
        # 2 parents both heads -> 2 parents
173
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
174
            ((ROOT_ID, 'left'), (ROOT_ID, 'right')),
175
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
176
             ('left', None, []),
177
             ('right', ['base'], []),
178
             ('tip', ['left', 'right'], []),
179
            ])
180
181
    def test_fetch_to_rich_root_set_parent_2_parents_1_head(self):
182
        # 2 parents one head -> 1 parent
183
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
184
            ((ROOT_ID, 'right'),),
185
            [('left', None, [('add', ('', ROOT_ID, 'directory', ''))]),
186
             ('right', None, []),
187
             ('tip', ['left', 'right'], []),
188
            ])
189
190
    def test_fetch_to_rich_root_set_parent_1_parent_different_id_gone(self):
191
        # 1 parent different fileid, ours missing -> no parents
192
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
193
            (),
194
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
195
             ('tip', None, [('unversion', ROOT_ID),
196
                            ('add', ('', 'my-root', 'directory', '')),
197
                            ]),
198
            ], root_id='my-root')
199
200
    def test_fetch_to_rich_root_set_parent_1_parent_different_id_moved(self):
201
        # 1 parent different fileid, ours moved -> 1 parent
202
        # (and that parent honours the changing revid of the other location)
203
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
204
            (('my-root', 'origin'),),
205
            [('origin', None, [('add', ('', ROOT_ID, 'directory', '')),
206
                             ('add', ('child', 'my-root', 'directory', ''))]),
207
             ('base', None, []),
208
             ('tip', None, [('unversion', 'my-root'),
209
                            ('unversion', ROOT_ID),
6008.2.5 by Andrew Bennetts
Rename 'checkpoint' to 'flush', add some unit tests and more comments.
210
                            ('flush', None),
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
211
                            ('add', ('', 'my-root', 'directory', '')),
212
                            ]),
213
            ], root_id='my-root')
214
215
    def test_fetch_to_rich_root_set_parent_2_parent_1_different_id_gone(self):
216
        # 2 parents, 1 different fileid, our second missing -> 1 parent
217
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
218
            (('my-root', 'right'),),
219
            [('base', None, [('add', ('', ROOT_ID, 'directory', ''))]),
220
             ('right', None, [('unversion', ROOT_ID),
221
                              ('add', ('', 'my-root', 'directory', ''))]),
222
             ('tip', ['base', 'right'], [('unversion', ROOT_ID),
223
                            ('add', ('', 'my-root', 'directory', '')),
224
                            ]),
225
            ], root_id='my-root')
226
227
    def test_fetch_to_rich_root_set_parent_2_parent_2_different_id_moved(self):
228
        # 2 parents, 1 different fileid, our second moved -> 2 parent
229
        # (and that parent honours the changing revid of the other location)
230
        self.do_test_fetch_to_rich_root_sets_parents_correctly(
231
            (('my-root', 'right'),),
232
            # 'my-root' at 'child'.
233
            [('origin', None, [('add', ('', ROOT_ID, 'directory', '')),
234
                             ('add', ('child', 'my-root', 'directory', ''))]),
235
             ('base', None, []),
236
            # 'my-root' at root
237
             ('right', None, [('unversion', 'my-root'),
238
                              ('unversion', ROOT_ID),
6008.2.5 by Andrew Bennetts
Rename 'checkpoint' to 'flush', add some unit tests and more comments.
239
                              ('flush', None),
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
240
                              ('add', ('', 'my-root', 'directory', ''))]),
241
             ('tip', ['base', 'right'], [('unversion', 'my-root'),
242
                            ('unversion', ROOT_ID),
6008.2.5 by Andrew Bennetts
Rename 'checkpoint' to 'flush', add some unit tests and more comments.
243
                            ('flush', None),
4324.3.1 by Robert Collins
When adding rich root data follow the standard revision graph rules, so it does not create 'inconstent parents'.
244
                            ('add', ('', 'my-root', 'directory', '')),
245
                            ]),
246
            ], root_id='my-root')
247
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
248
    def test_fetch_all_from_self(self):
249
        tree = self.make_branch_and_tree('.')
250
        rev_id = tree.commit('one')
251
        # This needs to be a new copy of the repository, if this changes, the
252
        # test needs to be rewritten
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
253
        repo = tree.branch.repository.controldir.open_repository()
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
254
        # This fetch should be a no-op see bug #158333
255
        tree.branch.repository.fetch(repo, None)
256
257
    def test_fetch_from_self(self):
258
        tree = self.make_branch_and_tree('.')
259
        rev_id = tree.commit('one')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
260
        repo = tree.branch.repository.controldir.open_repository()
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
261
        # This fetch should be a no-op see bug #158333
262
        tree.branch.repository.fetch(repo, rev_id)
263
264
    def test_fetch_missing_from_self(self):
265
        tree = self.make_branch_and_tree('.')
266
        rev_id = tree.commit('one')
267
        # Even though the fetch() is a NO-OP it should assert the revision id
268
        # is present
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
269
        repo = tree.branch.repository.controldir.open_repository()
2948.3.1 by John Arbash Meinel
Fix bug #158333, make sure that Repository.fetch(self) is properly a no-op for all Repository implementations.
270
        self.assertRaises(errors.NoSuchRevision, tree.branch.repository.fetch,
271
                          repo, 'no-such-revision')
272
2696.3.9 by Martin Pool
merge trunk
273
    def makeARepoWithSignatures(self):
274
        wt = self.make_branch_and_tree('a-repo-with-sigs')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
275
        rev1 = wt.commit('rev1', allow_pointless=True)
2696.3.9 by Martin Pool
merge trunk
276
        repo = wt.branch.repository
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
277
        repo.lock_write()
278
        repo.start_write_group()
5751.2.3 by Jelmer Vernooij
More tests
279
        try:
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
280
            repo.sign_revision(rev1, gpg.LoopbackGPGStrategy(None))
5751.2.3 by Jelmer Vernooij
More tests
281
        except errors.UnsupportedOperation:
282
            self.assertFalse(repo._format.supports_revision_signatures)
283
            raise TestNotApplicable("repository format does not support signatures")
2592.3.96 by Robert Collins
Merge index improvements (includes bzr.dev).
284
        repo.commit_write_group()
285
        repo.unlock()
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
286
        return repo, rev1
2696.3.9 by Martin Pool
merge trunk
287
288
    def test_fetch_copies_signatures(self):
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
289
        source_repo, rev1 = self.makeARepoWithSignatures()
2696.3.9 by Martin Pool
merge trunk
290
        target_repo = self.make_repository('target')
291
        target_repo.fetch(source_repo, revision_id=None)
292
        self.assertEqual(
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
293
            source_repo.get_signature_text(rev1),
294
            target_repo.get_signature_text(rev1))
2535.3.48 by Andrew Bennetts
Merge from bzr.dev.
295
296
    def make_repository_with_one_revision(self):
3242.2.17 by Aaron Bentley
Fix broken tests
297
        wt = self.make_branch_and_tree('source')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
298
        rev1 = wt.commit('rev1', allow_pointless=True)
299
        return wt.branch.repository, rev1
2535.3.48 by Andrew Bennetts
Merge from bzr.dev.
300
301
    def test_fetch_revision_already_exists(self):
302
        # Make a repository with one revision.
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
303
        source_repo, rev1 = self.make_repository_with_one_revision()
2535.3.48 by Andrew Bennetts
Merge from bzr.dev.
304
        # Fetch that revision into a second repository.
305
        target_repo = self.make_repository('target')
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
306
        target_repo.fetch(source_repo, revision_id=rev1)
2535.3.48 by Andrew Bennetts
Merge from bzr.dev.
307
        # Now fetch again; there will be nothing to do.  This should work
308
        # without causing any errors.
6747.3.1 by Jelmer Vernooij
Avoid more uses of revision_id.
309
        target_repo.fetch(source_repo, revision_id=rev1)
2535.3.48 by Andrew Bennetts
Merge from bzr.dev.
310
1551.19.36 by Aaron Bentley
Prevent fetch all from causing pack collisions
311
    def test_fetch_all_same_revisions_twice(self):
312
        # Blind-fetching all the same revisions twice should succeed and be a
313
        # no-op the second time.
314
        repo = self.make_repository('repo')
315
        tree = self.make_branch_and_tree('tree')
316
        revision_id = tree.commit('test')
317
        repo.fetch(tree.branch.repository)
318
        repo.fetch(tree.branch.repository)
4360.2.1 by Robert Collins
Don't return ghosts in the keyset for PendingAncestryResult.
319
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
320
    def make_simple_branch_with_ghost(self):
4476.3.59 by Andrew Bennetts
Undo changes that aren't needed anymore.
321
        builder = self.make_branch_builder('source')
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
322
        builder.start_series()
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
323
        a_revid = builder.build_snapshot(None, [
4476.3.59 by Andrew Bennetts
Undo changes that aren't needed anymore.
324
            ('add', ('', 'root-id', 'directory', None)),
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
325
            ('add', ('file', 'file-id', 'file', 'content\n'))])
326
        b_revid = builder.build_snapshot([a_revid, 'ghost-id'], [])
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
327
        builder.finish_series()
328
        source_b = builder.get_branch()
329
        source_b.lock_read()
330
        self.addCleanup(source_b.unlock)
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
331
        return source_b, b_revid
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
332
333
    def test_fetch_with_ghost(self):
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
334
        source_b, b_revid = self.make_simple_branch_with_ghost()
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
335
        target = self.make_repository('target')
336
        target.lock_write()
337
        self.addCleanup(target.unlock)
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
338
        target.fetch(source_b.repository, revision_id=b_revid)
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
339
340
    def test_fetch_into_smart_with_ghost(self):
341
        trans = self.make_smart_server('target')
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
342
        source_b, b_revid = self.make_simple_branch_with_ghost()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
343
        if not source_b.controldir._format.supports_transport(trans):
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
344
            raise TestNotApplicable("format does not support transport")
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
345
        target = self.make_repository('target')
346
        # Re-open the repository over the smart protocol
347
        target = repository.Repository.open(trans.base)
348
        target.lock_write()
349
        self.addCleanup(target.unlock)
350
        try:
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
351
            target.fetch(source_b.repository, revision_id=b_revid)
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
352
        except errors.TokenLockingNotSupported:
353
            # The code inside fetch() that tries to lock and then fails, also
354
            # causes weird problems with 'lock_not_held' later on...
355
            target.lock_read()
6050.1.2 by Martin
Make tests raising KnownFailure use the knownFailure method instead
356
            self.knownFailure('some repositories fail to fetch'
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
357
                ' via the smart server because of locking issues.')
358
359
    def test_fetch_from_smart_with_ghost(self):
360
        trans = self.make_smart_server('source')
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
361
        source_b, b_revid = self.make_simple_branch_with_ghost()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
362
        if not source_b.controldir._format.supports_transport(trans):
6205.3.1 by Jelmer Vernooij
Add ControlDirFormat.supports_transport.
363
            raise TestNotApplicable("format does not support transport")
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
364
        target = self.make_repository('target')
365
        target.lock_write()
366
        self.addCleanup(target.unlock)
367
        # Re-open the repository over the smart protocol
368
        source = repository.Repository.open(trans.base)
369
        source.lock_read()
370
        self.addCleanup(source.unlock)
6825.2.1 by Jelmer Vernooij
Fix some tests for foreign branches.
371
        target.fetch(source, revision_id=b_revid)
4392.2.2 by John Arbash Meinel
Add tests that ensure we can fetch branches with ghosts in their ancestry.
372