~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_fetch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-04-30 06:54:40 UTC
  • mfrom: (3380.1.16 make-it-right)
  • Revision ID: pqm@pqm.ubuntu.com-20080430065440-1l8693padc4f7uho
(abentley) Fix fetch from non-rich-root to rich-root

Show diffs side-by-side

added added

removed removed

Lines of Context:
322
322
        self.assertTrue(1 >= self._count_log_matches('last-revision',
323
323
                                                     http_logs))
324
324
        self.assertEqual(4, len(http_logs))
 
325
 
 
326
 
 
327
class Test1To2Fetch(TestCaseWithTransport):
 
328
    """Tests for Model1To2 failure modes"""
 
329
 
 
330
    def make_tree_and_repo(self):
 
331
        self.tree = self.make_branch_and_tree('tree', format='pack-0.92')
 
332
        self.repo = self.make_repository('rich-repo', format='rich-root-pack')
 
333
        self.repo.lock_write()
 
334
        self.addCleanup(self.repo.unlock)
 
335
 
 
336
    def do_fetch_order_test(self, first, second):
 
337
        """Test that fetch works no matter what the set order of revision is.
 
338
 
 
339
        This test depends on the order of items in a set, which is
 
340
        implementation-dependant, so we test A, B and then B, A.
 
341
        """
 
342
        self.make_tree_and_repo()
 
343
        self.tree.commit('Commit 1', rev_id=first)
 
344
        self.tree.commit('Commit 2', rev_id=second)
 
345
        self.repo.fetch(self.tree.branch.repository, second)
 
346
 
 
347
    def test_fetch_order_AB(self):
 
348
        """See do_fetch_order_test"""
 
349
        self.do_fetch_order_test('A', 'B')
 
350
 
 
351
    def test_fetch_order_BA(self):
 
352
        """See do_fetch_order_test"""
 
353
        self.do_fetch_order_test('B', 'A')
 
354
 
 
355
    def get_parents(self, file_id, revision_id):
 
356
        transaction = self.repo.get_transaction()
 
357
        vf = self.repo.weave_store.get_weave(file_id, transaction)
 
358
        return vf.get_parents_with_ghosts(revision_id)
 
359
 
 
360
    def test_fetch_ghosts(self):
 
361
        self.make_tree_and_repo()
 
362
        self.tree.commit('first commit', rev_id='left-parent')
 
363
        self.tree.add_parent_tree_id('ghost-parent')
 
364
        fork = self.tree.bzrdir.sprout('fork', 'null:').open_workingtree()
 
365
        fork.commit('not a ghost', rev_id='not-ghost-parent')
 
366
        self.tree.branch.repository.fetch(fork.branch.repository,
 
367
                                     'not-ghost-parent')
 
368
        self.tree.add_parent_tree_id('not-ghost-parent')
 
369
        self.tree.commit('second commit', rev_id='second-id')
 
370
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
371
        root_id = self.tree.get_root_id()
 
372
        self.assertEqual(['left-parent', 'ghost-parent', 'not-ghost-parent'],
 
373
                         self.get_parents(root_id, 'second-id'))
 
374
 
 
375
    def make_two_commits(self, change_root, fetch_twice):
 
376
        self.make_tree_and_repo()
 
377
        self.tree.commit('first commit', rev_id='first-id')
 
378
        if change_root:
 
379
            self.tree.set_root_id('unique-id')
 
380
        self.tree.commit('second commit', rev_id='second-id')
 
381
        if fetch_twice:
 
382
            self.repo.fetch(self.tree.branch.repository, 'first-id')
 
383
        self.repo.fetch(self.tree.branch.repository, 'second-id')
 
384
 
 
385
    def test_fetch_changed_root(self):
 
386
        self.make_two_commits(change_root=True, fetch_twice=False)
 
387
        self.assertEqual([], self.get_parents('unique-id', 'second-id'))
 
388
 
 
389
    def test_two_fetch_changed_root(self):
 
390
        self.make_two_commits(change_root=True, fetch_twice=True)
 
391
        self.assertEqual([], self.get_parents('unique-id', 'second-id'))
 
392
 
 
393
    def test_two_fetches(self):
 
394
        self.make_two_commits(change_root=False, fetch_twice=True)
 
395
        self.assertEqual(['first-id'],
 
396
                         self.get_parents('TREE_ROOT', 'second-id'))