~bzr-pqm/bzr/bzr.dev

3389.2.5 by John Arbash Meinel
Fix the line endings on test_check and test_reconcile
1
# Copyright (C) 2008 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
3389.2.5 by John Arbash Meinel
Fix the line endings on test_check and test_reconcile
16
17
"""Tests for branch implementations - test reconcile() functionality"""
18
19
from bzrlib import errors, reconcile
6217.3.4 by Jelmer Vernooij
Skip bzr-specific test against other formats.
20
from bzrlib.branch import BzrBranch
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
21
from bzrlib.symbol_versioning import deprecated_in
4523.1.1 by Martin Pool
Rename tests.branch_implementations to per_branch
22
from bzrlib.tests.per_branch import TestCaseWithBranch
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
23
from bzrlib.tests import TestNotApplicable
3389.2.5 by John Arbash Meinel
Fix the line endings on test_check and test_reconcile
24
25
26
class TestBranchReconcile(TestCaseWithBranch):
27
28
    def test_reconcile_fixes_invalid_revhistory(self):
6217.3.4 by Jelmer Vernooij
Skip bzr-specific test against other formats.
29
        if not isinstance(self.branch_format, BzrBranch):
30
            raise TestNotApplicable("test only applies to bzr formats")
3389.2.5 by John Arbash Meinel
Fix the line endings on test_check and test_reconcile
31
        # Different formats have different ways of handling invalid revision
32
        # histories, so the setup portion is customized
33
        tree = self.make_branch_and_tree('test')
34
        r1 = tree.commit('one')
35
        r2 = tree.commit('two')
36
        r3 = tree.commit('three')
37
        r4 = tree.commit('four')
38
        # create an alternate branch
39
        tree.set_parent_ids([r1])
40
        tree.branch.set_last_revision_info(1, r1)
41
        r2b = tree.commit('two-b')
42
43
        # now go back and merge the commit
44
        tree.set_parent_ids([r4, r2b])
45
        tree.branch.set_last_revision_info(4, r4)
46
47
        r5 = tree.commit('five')
48
        # Now, try to set an invalid history
49
        try:
5718.7.4 by Jelmer Vernooij
Branch.set_revision_history.
50
            self.applyDeprecated(deprecated_in((2, 4, 0)),
51
                tree.branch.set_revision_history, [r1, r2b, r5])
3489.2.4 by Andrew Bennetts
Fix all tests broken by fixing make_branch_and_tree.
52
            if tree.branch.last_revision_info() != (3, r5):
53
                # RemoteBranch silently corrects an impossible revision
54
                # history given to set_revision_history.  It can be tricked
55
                # with set_last_revision_info though.
56
                tree.branch.set_last_revision_info(3, r5)
3389.2.5 by John Arbash Meinel
Fix the line endings on test_check and test_reconcile
57
        except errors.NotLefthandHistory:
58
            # Branch5 allows set_revision_history to be wrong
59
            # Branch6 raises NotLefthandHistory, but we can force bogus stuff
60
            # with set_last_revision_info
61
            tree.branch.set_last_revision_info(3, r5)
62
63
        self.assertEqual((3, r5), tree.branch.last_revision_info())
64
        reconciler = tree.branch.reconcile()
65
        self.assertEqual((5, r5), tree.branch.last_revision_info())
66
        self.assertIs(True, reconciler.fixed_history)
67
68
    def test_reconcile_returns_reconciler(self):
69
        a_branch = self.make_branch('a_branch')
70
        result = a_branch.reconcile()
71
        self.assertIsInstance(result, reconcile.BranchReconciler)
72
        # No history to fix
73
        self.assertIs(False, result.fixed_history)
74
75
    def test_reconcile_supports_thorough(self):
76
        a_branch = self.make_branch('a_branch')
77
        a_branch.reconcile(thorough=False)
78
        a_branch.reconcile(thorough=True)
4266.3.11 by Jelmer Vernooij
Support reconcile on branches with ghosts in their mainline.
79
80
    def test_reconcile_handles_ghosts_in_revhistory(self):
81
        tree = self.make_branch_and_tree('test')
6164.2.1 by Jelmer Vernooij
Skip tests if the repository doesn't support ghosts.
82
        if not tree.branch.repository._format.supports_ghosts:
83
            raise TestNotApplicable("repository format does not support ghosts")
4266.3.11 by Jelmer Vernooij
Support reconcile on branches with ghosts in their mainline.
84
        tree.set_parent_ids(["spooky"], allow_leftmost_as_ghost=True)
85
        r1 = tree.commit('one')
86
        r2 = tree.commit('two')
87
        tree.branch.set_last_revision_info(2, r2)
88
89
        reconciler = tree.branch.reconcile()
6165.4.6 by Jelmer Vernooij
Avoid more uses of revision_history.
90
        self.assertEquals(r2, tree.branch.last_revision())