1
# Copyright (C) 2008 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 branch implementations - test check() functionality"""
19
from bzrlib import errors
20
from bzrlib.tests.branch_implementations import TestCaseWithBranch
23
class TestBranchCheck(TestCaseWithBranch):
25
def test_check_detects_invalid_revhistory(self):
26
# Different formats have different ways of handling invalid revision
27
# histories, so the setup portion is customized
28
tree = self.make_branch_and_tree('test')
29
r1 = tree.commit('one')
30
r2 = tree.commit('two')
31
r3 = tree.commit('three')
32
r4 = tree.commit('four')
33
# create an alternate branch
34
tree.set_parent_ids([r1])
35
tree.branch.set_last_revision_info(1, r1)
36
r2b = tree.commit('two-b')
38
# now go back and merge the commit
39
tree.set_parent_ids([r4, r2b])
40
tree.branch.set_last_revision_info(4, r4)
42
r5 = tree.commit('five')
43
# Now, try to set an invalid history
45
tree.branch.set_revision_history([r1, r2b, r5])
46
if tree.branch.last_revision_info() != (3, r5):
47
# RemoteBranch silently corrects an impossible revision
48
# history given to set_revision_history. It can be tricked
49
# with set_last_revision_info though.
50
tree.branch.set_last_revision_info(3, r5)
51
except errors.NotLefthandHistory:
52
# Branch5 allows set_revision_history to be wrong
53
# Branch6 raises NotLefthandHistory, but we can force bogus stuff
54
# with set_last_revision_info
55
tree.branch.set_last_revision_info(3, r5)
57
e = self.assertRaises(errors.BzrCheckError,
59
self.assertEqual('Internal check failed:'
60
' revno does not match len(mainline) 3 != 5', str(e))
62
def test_check_branch_report_results(self):
63
"""Checking a branch produces results which can be printed"""
64
branch = self.make_branch('.')
65
result = branch.check()
66
# reports results through logging
67
result.report_results(verbose=True)
68
result.report_results(verbose=False)