~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/repository_implementations/test_reconcile.py

  • Committer: Robert Collins
  • Date: 2006-02-23 04:08:56 UTC
  • mto: (1587.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1588.
  • Revision ID: robertc@robertcollins.net-20060223040856-8b476741783b6244
Import bzrtools' 'fix' command as 'bzr reconcile.'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
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
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""Tests for reconiliation of repositories."""
 
18
 
 
19
 
 
20
import bzrlib
 
21
import bzrlib.errors as errors
 
22
from bzrlib.reconcile import reconcile
 
23
from bzrlib.revision import Revision
 
24
from bzrlib.tests.repository_implementations.test_repository import TestCaseWithRepository
 
25
from bzrlib.transport import get_transport
 
26
from bzrlib.tree import EmptyTree
 
27
from bzrlib.workingtree import WorkingTree
 
28
 
 
29
 
 
30
class TestNeedingReweave(TestCaseWithRepository):
 
31
 
 
32
    def setUp(self):
 
33
        super(TestNeedingReweave, self).setUp()
 
34
        
 
35
        t = get_transport(self.get_url())
 
36
        # an empty inventory with no revision for testing with.
 
37
        repo = self.make_repository('inventory_no_revision')
 
38
        inv = EmptyTree().inventory
 
39
        repo.add_inventory('missing', inv, [])
 
40
 
 
41
        # a inventory with no parents and the revision has parents..
 
42
        # i.e. a ghost.
 
43
        t.copy_tree('inventory_no_revision', 'inventory_one_ghost')
 
44
        repo = bzrlib.repository.Repository.open('inventory_one_ghost')
 
45
        sha1 = repo.add_inventory('ghost', inv, [])
 
46
        rev = Revision(timestamp=0,
 
47
                       timezone=None,
 
48
                       committer="Foo Bar <foo@example.com>",
 
49
                       message="Message",
 
50
                       inventory_sha1=sha1,
 
51
                       revision_id='ghost')
 
52
        rev.parent_ids = ['the_ghost']
 
53
        repo.add_revision('ghost', rev)
 
54
         
 
55
        # a inventory with a ghost that can be corrected now.
 
56
        t.copy_tree('inventory_one_ghost', 'inventory_ghost_present')
 
57
        repo = bzrlib.repository.Repository.open('inventory_ghost_present')
 
58
        sha1 = repo.add_inventory('the_ghost', inv, [])
 
59
        rev = Revision(timestamp=0,
 
60
                       timezone=None,
 
61
                       committer="Foo Bar <foo@example.com>",
 
62
                       message="Message",
 
63
                       inventory_sha1=sha1,
 
64
                       revision_id='the_ghost')
 
65
        rev.parent_ids = []
 
66
        repo.add_revision('the_ghost', rev)
 
67
         
 
68
 
 
69
    def test_reweave_empty_makes_backup_wave(self):
 
70
        self.make_repository('empty')
 
71
        d = bzrlib.bzrdir.BzrDir.open('empty')
 
72
        reconcile(d)
 
73
        repo = d.open_repository()
 
74
        repo.control_weaves.get_weave('inventory.backup',
 
75
                                      repo.get_transaction())
 
76
 
 
77
    def test_reweave_inventory_without_revision(self):
 
78
        d = bzrlib.bzrdir.BzrDir.open('inventory_no_revision')
 
79
        reconcile(d)
 
80
        # now the backup should have it but not the current inventory
 
81
        repo = d.open_repository()
 
82
        backup = repo.control_weaves.get_weave('inventory.backup',
 
83
                                               repo.get_transaction())
 
84
        self.assertTrue('missing' in backup.names())
 
85
        self.assertRaises(errors.WeaveRevisionNotPresent,
 
86
                          repo.get_inventory, 'missing')
 
87
 
 
88
    def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
 
89
        d = bzrlib.bzrdir.BzrDir.open('inventory_one_ghost')
 
90
        reconcile(d)
 
91
        # now the current inventory should still have 'ghost'
 
92
        repo = d.open_repository()
 
93
        repo.get_inventory('ghost')
 
94
        self.assertEqual([None, 'ghost'], repo.get_ancestry('ghost'))
 
95
        
 
96
    def test_reweave_inventory_fixes_ancestryfor_a_present_ghost(self):
 
97
        d = bzrlib.bzrdir.BzrDir.open('inventory_ghost_present')
 
98
        repo = d.open_repository()
 
99
        self.assertEqual([None, 'ghost'], repo.get_ancestry('ghost'))
 
100
        reconcile(d)
 
101
        # now the current inventory should still have 'ghost'
 
102
        repo = d.open_repository()
 
103
        repo.get_inventory('ghost')
 
104
        repo.get_inventory('the_ghost')
 
105
        self.assertEqual([None, 'the_ghost', 'ghost'], repo.get_ancestry('ghost'))
 
106
        self.assertEqual([None, 'the_ghost'], repo.get_ancestry('the_ghost'))