1
# Copyright (C) 2006 by Canonical Ltd
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.
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.
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
17
"""Tests for reconiliation of repositories."""
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
30
class TestNeedingReweave(TestCaseWithRepository):
33
super(TestNeedingReweave, self).setUp()
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, [])
41
# a inventory with no parents and the revision has parents..
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,
48
committer="Foo Bar <foo@example.com>",
52
rev.parent_ids = ['the_ghost']
53
repo.add_revision('ghost', rev)
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,
61
committer="Foo Bar <foo@example.com>",
64
revision_id='the_ghost')
66
repo.add_revision('the_ghost', rev)
69
def test_reweave_empty_makes_backup_wave(self):
70
self.make_repository('empty')
71
d = bzrlib.bzrdir.BzrDir.open('empty')
73
repo = d.open_repository()
74
repo.control_weaves.get_weave('inventory.backup',
75
repo.get_transaction())
77
def test_reweave_inventory_without_revision(self):
78
d = bzrlib.bzrdir.BzrDir.open('inventory_no_revision')
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')
88
def test_reweave_inventory_preserves_a_revision_with_ghosts(self):
89
d = bzrlib.bzrdir.BzrDir.open('inventory_one_ghost')
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'))
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'))
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'))