~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_uncommit.py

  • Committer: Patch Queue Manager
  • Date: 2016-04-21 04:10:52 UTC
  • mfrom: (6616.1.1 fix-en-user-guide)
  • Revision ID: pqm@pqm.ubuntu.com-20160421041052-clcye7ns1qcl2n7w
(richard-wilbur) Ensure build of English use guide always uses English text
 even when user's locale specifies a different language. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 2013, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
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
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Test the uncommit command."""
18
18
 
19
19
import os
20
20
 
21
 
from bzrlib import uncommit, workingtree
 
21
from bzrlib import uncommit
22
22
from bzrlib.bzrdir import BzrDirMetaFormat1
23
 
from bzrlib.errors import BzrError, BoundBranchOutOfDate
 
23
from bzrlib.errors import BoundBranchOutOfDate
24
24
from bzrlib.tests import TestCaseWithTransport
 
25
from bzrlib.tests.matchers import ContainsNoVfsCalls
 
26
from bzrlib.tests.script import (
 
27
    run_script,
 
28
    ScriptRunner,
 
29
    )
25
30
 
26
31
 
27
32
class TestUncommit(TestCaseWithTransport):
32
37
        wt.add(['a', 'b', 'c'])
33
38
        wt.commit('initial commit', rev_id='a1')
34
39
 
35
 
        open('tree/a', 'wb').write('new contents of a\n')
 
40
        self.build_tree_contents([('tree/a', 'new contents of a\n')])
36
41
        wt.commit('second commit', rev_id='a2')
37
42
 
38
43
        return wt
58
63
        # This should look like we are back in revno 1
59
64
        self.assertEqual(['a1'], wt.get_parent_ids())
60
65
        out, err = self.run_bzr('status')
61
 
        self.assertEquals(out, 'modified:\n  a\n')
 
66
        self.assertEqual(out, 'modified:\n  a\n')
 
67
 
 
68
    def test_uncommit_interactive(self):
 
69
        """Uncommit seeks confirmation, and doesn't proceed without it."""
 
70
        wt = self.create_simple_tree()
 
71
        os.chdir('tree')
 
72
        run_script(self, """    
 
73
        $ bzr uncommit
 
74
        ...
 
75
        The above revision(s) will be removed.
 
76
        2>Uncommit these revisions? ([y]es, [n]o): no
 
77
        <n
 
78
        Canceled
 
79
        """)
 
80
        self.assertEqual(['a2'], wt.get_parent_ids())
62
81
 
63
82
    def test_uncommit_no_history(self):
64
83
        wt = self.make_branch_and_tree('tree')
86
105
 
87
106
        # uncommit in a checkout should uncommit the parent branch
88
107
        # (but doesn't effect the other working tree)
89
 
        self.assertEquals(['a1'], checkout_tree.get_parent_ids())
90
 
        self.assertEquals('a1', wt.branch.last_revision())
91
 
        self.assertEquals(['a2'], wt.get_parent_ids())
 
108
        self.assertEqual(['a1'], checkout_tree.get_parent_ids())
 
109
        self.assertEqual('a1', wt.branch.last_revision())
 
110
        self.assertEqual(['a2'], wt.get_parent_ids())
92
111
 
93
112
    def test_uncommit_bound(self):
94
113
        os.mkdir('a')
101
120
        t_a.commit('commit 3')
102
121
        b = t_a.branch.create_checkout('b').branch
103
122
        uncommit.uncommit(b)
104
 
        self.assertEqual(len(b.revision_history()), 2)
105
 
        self.assertEqual(len(t_a.branch.revision_history()), 2)
106
 
        # update A's tree to not have the uncomitted revision referenced.
 
123
        self.assertEqual(b.last_revision_info()[0], 2)
 
124
        self.assertEqual(t_a.branch.last_revision_info()[0], 2)
 
125
        # update A's tree to not have the uncommitted revision referenced.
107
126
        t_a.update()
108
127
        t_a.commit('commit 3b')
109
128
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
110
129
        b.pull(t_a.branch)
