149
146
branch = self.make_branch('branch', format=knit2_format)
150
147
branch.pull(tree.branch, stop_revision='rev1')
151
148
repo = branch.repository
152
root_knit = repo.weave_store.get_weave('tree-root',
153
repo.get_transaction())
154
# Make sure fetch retrieved only what we requested
155
self.assertTrue('rev1' in root_knit)
156
self.assertTrue('rev2' not in root_knit)
151
# Make sure fetch retrieved only what we requested
152
self.assertEqual({('tree-root', 'rev1'):()},
153
repo.texts.get_parent_map(
154
[('tree-root', 'rev1'), ('tree-root', 'rev2')]))
157
157
branch.pull(tree.branch)
158
root_knit = repo.weave_store.get_weave('tree-root',
159
repo.get_transaction())
160
158
# Make sure that the next revision in the root knit was retrieved,
161
159
# even though the text, name, parent_id, etc., were unchanged.
162
self.assertTrue('rev2' in root_knit)
162
# Make sure fetch retrieved only what we requested
163
self.assertEqual({('tree-root', 'rev2'):(('tree-root', 'rev1'),)},
164
repo.texts.get_parent_map([('tree-root', 'rev2')]))
164
168
def test_fetch_incompatible(self):
165
169
knit_tree = self.make_branch_and_tree('knit', format='knit')
297
303
# FIXME naughty poking in there.
298
304
self.get_readonly_server().logs = []
299
# check there is nothing more to fetch
300
source = Branch.open(self.get_readonly_url("source/"))
305
# check there is nothing more to fetch. We take care to re-use the
306
# existing transport so that the request logs we're about to examine
307
# aren't cluttered with redundant probes for a smart server.
308
# XXX: Perhaps this further parameterisation: test http with smart
309
# server, and test http without smart server?
310
source = Branch.open(
311
self.get_readonly_url("source/"),
312
possible_transports=[source.bzrdir.root_transport])
301
313
self.assertEqual(target.fetch(source), (0, []))
302
314
# should make just two requests
303
315
http_logs = self.get_readonly_server().logs
305
317
self.log('\n'.join(http_logs))
306
318
self.assertEqual(1, self._count_log_matches('branch-format', http_logs))
307
319
self.assertEqual(1, self._count_log_matches('branch/format', http_logs))
308
self.assertEqual(1, self._count_log_matches('repository/format', http_logs))
320
self.assertEqual(1, self._count_log_matches('repository/format',
309
322
self.assertTrue(1 >= self._count_log_matches('revision-history',
311
324
self.assertTrue(1 >= self._count_log_matches('last-revision',
313
326
self.assertEqual(4, len(http_logs))
329
class Test1To2Fetch(TestCaseWithTransport):
330
"""Tests for Model1To2 failure modes"""
332
def make_tree_and_repo(self):
333
self.tree = self.make_branch_and_tree('tree', format='pack-0.92')
334
self.repo = self.make_repository('rich-repo', format='rich-root-pack')
335
self.repo.lock_write()
336
self.addCleanup(self.repo.unlock)
338
def do_fetch_order_test(self, first, second):
339
"""Test that fetch works no matter what the set order of revision is.
341
This test depends on the order of items in a set, which is
342
implementation-dependant, so we test A, B and then B, A.
344
self.make_tree_and_repo()
345
self.tree.commit('Commit 1', rev_id=first)
346
self.tree.commit('Commit 2', rev_id=second)
347
self.repo.fetch(self.tree.branch.repository, second)
349
def test_fetch_order_AB(self):
350
"""See do_fetch_order_test"""
351
self.do_fetch_order_test('A', 'B')
353
def test_fetch_order_BA(self):
354
"""See do_fetch_order_test"""
355
self.do_fetch_order_test('B', 'A')
357
def get_parents(self, file_id, revision_id):
358
self.repo.lock_read()
360
parent_map = self.repo.texts.get_parent_map([(file_id, revision_id)])
361
return parent_map[(file_id, revision_id)]
365
def test_fetch_ghosts(self):
366
self.make_tree_and_repo()
367
self.tree.commit('first commit', rev_id='left-parent')
368
self.tree.add_parent_tree_id('ghost-parent')
369
fork = self.tree.bzrdir.sprout('fork', 'null:').open_workingtree()
370
fork.commit('not a ghost', rev_id='not-ghost-parent')
371
self.tree.branch.repository.fetch(fork.branch.repository,
373
self.tree.add_parent_tree_id('not-ghost-parent')
374
self.tree.commit('second commit', rev_id='second-id')
375
self.repo.fetch(self.tree.branch.repository, 'second-id')
376
root_id = self.tree.get_root_id()
378
((root_id, 'left-parent'), (root_id, 'ghost-parent'),
379
(root_id, 'not-ghost-parent')),
380
self.get_parents(root_id, 'second-id'))
382
def make_two_commits(self, change_root, fetch_twice):
383
self.make_tree_and_repo()
384
self.tree.commit('first commit', rev_id='first-id')
386
self.tree.set_root_id('unique-id')
387
self.tree.commit('second commit', rev_id='second-id')
389
self.repo.fetch(self.tree.branch.repository, 'first-id')
390
self.repo.fetch(self.tree.branch.repository, 'second-id')
392
def test_fetch_changed_root(self):
393
self.make_two_commits(change_root=True, fetch_twice=False)
394
self.assertEqual((), self.get_parents('unique-id', 'second-id'))
396
def test_two_fetch_changed_root(self):
397
self.make_two_commits(change_root=True, fetch_twice=True)
398
self.assertEqual((), self.get_parents('unique-id', 'second-id'))
400
def test_two_fetches(self):
401
self.make_two_commits(change_root=False, fetch_twice=True)
402
self.assertEqual((('TREE_ROOT', 'first-id'),),
403
self.get_parents('TREE_ROOT', 'second-id'))