1
# Copyright (C) 2007-2011 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Test operations that check the repository for corruption"""
23
from bzrlib.tests import (
26
from bzrlib.tests.scenarios import load_tests_apply_scenarios
27
from bzrlib.tests.per_repository_vf import (
28
TestCaseWithRepository,
29
all_repository_vf_format_scenarios,
31
from bzrlib.tests.per_repository_vf.helpers import (
32
TestCaseWithBrokenRevisionIndex,
36
load_tests = load_tests_apply_scenarios
39
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
41
scenarios = all_repository_vf_format_scenarios()
43
def test__find_inconsistent_revision_parents(self):
44
"""_find_inconsistent_revision_parents finds revisions with broken
47
repo = self.make_repo_with_extra_ghost_index()
49
[('revision-id', ('incorrect-parent',), ())],
50
list(repo._find_inconsistent_revision_parents()))
52
def test__check_for_inconsistent_revision_parents(self):
53
"""_check_for_inconsistent_revision_parents raises BzrCheckError if
54
there are any revisions with inconsistent parents.
56
repo = self.make_repo_with_extra_ghost_index()
59
repo._check_for_inconsistent_revision_parents)
61
def test__check_for_inconsistent_revision_parents_on_clean_repo(self):
62
"""_check_for_inconsistent_revision_parents does nothing if there are
65
repo = self.make_repository('empty-repo')
66
if not repo._format.revision_graph_can_have_wrong_parents:
67
raise TestNotApplicable(
68
'%r cannot have corrupt revision index.' % repo)
71
repo._check_for_inconsistent_revision_parents() # nothing happens
75
def test_check_reports_bad_ancestor(self):
76
repo = self.make_repo_with_extra_ghost_index()
77
# XXX: check requires a non-empty revision IDs list, but it ignores the
79
check_object = repo.check(['ignored'])
80
check_object.report_results(verbose=False)
81
self.assertContainsRe(self.get_log(),
82
'1 revisions have incorrect parents in the revision index')
83
check_object.report_results(verbose=True)
84
self.assertContainsRe(
86
"revision-id has wrong parents in index: "
87
r"\('incorrect-parent',\) should be \(\)")
90
class TestCallbacks(TestCaseWithRepository):
92
scenarios = all_repository_vf_format_scenarios()
94
def test_callback_tree_and_branch(self):
95
# use a real tree to get actual refs that will work
96
tree = self.make_branch_and_tree('foo')
97
revid = tree.commit('foo')
99
self.addCleanup(tree.unlock)
101
for ref in tree._get_check_refs():
102
needed_refs.setdefault(ref, []).append(tree)
103
for ref in tree.branch._get_check_refs():
104
needed_refs.setdefault(ref, []).append(tree.branch)
105
self.tree_check = tree._check
106
self.branch_check = tree.branch.check
107
self.overrideAttr(tree, "_check", self.tree_callback)
108
self.overrideAttr(tree.branch, "check", self.branch_callback)
110
tree.branch.repository.check([revid], callback_refs=needed_refs)
111
self.assertNotEqual([], self.callbacks)
113
def tree_callback(self, refs):
114
self.callbacks.append(('tree', refs))
115
return self.tree_check(refs)
117
def branch_callback(self, refs):
118
self.callbacks.append(('branch', refs))
119
return self.branch_check(refs)
122
class TestNoSpuriousInconsistentAncestors(TestCaseWithRepository):
124
scenarios = all_repository_vf_format_scenarios()
126
def test_two_files_different_versions_no_inconsistencies_bug_165071(self):
127
"""Two files, with different versions can be clean."""
128
tree = self.make_branch_and_tree('.')
129
self.build_tree(['foo'])
130
tree.smart_add(['.'])
131
revid1 = tree.commit('1')
132
self.build_tree(['bar'])
133
tree.smart_add(['.'])
134
revid2 = tree.commit('2')
135
check_object = tree.branch.repository.check([revid1, revid2])
136
check_object.report_results(verbose=True)
137
self.assertContainsRe(self.get_log(), "0 unreferenced text versions")