/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2005, 2006 Canonical Ltd
1850.3.4 by John Arbash Meinel
Add copyright to test_uncommit.py
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""Test the uncommit command."""
1558.1.12 by Aaron Bentley
Got uncommit working properly with checkouts
18
19
import os
20
3101.1.1 by Aaron Bentley
Uncommit doesn't throw when it encounters un-encodable characters
21
import bzrlib
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
22
from bzrlib import uncommit, workingtree
1558.9.1 by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking
23
from bzrlib.bzrdir import BzrDirMetaFormat1
24
from bzrlib.errors import BzrError, BoundBranchOutOfDate
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
25
from bzrlib.tests import TestCaseWithTransport
26
27
28
class TestUncommit(TestCaseWithTransport):
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
29
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
30
    def create_simple_tree(self):
31
        wt = self.make_branch_and_tree('tree')
32
        self.build_tree(['tree/a', 'tree/b', 'tree/c'])
33
        wt.add(['a', 'b', 'c'])
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
34
        wt.commit('initial commit', rev_id='a1')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
35
36
        open('tree/a', 'wb').write('new contents of a\n')
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
37
        wt.commit('second commit', rev_id='a2')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
38
39
        return wt
40
0.3.11 by John Arbash Meinel
Updated to latest bzr.dev code, and added tests.
41
    def test_uncommit(self):
42
        """Test uncommit functionality."""
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
43
        wt = self.create_simple_tree()
44
45
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
46
        out, err = self.run_bzr('uncommit --dry-run --force')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
47
        self.assertContainsRe(out, 'Dry-run')
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
48
        self.assertNotContainsRe(out, 'initial commit')
49
        self.assertContainsRe(out, 'second commit')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
50
51
        # Nothing has changed
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
52
        self.assertEqual(['a2'], wt.get_parent_ids())
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
53
54
        # Uncommit, don't prompt
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
55
        out, err = self.run_bzr('uncommit --force')
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
56
        self.assertNotContainsRe(out, 'initial commit')
57
        self.assertContainsRe(out, 'second commit')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
58
59
        # This should look like we are back in revno 1
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
60
        self.assertEqual(['a1'], wt.get_parent_ids())
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
61
        out, err = self.run_bzr('status')
62
        self.assertEquals(out, 'modified:\n  a\n')
63
2948.2.1 by John Arbash Meinel
Fix 'bzr uncommit' when there is no revision history.
64
    def test_uncommit_no_history(self):
65
        wt = self.make_branch_and_tree('tree')
66
        out, err = self.run_bzr('uncommit --force', retcode=1)
67
        self.assertEqual('', err)
68
        self.assertEqual('No revisions to uncommit.\n', out)
69
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
70
    def test_uncommit_checkout(self):
71
        wt = self.create_simple_tree()
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
72
        checkout_tree = wt.branch.create_checkout('checkout')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
73
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
74
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
75
76
        os.chdir('checkout')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
77
        out, err = self.run_bzr('uncommit --dry-run --force')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
78
        self.assertContainsRe(out, 'Dry-run')
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
79
        self.assertNotContainsRe(out, 'initial commit')
80
        self.assertContainsRe(out, 'second commit')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
81
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
82
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
83
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
84
        out, err = self.run_bzr('uncommit --force')
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
85
        self.assertNotContainsRe(out, 'initial commit')
86
        self.assertContainsRe(out, 'second commit')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
87
88
        # uncommit in a checkout should uncommit the parent branch
89
        # (but doesn't effect the other working tree)
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
90
        self.assertEquals(['a1'], checkout_tree.get_parent_ids())
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
91
        self.assertEquals('a1', wt.branch.last_revision())
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
92
        self.assertEquals(['a2'], wt.get_parent_ids())
1558.9.1 by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking
93
94
    def test_uncommit_bound(self):
95
        os.mkdir('a')
96
        a = BzrDirMetaFormat1().initialize('a')
97
        a.create_repository()
98
        a.create_branch()
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
99
        t_a = a.create_workingtree()
100
        t_a.commit('commit 1')
101
        t_a.commit('commit 2')
102
        t_a.commit('commit 3')
1997.1.5 by Robert Collins
``Branch.bind(other_branch)`` no longer takes a write lock on the
103
        b = t_a.branch.create_checkout('b').branch
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
104
        uncommit.uncommit(b)
1558.9.1 by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking
105
        self.assertEqual(len(b.revision_history()), 2)
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
106
        self.assertEqual(len(t_a.branch.revision_history()), 2)
107
        # update A's tree to not have the uncomitted revision referenced.
108
        t_a.update()
109
        t_a.commit('commit 3b')
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
110
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
111
        b.pull(t_a.branch)
1850.3.1 by John Arbash Meinel
cleanup the uncommit tests
112
        uncommit.uncommit(b)
1558.9.1 by Aaron Bentley
Fix uncommit to handle bound branches, and to do locking
113
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
114
    def test_uncommit_revision(self):
115
        wt = self.create_simple_tree()
116
117
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
118
        out, err = self.run_bzr('uncommit -r1 --force')
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
119
120
        self.assertNotContainsRe(out, 'initial commit')
121
        self.assertContainsRe(out, 'second commit')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
122
        self.assertEqual(['a1'], wt.get_parent_ids())
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
123
        self.assertEqual('a1', wt.branch.last_revision())
124
125
    def test_uncommit_neg_1(self):
126
        wt = self.create_simple_tree()
127
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
128
        out, err = self.run_bzr('uncommit -r -1', retcode=1)
1850.3.2 by John Arbash Meinel
Change uncommit -r 10 so that it uncommits *to* 10, rather than removing 10
129
        self.assertEqual('No revisions to uncommit.\n', out)
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
130
131
    def test_uncommit_merges(self):
132
        wt = self.create_simple_tree()
133
134
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
135
136
        tree2.commit('unchanged', rev_id='b3')
137
        tree2.commit('unchanged', rev_id='b4')
138
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
139
        wt.merge_from_branch(tree2.branch)
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
140
        wt.commit('merge b4', rev_id='a3')
141
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
142
        self.assertEqual(['a3'], wt.get_parent_ids())
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
143
144
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
145
        out, err = self.run_bzr('uncommit --force')
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
146
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
147
        self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
148
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
149
    def test_uncommit_pending_merge(self):
150
        wt = self.create_simple_tree()
151
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
152
        tree2.commit('unchanged', rev_id='b3')
153
154
        wt.branch.fetch(tree2.branch)
155
        wt.set_pending_merges(['b3'])
156
157
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
158
        out, err = self.run_bzr('uncommit --force')
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
159
        self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
160
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
161
    def test_uncommit_multiple_merge(self):
162
        wt = self.create_simple_tree()
163
164
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
165
166
        tree2.commit('unchanged', rev_id='b3')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
167
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
168
        wt.merge_from_branch(tree2.branch)
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
169
        wt.commit('merge b3', rev_id='a3')
170
171
        tree2.commit('unchanged', rev_id='b4')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
172
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
173
        wt.merge_from_branch(tree2.branch)
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
174
        wt.commit('merge b4', rev_id='a4')
175
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
176
        self.assertEqual(['a4'], wt.get_parent_ids())
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
177
178
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
179
        out, err = self.run_bzr('uncommit --force -r 2')
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
180
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
181
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
182
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
183
    def test_uncommit_merge_plus_pending(self):
184
        wt = self.create_simple_tree()
185
186
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
187
188
        tree2.commit('unchanged', rev_id='b3')
189
        wt.branch.fetch(tree2.branch)
190
        wt.set_pending_merges(['b3'])
191
        wt.commit('merge b3', rev_id='a3')
192
193
        tree2.commit('unchanged', rev_id='b4')
194
        wt.branch.fetch(tree2.branch)
195
        wt.set_pending_merges(['b4'])
196
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
197
        self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
198
199
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
200
        out, err = self.run_bzr('uncommit --force -r 2')
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
201
1908.7.6 by Robert Collins
Deprecate WorkingTree.last_revision.
202
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
1956.1.1 by John Arbash Meinel
Fix bug #57660: 'bzr uncommit' should preserve pending merges
203
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
204
    def test_uncommit_octopus_merge(self):
205
        # Check that uncommit keeps the pending merges in the same order
206
        wt = self.create_simple_tree()
207
208
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
209
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
210
211
        tree2.commit('unchanged', rev_id='b3')
212
        tree3.commit('unchanged', rev_id='c3')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
213
        
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
214
        wt.merge_from_branch(tree2.branch)
215
        wt.merge_from_branch(tree3.branch)
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
216
        wt.commit('merge b3, c3', rev_id='a3')
217
218
        tree2.commit('unchanged', rev_id='b4')
219
        tree3.commit('unchanged', rev_id='c4')
1908.6.7 by Robert Collins
Remove all users of set_pending_merges and add_pending_merge except tests that they work correctly.
220
1979.2.1 by Robert Collins
(robertc) adds a convenience method "merge_from_branch" to WorkingTree.
221
        wt.merge_from_branch(tree3.branch)
222
        wt.merge_from_branch(tree2.branch)
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
223
        wt.commit('merge b4, c4', rev_id='a4')
224
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
225
        self.assertEqual(['a4'], wt.get_parent_ids())
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
226
227
        os.chdir('tree')
2552.2.3 by Vincent Ladeuil
Deprecate the varargs syntax and fix the tests.
228
        out, err = self.run_bzr('uncommit --force -r 2')
1850.3.5 by John Arbash Meinel
Fix bug 31426, have uncommit keep track of pending merges.
229
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
230
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())
3101.1.1 by Aaron Bentley
Uncommit doesn't throw when it encounters un-encodable characters
231
232
    def test_uncommit_nonascii(self):
233
        tree = self.make_branch_and_tree('tree')
234
        tree.commit(u'\u1234 message')
235
        real_encoding = bzrlib.user_encoding
236
        bzrlib.user_encoding = 'ascii'
237
        try:
238
            out, err = self.run_bzr('uncommit --force tree')
239
        finally:
240
            bzrlib.user_encoding = real_encoding
241
        self.assertContainsRe(out, r'\? message')