/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_uncommit.py

  • Committer: Vincent Ladeuil
  • Date: 2012-01-18 14:09:19 UTC
  • mto: This revision was merged to the branch mainline in revision 6468.
  • Revision ID: v.ladeuil+lp@free.fr-20120118140919-rlvdrhpc0nq1lbwi
Change set/remove to require a lock for the branch config files.

This means that tests (or any plugin for that matter) do not requires an
explicit lock on the branch anymore to change a single option. This also
means the optimisation becomes "opt-in" and as such won't be as
spectacular as it may be and/or harder to get right (nothing fails
anymore).

This reduces the diff by ~300 lines.

Code/tests that were updating more than one config option is still taking
a lock to at least avoid some IOs and demonstrate the benefits through
the decreased number of hpss calls.

The duplication between BranchStack and BranchOnlyStack will be removed
once the same sharing is in place for local config files, at which point
the Stack class itself may be able to host the changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""Test uncommit."""
 
18
 
 
19
 
 
20
from bzrlib import (
 
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
 
52
        self.assertPathExists('tree/two')
 
53
        # And it should still be listed as added
 
54
        self.assertIsNot(None, tree.path2id('two'))
 
55
 
 
56
    def test_uncommit_bound(self):
 
57
        tree, history = self.make_linear_tree()
 
58
        child = tree.bzrdir.sprout('child').open_workingtree()
 
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()
 
77
        child = tree.bzrdir.sprout('child').open_workingtree()
 
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())
 
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,
 
98
            uncommit.uncommit, tree.branch, tree=tree, local=True)
 
99
 
 
100
    def test_uncommit_remove_tags(self):
 
101
        tree, history = self.make_linear_tree()
 
102
        self.assertEqual(history[1], tree.last_revision())
 
103
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
 
104
        tree.branch.tags.set_tag(u"pointsatexisting", history[0])
 
105
        tree.branch.tags.set_tag(u"pointsatremoved", history[1])
 
106
        uncommit.uncommit(tree.branch, tree=tree)
 
107
        self.assertEqual(history[0], tree.last_revision())
 
108
        self.assertEqual((1, history[0]), tree.branch.last_revision_info())
 
109
        self.assertEqual({
 
110
            "pointsatexisting": history[0]
 
111
            }, tree.branch.tags.get_tag_dict())
 
112
 
 
113
    def test_uncommit_remove_tags_keeps_pending_merges(self):
 
114
        tree, history = self.make_linear_tree()
 
115
        copy = tree.bzrdir.sprout('copyoftree').open_workingtree()
 
116
        copy.commit(message='merged', rev_id='merged')
 
117
        tree.merge_from_branch(copy.branch)
 
118
        tree.branch.tags.set_tag('pointsatmerged', 'merged')
 
119
        history.append(tree.commit('merge'))
 
120
        self.assertEquals('merged', tree.branch.tags.lookup_tag('pointsatmerged'))
 
121
        self.assertEqual(history[2], tree.last_revision())
 
122
        self.assertEqual((3, history[2]), tree.branch.last_revision_info())
 
123
        tree.branch.tags.set_tag(u"pointsatexisting", history[1])
 
124
        tree.branch.tags.set_tag(u"pointsatremoved", history[2])
 
125
        uncommit.uncommit(tree.branch, tree=tree)
 
126
        self.assertEqual(history[1], tree.last_revision())
 
127
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
 
128
        self.assertEquals([history[1], 'merged'], tree.get_parent_ids())
 
129
        self.assertEqual({
 
130
            "pointsatexisting": history[1],
 
131
            "pointsatmerged": 'merged',
 
132
            }, tree.branch.tags.get_tag_dict())
 
133
 
 
134
    def test_uncommit_keep_tags(self):
 
135
        tree, history = self.make_linear_tree()
 
136
        self.assertEqual(history[1], tree.last_revision())
 
137
        self.assertEqual((2, history[1]), tree.branch.last_revision_info())
 
138
        tree.branch.tags.set_tag(u"pointsatexisting", history[0])
 
139
        tree.branch.tags.set_tag(u"pointsatremoved", history[1])
 
140
        uncommit.uncommit(tree.branch, tree=tree, keep_tags=True)
 
141
        self.assertEqual(history[0], tree.last_revision())
 
142
        self.assertEqual((1, history[0]), tree.branch.last_revision_info())
 
143
        self.assertEqual({
 
144
            "pointsatexisting": history[0],
 
145
            "pointsatremoved": history[1],
 
146
            }, tree.branch.tags.get_tag_dict())