111
130
        uncommit.uncommit(b)
112
131
 
 
132
    def test_uncommit_bound_local(self):
 
133
        t_a = self.make_branch_and_tree('a')
 
134
        rev_id1 = t_a.commit('commit 1')
 
135
        rev_id2 = t_a.commit('commit 2')
 
136
        rev_id3 = t_a.commit('commit 3')
 
137
        b = t_a.branch.create_checkout('b').branch
 
138
 
 
139
        out, err = self.run_bzr(['uncommit', '--local', 'b', '--force'])
 
140
        self.assertEqual(rev_id3, t_a.last_revision())
 
141
        self.assertEqual((3, rev_id3), t_a.branch.last_revision_info())
 
142
        self.assertEqual((2, rev_id2), b.last_revision_info())
 
143
 
113
144
    def test_uncommit_revision(self):
114
145
        wt = self.create_simple_tree()
115
146
 
161
192
        wt = self.create_simple_tree()
162
193
 
163
194
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
164
 
 
165
195
        tree2.commit('unchanged', rev_id='b3')
166
196
 
 
197
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
198
        tree3.commit('unchanged', rev_id='c3')
 
199
 
167
200
        wt.merge_from_branch(tree2.branch)
168
201
        wt.commit('merge b3', rev_id='a3')
169
202
 
170
 
        tree2.commit('unchanged', rev_id='b4')
171
 
 
172
 
        wt.merge_from_branch(tree2.branch)
173
 
        wt.commit('merge b4', rev_id='a4')
 
203
        wt.merge_from_branch(tree3.branch)
 
204
        wt.commit('merge c3', rev_id='a4')
174
205
 
175
206
        self.assertEqual(['a4'], wt.get_parent_ids())
176
207
 
177
208
        os.chdir('tree')
178
209
        out, err = self.run_bzr('uncommit --force -r 2')
179
210
 
180
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
211
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
181
212
 
182
213
    def test_uncommit_merge_plus_pending(self):
183
214
        wt = self.create_simple_tree()
184
215
 
185
216
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
186
 
 
187
217
        tree2.commit('unchanged', rev_id='b3')
 
218
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
219
        tree3.commit('unchanged', rev_id='c3')
 
220
 
188
221
        wt.branch.fetch(tree2.branch)
189
222
        wt.set_pending_merges(['b3'])
190
223
        wt.commit('merge b3', rev_id='a3')
191
224
 
192
 
        tree2.commit('unchanged', rev_id='b4')
193
 
        wt.branch.fetch(tree2.branch)
194
 
        wt.set_pending_merges(['b4'])
195
 
 
196
 
        self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
 
225
 
 
226
        wt.merge_from_branch(tree3.branch)
 
227
 
 
228
        self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
197
229
 
198
230
        os.chdir('tree')
199
231
        out, err = self.run_bzr('uncommit --force -r 2')
200
232
 
201
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
233
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
 
234
 
 
235
    def test_uncommit_shows_log_with_revision_id(self):
 
236
        wt = self.create_simple_tree()
 
237
 
 
238
        script = ScriptRunner()
 
239
        script.run_script(self, """
 
240
$ cd tree
 
241
$ bzr uncommit --force 
 
242
    2 ...
 
243
      second commit
 
244
...
 
245
The above revision(s) will be removed.
 
246
You can restore the old tip by running:
 
247
  bzr pull . -r revid:a2
 
248
""")
202
249
 
203
250
    def test_uncommit_octopus_merge(self):
204
251
        # Check that uncommit keeps the pending merges in the same order
 
252
        # though it will also filter out ones in the ancestry
205
253
        wt = self.create_simple_tree()
206
254
 
207
255
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
209
257
 
210
258
        tree2.commit('unchanged', rev_id='b3')
211
259
        tree3.commit('unchanged', rev_id='c3')
212
 
        
 
260
 
213
261
        wt.merge_from_branch(tree2.branch)
214
 
        wt.merge_from_branch(tree3.branch)
 
