13
13
# You should have received a copy of the GNU General Public License
14
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
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
"""Test operations that check the repository for corruption"""
21
22
from bzrlib import (
24
config as _mod_config,
24
27
revision as _mod_revision,
26
29
from bzrlib.tests import TestNotApplicable
27
from bzrlib.tests.repository_implementations import TestCaseWithRepository
28
from bzrlib.tests.repository_implementations.helpers import (
30
from bzrlib.tests.per_repository import TestCaseWithRepository
31
from bzrlib.tests.per_repository.helpers import (
29
32
TestCaseWithBrokenRevisionIndex,
37
40
tree = self.make_branch_and_tree('.')
38
41
self.build_tree(['foo'])
39
42
tree.smart_add(['.'])
43
revid1 = tree.commit('1')
41
44
self.build_tree(['bar'])
42
45
tree.smart_add(['.'])
44
# XXX: check requires a non-empty revision IDs list, but it ignores the
46
check_object = tree.branch.repository.check(['ignored'])
47
check_object.report_results(verbose=False)
46
revid2 = tree.commit('2')
47
check_object = tree.branch.repository.check([revid1, revid2])
48
check_object.report_results(verbose=True)
48
49
log = self._get_log(keep_log_file=True)
49
self.assertContainsRe(
51
"0 unreferenced text versions")
50
self.assertContainsRe(log, "0 unreferenced text versions")
54
53
class TestFindInconsistentRevisionParents(TestCaseWithBrokenRevisionIndex):
101
100
"revision-id has wrong parents in index: "
102
101
r"\('incorrect-parent',\) should be \(\)")
104
class TestCallbacks(TestCaseWithRepository):
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')
111
self.addCleanup(tree.unlock)
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
122
tree.branch.repository.check([revid], callback_refs=needed_refs)
123
self.assertNotEqual([], self.callbacks)
125
def tree_callback(self, refs):
126
self.callbacks.append(('tree', refs))
127
return self.tree_check(refs)
129
def branch_callback(self, refs):
130
self.callbacks.append(('branch', refs))
131
return self.branch_check(refs)
134
class TestCleanRepository(TestCaseWithRepository):
136
def test_new_repo(self):
137
repo = self.make_repository('foo')
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)