/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2008, 2009, 2011, 2016 Canonical Ltd
3280.4.1 by John Arbash Meinel
Add uncommit --local.
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
3280.4.1 by John Arbash Meinel
Add uncommit --local.
16
17
"""Test uncommit."""
18
19
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
20
from .. import (
3280.4.1 by John Arbash Meinel
Add uncommit --local.
21
    errors,
22
    tests,
23
    uncommit,
24
    )
25
26
27
class TestUncommit(tests.TestCaseWithTransport):
28
29
    def make_linear_tree(self):
30
        tree = self.make_branch_and_tree('tree')
31
        tree.lock_write()
32
        try:
33
            self.build_tree(['tree/one'])
34
            tree.add('one')
35
            rev_id1 = tree.commit('one')
36
            self.build_tree(['tree/two'])
37
            tree.add('two')
38
            rev_id2 = tree.commit('two')
39
        finally:
40
            tree.unlock()
41
        return tree, [rev_id1, rev_id2]
42
43
    def test_uncommit(self):
44
        tree, history = self.make_linear_tree()
45
        self.assertEqual(history[1], tree.last_revision())
46
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
47
        uncommit.uncommit(tree.branch, tree=tree)
48
        self.assertEqual(history[0], tree.last_revision())
49
        self.assertEqual((1, history[0]), tree.branch.last_revision_info())
50
51
        # The file should not be removed
5784.1.3 by Martin Pool
Switch away from using failUnlessExists and failIfExists
52
        self.assertPathExists('tree/two')
3280.4.1 by John Arbash Meinel
Add uncommit --local.
53
        # And it should still be listed as added
6852.3.1 by Jelmer Vernooij
add Tree.is_versioned.
54
        self.assertTrue(tree.is_versioned('two'))
3280.4.1 by John Arbash Meinel
Add uncommit --local.
55
56
    def test_uncommit_bound(self):
57
        tree, history = self.make_linear_tree()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
58
        child = tree.controldir.sprout('child').open_workingtree()
3280.4.1 by John Arbash Meinel
Add uncommit --local.
59
        child.branch.bind(tree.branch)
60
61
        self.assertEqual(history[1], tree.last_revision())
62
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
63
        self.assertEqual(history[1], child.last_revision())
64
        self.assertEqual((2, history[1]), child.branch.last_revision_info())
65
66
        # Uncommit in a bound branch should uncommit the master branch, but not
67
        # touch the other working tree.
68
        uncommit.uncommit(child.branch, tree=child)
69
70
        self.assertEqual(history[1], tree.last_revision())
71
        self.assertEqual((1, history[0]), tree.branch.last_revision_info())
72
        self.assertEqual(history[0], child.last_revision())
73
        self.assertEqual((1, history[0]), child.branch.last_revision_info())
74
75
    def test_uncommit_bound_local(self):
76
        tree, history = self.make_linear_tree()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
77
        child = tree.controldir.sprout('child').open_workingtree()
3280.4.1 by John Arbash Meinel
Add uncommit --local.
78
        child.branch.bind(tree.branch)
79
80
        self.assertEqual(history[1], tree.last_revision())
81
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
82
        self.assertEqual(history[1], child.last_revision())
83
        self.assertEqual((2, history[1]), child.branch.last_revision_info())
84
85
        # Uncommit local=True should only affect the local branch
86
        uncommit.uncommit(child.branch, tree=child, local=True)
87
88
        self.assertEqual(history[1], tree.last_revision())
89
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
90
        self.assertEqual(history[0], child.last_revision())
91
        self.assertEqual((1, history[0]), child.branch.last_revision_info())
3280.4.4 by John Arbash Meinel
uncommit --local in an unbound branch raises the same exception as commit --local
92
93
    def test_uncommit_unbound_local(self):
94
        tree, history = self.make_linear_tree()
95
96
        # If this tree isn't bound, local=True raises an exception
97
        self.assertRaises(errors.LocalRequiresBoundBranch,
7143.15.5 by Jelmer Vernooij
More PEP8 fixes.
98
                          uncommit.uncommit, tree.branch, tree=tree,
99
                          local=True)
