/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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2745.6.7 by Aaron Bentley
Clean-up
16
17
18
"""Test operations that check the repository for corruption"""
19
4657.1.1 by Robert Collins
Do not add the root directory entry to the list of expected keys during check in non rich-root repositories. (#416732)
20
import os
2745.6.7 by Aaron Bentley
Clean-up
21
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
22
from bzrlib import (
4657.1.1 by Robert Collins
Do not add the root directory entry to the list of expected keys during check in non rich-root repositories. (#416732)
23
    check,
24
    config as _mod_config,
2745.6.48 by Andrew Bennetts
Merge find-inconsistent-parents.
25
    errors,
4657.1.1 by Robert Collins
Do not add the root directory entry to the list of expected keys during check in non rich-root repositories. (#416732)
26
    inventory,
2745.6.1 by Aaron Bentley
Initial checking of knit graphs
27
    revision as _mod_revision,
28
    )
2745.6.48 by Andrew Bennetts
Merge find-inconsistent-parents.
29
from bzrlib.tests import TestNotApplicable
3689.1.1 by John Arbash Meinel
Rename repository_implementations tests into per_repository tests
30
from bzrlib.tests.per_repository import TestCaseWithRepository
31
from bzrlib.tests.per_repository.helpers import (
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
32
    TestCaseWithBrokenRevisionIndex,
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
33
    )
34
35
3036.1.1 by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions.
36
class TestNoSpuriousInconsistentAncestors(TestCaseWithRepository):
37
38
    def test_two_files_different_versions_no_inconsistencies_bug_165071(self):
39
        """Two files, with different versions can be clean."""
40
        tree = self.make_branch_and_tree('.')
41
        self.build_tree(['foo'])
42
        tree.smart_add(['.'])
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
43
        revid1 = tree.commit('1')
3036.1.1 by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions.
44
        self.build_tree(['bar'])
45
        tree.smart_add(['.'])
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
46
        revid2 = tree.commit('2')
47
        check_object = tree.branch.repository.check([revid1, revid2])
4245.1.1 by Ian Clatworthy
minor test clean-ups & _reconcile_pack API
48
        check_object.report_results(verbose=True)
3036.1.1 by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions.
49
        log = self._get_log(keep_log_file=True)
4332.3.17 by Robert Collins
Check revisions as we cross check the revision index, rather than in a separate pass.
50
        self.assertContainsRe(log, "0 unreferenced text versions")
3036.1.1 by Robert Collins
* ``check`` no longer reports spurious unreferenced text versions.
51
52
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
53
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
54
2819.2.2 by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents.
55
    def test__find_inconsistent_revision_parents(self):
56
        """_find_inconsistent_revision_parents finds revisions with broken
57
        parents.
58
        """
59
        repo = self.make_repo_with_extra_ghost_index()
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
60
        self.assertEqual(
2592.3.214 by Robert Collins
Merge bzr.dev.
61
            [('revision-id', ('incorrect-parent',), ())],
2819.2.1 by Andrew Bennetts
Implement KnitRepository._find_inconsistent_revision_parents.
62
            list(repo._find_inconsistent_revision_parents()))
63
2819.2.2 by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents.
64
    def test__check_for_inconsistent_revision_parents(self):
65
        """_check_for_inconsistent_revision_parents raises BzrCheckError if
66
        there are any revisions with inconsistent parents.
67
        """
68
        repo = self.make_repo_with_extra_ghost_index()
69
        self.assertRaises(
70
            errors.BzrCheckError,
71
            repo._check_for_inconsistent_revision_parents)
72
73
    def test__check_for_inconsistent_revision_parents_on_clean_repo(self):
74
        """_check_for_inconsistent_revision_parents does nothing if there are
75
        no broken revisions.
76
        """
77
        repo = self.make_repository('empty-repo')
2819.2.5 by Andrew Bennetts
Make reconcile abort gracefully if the revision index has bad parents.
78
        if not repo.revision_graph_can_have_wrong_parents():
79
            raise TestNotApplicable(
80
                '%r cannot have corrupt revision index.' % repo)
2592.3.214 by Robert Collins
Merge bzr.dev.
81
        repo.lock_read()
82
        try:
83
            repo._check_for_inconsistent_revision_parents()  # nothing happens
84
        finally:
85
            repo.unlock()
2819.2.2 by Andrew Bennetts
Implement _check_for_inconsistent_revision_parents.
86
2819.2.3 by Andrew Bennetts
Add test that repo.check will report on wrong parents in the revision graph.
87
    def test_check_reports_bad_ancestor(self):
88
        repo = self.make_repo_with_extra_ghost_index()
89
        # XXX: check requires a non-empty revision IDs list, but it ignores the
90
        # contents of it!
91
        check_object = repo.check(['ignored'])
92
        check_object.report_results(verbose=False)
93
        log = self._get_log(keep_log_file=True)
94
        self.assertContainsRe(
95
            log, '1 revisions have incorrect parents in the revision index')
96
        check_object.report_results(verbose=True)
97
        log = self._get_log(keep_log_file=True)
98
        self.assertContainsRe(
99
            log,
100
            "revision-id has wrong parents in index: "
2592.3.214 by Robert Collins
Merge bzr.dev.
101
            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.
102
4332.3.11 by Robert Collins
Move tree and back callbacks into the repository check core.
103
104
class TestCallbacks(TestCaseWithRepository):
105
106
    def test_callback_tree_and_branch(self):
107
        # use a real tree to get actual refs that will work
108
        tree = self.make_branch_and_tree('foo')
109
        revid = tree.commit('foo')
110
        tree.lock_read()
111
        self.addCleanup(tree.unlock)
112
        needed_refs = {}
113
        for ref in tree._get_check_refs():
114
            needed_refs.setdefault(ref, []).append(tree)
115
        for ref in tree.branch._get_check_refs():
116
            needed_refs.setdefault(ref, []).append(tree.branch)
117
        self.tree_check = tree._check
118
        self.branch_check = tree.branch.check
119
        tree._check = self.tree_callback
120
        tree.branch.check = self.branch_callback
121
        self.callbacks = []
122
        tree.branch.repository.check([revid], callback_refs=needed_refs)
123
        self.assertNotEqual([], self.callbacks)
124
125
    def tree_callback(self, refs):
126
        self.callbacks.append(('tree', refs))
127
        return self.tree_check(refs)
128
129
    def branch_callback(self, refs):
130
        self.callbacks.append(('branch', refs))
131
        return self.branch_check(refs)
4657.1.1 by Robert Collins
Do not add the root directory entry to the list of expected keys during check in non rich-root repositories. (#416732)
132
133
134
class TestCleanRepository(TestCaseWithRepository):
135
136
    def test_new_repo(self):
137
        repo = self.make_repository('foo')
138
        repo.lock_write()
139
        self.addCleanup(repo.unlock)
140
        config = _mod_config.Config()
141
        os.environ['BZR_EMAIL'] = 'foo@sample.com'
142
        builder = repo.get_commit_builder(None, [], config)
143
        list(builder.record_iter_changes(None, _mod_revision.NULL_REVISION, [
144
            ('TREE_ROOT', (None, ''), True, (False, True), (None, None),
145
            (None, ''), (None, 'directory'), (None, False))]))
146
        builder.finish_inventory()
147
        rev_id = builder.commit('first post')
148
        result = repo.check(None, check_repo=True)
149
        result.report_results(True)
150
        log = self._get_log(keep_log_file=True)
151
        self.assertFalse('Missing' in log, "Something was missing in %r" % log)