/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2745.6.7 by Aaron Bentley
Clean-up
1
# Copyright (C) 2007 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
18
"""Test operations that check the repository for corruption"""
19
20
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
21
from bzrlib import (
2745.6.48 by Andrew Bennetts
Merge find-inconsistent-parents.
22
    errors,
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
23
    inventory,
24
    revision as _mod_revision,
25
    )
2745.6.48 by Andrew Bennetts
Merge find-inconsistent-parents.
26
from bzrlib.tests import TestNotApplicable
2745.6.42 by Andrew Bennetts
Use TestScenarioApplier to more cleanly parameterise check and reconcile tests.
27
from bzrlib.tests.repository_implementations import TestCaseWithRepository
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
28
from bzrlib.tests.repository_implementations.helpers import (
29
    TestCaseWithBrokenRevisionIndex,
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
30
    )
31
32
3036.1.1 by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions.
33
class TestNoSpuriousInconsistentAncestors(TestCaseWithRepository):
34
35
    def test_two_files_different_versions_no_inconsistencies_bug_165071(self):
36
        """Two files, with different versions can be clean."""
37
        tree = self.make_branch_and_tree('.')
38
        self.build_tree(['foo'])
39
        tree.smart_add(['.'])
40
        tree.commit('1')
41
        self.build_tree(['bar'])
42
        tree.smart_add(['.'])
43
        tree.commit('2')
44
        # XXX: check requires a non-empty revision IDs list, but it ignores the
45
        # contents of it!
46
        check_object = tree.branch.repository.check(['ignored'])
47
        check_object.report_results(verbose=False)
48
        log = self._get_log(keep_log_file=True)
49
        self.assertContainsRe(
50
            log,
51
            "0 unreferenced text versions")
52
53
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
54
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
55
2819.2.2 by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents.
56
    def test__find_inconsistent_revision_parents(self):
57
        """_find_inconsistent_revision_parents finds revisions with broken
58
        parents.
59
        """
60
        repo = self.make_repo_with_extra_ghost_index()
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
61
        self.assertEqual(
2592.3.214 by Robert Collins
Merge bzr.dev.
62
            [('revision-id', ('incorrect-parent',), ())],
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
63
            list(repo._find_inconsistent_revision_parents()))
64
2819.2.2 by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents.
65
    def test__check_for_inconsistent_revision_parents(self):
66
        """_check_for_inconsistent_revision_parents raises BzrCheckError if
67
        there are any revisions with inconsistent parents.
68
        """
69
        repo = self.make_repo_with_extra_ghost_index()
70
        self.assertRaises(
71
            errors.BzrCheckError,
72
            repo._check_for_inconsistent_revision_parents)
73
74
    def test__check_for_inconsistent_revision_parents_on_clean_repo(self):
75
        """_check_for_inconsistent_revision_parents does nothing if there are
76
        no broken revisions.
77
        """
78
        repo = self.make_repository('empty-repo')
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
79
        if not repo.revision_graph_can_have_wrong_parents():
80
            raise TestNotApplicable(
81
                '%r cannot have corrupt revision index.' % repo)
2592.3.214 by Robert Collins
Merge bzr.dev.
82
        repo.lock_read()
83
        try:
84
            repo._check_for_inconsistent_revision_parents()  # nothing happens
85
        finally:
86
            repo.unlock()
2819.2.2 by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents.
87
2819.2.3 by Andrew Bennetts
Add test that repo.check will report on wrong parents in the revision graph.
88
    def test_check_reports_bad_ancestor(self):
89
        repo = self.make_repo_with_extra_ghost_index()
90
        # XXX: check requires a non-empty revision IDs list, but it ignores the
91
        # contents of it!
92
        check_object = repo.check(['ignored'])
93
        check_object.report_results(verbose=False)
94
        log = self._get_log(keep_log_file=True)
95
        self.assertContainsRe(
96
            log, '1 revisions have incorrect parents in the revision index')
97
        check_object.report_results(verbose=True)
98
        log = self._get_log(keep_log_file=True)
99
        self.assertContainsRe(
100
            log,
101
            "revision-id has wrong parents in index: "
2592.3.214 by Robert Collins
Merge bzr.dev.
102
            r"\('incorrect-parent',\) should be \(\)")
2819.2.3 by Andrew Bennetts
Add test that repo.check will report on wrong parents in the revision graph.
103