6091.1.3 by Jelmer Vernooij
Add tests.
100
101
    def test_uncommit_remove_tags(self):
102
        tree, history = self.make_linear_tree()
103
        self.assertEqual(history[1], tree.last_revision())
104
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
105
        tree.branch.tags.set_tag(u"pointsatexisting", history[0])
106
        tree.branch.tags.set_tag(u"pointsatremoved", history[1])
107
        uncommit.uncommit(tree.branch, tree=tree)
108
        self.assertEqual(history[0], tree.last_revision())
109
        self.assertEqual((1, history[0]), tree.branch.last_revision_info())
110
        self.assertEqual({
111
            "pointsatexisting": history[0]
6091.1.4 by Jelmer Vernooij
More tests.
112
            }, tree.branch.tags.get_tag_dict())
6091.1.3 by Jelmer Vernooij
Add tests.
113
6379.12.1 by Jelmer Vernooij
Uncommit no longer removes tags if they are part of the working trees pending merges.
114
    def test_uncommit_remove_tags_keeps_pending_merges(self):
115
        tree, history = self.make_linear_tree()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
116
        copy = tree.controldir.sprout('copyoftree').open_workingtree()
6855.4.1 by Jelmer Vernooij
Yet more bees.
117
        copy.commit(message='merged', rev_id=b'merged')
6379.12.1 by Jelmer Vernooij
Uncommit no longer removes tags if they are part of the working trees pending merges.
118
        tree.merge_from_branch(copy.branch)
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
119
        tree.branch.tags.set_tag('pointsatmerged', b'merged')
6379.12.1 by Jelmer Vernooij
Uncommit no longer removes tags if they are part of the working trees pending merges.
120
        history.append(tree.commit('merge'))
7143.15.2 by Jelmer Vernooij
Run autopep8.
121
        self.assertEqual(
122
            b'merged', tree.branch.tags.lookup_tag('pointsatmerged'))
6379.12.1 by Jelmer Vernooij
Uncommit no longer removes tags if they are part of the working trees pending merges.
123
        self.assertEqual(history[2], tree.last_revision())
124
        self.assertEqual((3, history[2]), tree.branch.last_revision_info())
125
        tree.branch.tags.set_tag(u"pointsatexisting", history[1])
126
        tree.branch.tags.set_tag(u"pointsatremoved", history[2])
127
        uncommit.uncommit(tree.branch, tree=tree)
128
        self.assertEqual(history[1], tree.last_revision())
129
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
130
        self.assertEqual([history[1], b'merged'], tree.get_parent_ids())
6379.12.1 by Jelmer Vernooij
Uncommit no longer removes tags if they are part of the working trees pending merges.
131
        self.assertEqual({
132
            "pointsatexisting": history[1],
7029.4.2 by Jelmer Vernooij
Fix more merge tests.
133
            "pointsatmerged": b'merged',
6379.12.1 by Jelmer Vernooij
Uncommit no longer removes tags if they are part of the working trees pending merges.
134
            }, tree.branch.tags.get_tag_dict())
135
6091.1.3 by Jelmer Vernooij
Add tests.
136
    def test_uncommit_keep_tags(self):
137
        tree, history = self.make_linear_tree()
138
        self.assertEqual(history[1], tree.last_revision())
139
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
140
        tree.branch.tags.set_tag(u"pointsatexisting", history[0])
141
        tree.branch.tags.set_tag(u"pointsatremoved", history[1])
142
        uncommit.uncommit(tree.branch, tree=tree, keep_tags=True)
143
        self.assertEqual(history[0], tree.last_revision())
144
        self.assertEqual((1, history[0]), tree.branch.last_revision_info())
145
        self.assertEqual({
146
            "pointsatexisting": history[0],
147
            "pointsatremoved": history[1],
6091.1.4 by Jelmer Vernooij
More tests.
148
            }, tree.branch.tags.get_tag_dict())