262
        wt.merge_from_branch(tree3.branch, force=True)
215
263
        wt.commit('merge b3, c3', rev_id='a3')
216
264
 
217
265
        tree2.commit('unchanged', rev_id='b4')
218
266
        tree3.commit('unchanged', rev_id='c4')
219
267
 
220
268
        wt.merge_from_branch(tree3.branch)
221
 
        wt.merge_from_branch(tree2.branch)
 
269
        wt.merge_from_branch(tree2.branch, force=True)
222
270
        wt.commit('merge b4, c4', rev_id='a4')
223
271
 
224
272
        self.assertEqual(['a4'], wt.get_parent_ids())
226
274
        os.chdir('tree')
227
275
        out, err = self.run_bzr('uncommit --force -r 2')
228
276
 
229
 
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())
 
277
        self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
230
278
 
231
279
    def test_uncommit_nonascii(self):
232
280
        tree = self.make_branch_and_tree('tree')
233
281
        tree.commit(u'\u1234 message')
234
282
        out, err = self.run_bzr('uncommit --force tree', encoding='ascii')
235
283
        self.assertContainsRe(out, r'\? message')
 
284
 
 
285
    def test_uncommit_removes_tags(self):
 
286
        tree = self.make_branch_and_tree('tree')
 
287
        revid = tree.commit('message')
 
288
        tree.branch.tags.set_tag("atag", revid)
 
289
        out, err = self.run_bzr('uncommit --force tree')
 
290
        self.assertEqual({}, tree.branch.tags.get_tag_dict())
 
291
 
 
292
    def test_uncommit_keep_tags(self):
 
293
        tree = self.make_branch_and_tree('tree')
 
294
        revid = tree.commit('message')
 
295
        tree.branch.tags.set_tag("atag", revid)
 
296
        out, err = self.run_bzr('uncommit --keep-tags --force tree')
 
297
        self.assertEqual({"atag": revid}, tree.branch.tags.get_tag_dict())
 
298
 
 
299
 
 
300
class TestSmartServerUncommit(TestCaseWithTransport):
 
301
 
 
302
    def test_uncommit(self):
 
303
        self.setup_smart_server_with_call_log()
 
304
        t = self.make_branch_and_tree('from')
 
305
        for count in range(2):
 
306
            t.commit(message='commit %d' % count)
 
307
        self.reset_smart_call_log()
 
308
        out, err = self.run_bzr(['uncommit', '--force', self.get_url('from')])
 
309
        # This figure represent the amount of work to perform this use case. It
 
310
        # is entirely ok to reduce this number if a test fails due to rpc_count
 
311
        # being too low. If rpc_count increases, more network roundtrips have
 
312
        # become necessary for this use case. Please do not adjust this number
 
313
        # upwards without agreement from bzr's network support maintainers.
 
314
        self.assertLength(14, self.hpss_calls)
 
315
        self.assertLength(1, self.hpss_connections)
 
316
        self.assertThat(self.hpss_calls, ContainsNoVfsCalls)
 
317
 
 
318
 
 
319
class TestInconsistentDelta(TestCaseWithTransport):
 
320
    # See https://bugs.launchpad.net/bzr/+bug/855155
 
321
    # See https://bugs.launchpad.net/bzr/+bug/1100385
 
322
    # bzr uncommit may result in error
 
323
    # 'An inconsistent delta was supplied involving'
 
324
 
 
325
    def test_inconsistent_delta(self):
 
326
        # Script taken from https://bugs.launchpad.net/bzr/+bug/855155/comments/26
 
327
        wt = self.make_branch_and_tree('test')
 
328
        self.build_tree(['test/a/', 'test/a/b', 'test/a/c'])
 
329
        wt.add(['a', 'a/b', 'a/c'])
 
330
        wt.commit('initial commit', rev_id='a1')
 
331
        wt.remove(['a/b', 'a/c'])
 
332
        wt.commit('remove b and c', rev_id='a2')
 
333
        self.run_bzr("uncommit --force test")