~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
 
22
22
from bzrlib.bzrdir import BzrDirMetaFormat1
23
23
from bzrlib.errors import BzrError, BoundBranchOutOfDate
24
24
from bzrlib.tests import TestCaseWithTransport
 
25
from bzrlib.tests.script import (
 
26
    run_script,
 
27
    ScriptRunner,
 
28
    )
25
29
 
26
30
 
27
31
class TestUncommit(TestCaseWithTransport):
32
36
        wt.add(['a', 'b', 'c'])
33
37
        wt.commit('initial commit', rev_id='a1')
34
38
 
35
 
        open('tree/a', 'wb').write('new contents of a\n')
 
39
        self.build_tree_contents([('tree/a', 'new contents of a\n')])
36
40
        wt.commit('second commit', rev_id='a2')
37
41
 
38
42
        return wt
60
64
        out, err = self.run_bzr('status')
61
65
        self.assertEquals(out, 'modified:\n  a\n')
62
66
 
 
67
    def test_uncommit_interactive(self):
 
68
        """Uncommit seeks confirmation, and doesn't proceed without it."""
 
69
        wt = self.create_simple_tree()
 
70
        os.chdir('tree')
 
71
        run_script(self, """    
 
72
        $ bzr uncommit
 
73
        ...
 
74
        The above revision(s) will be removed.
 
75
        2>Uncommit these revisions? [y/n]: 
 
76
        <n
 
77
        Canceled
 
78
        """)
 
79
        self.assertEqual(['a2'], wt.get_parent_ids())
 
80
 
 
81
    def test_uncommit_no_history(self):
 
82
        wt = self.make_branch_and_tree('tree')
 
83
        out, err = self.run_bzr('uncommit --force', retcode=1)
 
84
        self.assertEqual('', err)
 
85
        self.assertEqual('No revisions to uncommit.\n', out)
 
86
 
63
87
    def test_uncommit_checkout(self):
64
88
        wt = self.create_simple_tree()
65
89
        checkout_tree = wt.branch.create_checkout('checkout')
97
121
        uncommit.uncommit(b)
98
122
        self.assertEqual(len(b.revision_history()), 2)
99
123
        self.assertEqual(len(t_a.branch.revision_history()), 2)
100
 
        # update A's tree to not have the uncomitted revision referenced.
 
124
        # update A's tree to not have the uncommitted revision referenced.
101
125
        t_a.update()
102
126
        t_a.commit('commit 3b')
103
127
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
104
128
        b.pull(t_a.branch)
105
129
        uncommit.uncommit(b)
106
130
 
 
131
    def test_uncommit_bound_local(self):
 
132
        t_a = self.make_branch_and_tree('a')
 
133
        rev_id1 = t_a.commit('commit 1')
 
134
        rev_id2 = t_a.commit('commit 2')
 
135
        rev_id3 = t_a.commit('commit 3')
 
136
        b = t_a.branch.create_checkout('b').branch
 
137
 
 
138
        out, err = self.run_bzr(['uncommit', '--local', 'b', '--force'])
 
139
        self.assertEqual(rev_id3, t_a.last_revision())
 
140
        self.assertEqual((3, rev_id3), t_a.branch.last_revision_info())
 
141
        self.assertEqual((2, rev_id2), b.last_revision_info())
 
142
 
107
143
    def test_uncommit_revision(self):
108
144
        wt = self.create_simple_tree()
109
145
 
155
191
        wt = self.create_simple_tree()
156
192
 
157
193
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
158
 
 
159
194
        tree2.commit('unchanged', rev_id='b3')
160
195
 
 
196
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
197
        tree3.commit('unchanged', rev_id='c3')
 
198
 
161
199
        wt.merge_from_branch(tree2.branch)
162
200
        wt.commit('merge b3', rev_id='a3')
163
201
 
164
 
        tree2.commit('unchanged', rev_id='b4')
165
 
 
166
 
        wt.merge_from_branch(tree2.branch)
167
 
        wt.commit('merge b4', rev_id='a4')
 
202
        wt.merge_from_branch(tree3.branch)
 
203
        wt.commit('merge c3', rev_id='a4')
168
204
 
169
205
        self.assertEqual(['a4'], wt.get_parent_ids())
170
206
 
171
207
        os.chdir('tree')
172
208
        out, err = self.run_bzr('uncommit --force -r 2')
173
209
 
174
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
210
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
175
211
 
176
212
    def test_uncommit_merge_plus_pending(self):
177
213
        wt = self.create_simple_tree()
178
214
 
179
215
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
180
 
 
181
216
        tree2.commit('unchanged', rev_id='b3')
 
217
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
218
        tree3.commit('unchanged', rev_id='c3')
 
219
 
182
220
        wt.branch.fetch(tree2.branch)
183
221
        wt.set_pending_merges(['b3'])
184
222
        wt.commit('merge b3', rev_id='a3')
185
223
 
186
 
        tree2.commit('unchanged', rev_id='b4')
187
 
        wt.branch.fetch(tree2.branch)
188
 
        wt.set_pending_merges(['b4'])
189
 
 
190
 
        self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
 
224
 
 
225
        wt.merge_from_branch(tree3.branch)
 
226
 
 
227
        self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
191
228
 
192
229
        os.chdir('tree')
193
230
        out, err = self.run_bzr('uncommit --force -r 2')
194
231
 
195
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
232
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
 
233
 
 
234
    def test_uncommit_shows_log_with_revision_id(self):
 
235
        wt = self.create_simple_tree()
 
236
 
 
237
        script = ScriptRunner()
 
238
        script.run_script(self, """
 
239
$ cd tree
 
240
$ bzr uncommit --force 
 
241
    2 ...
 
242
      second commit
 
243
...
 
244
The above revision(s) will be removed.
 
245
You can restore the old tip by running:
 
246
  bzr pull . -r revid:a2
 
247
""")
196
248
 
197
249
    def test_uncommit_octopus_merge(self):
198
250
        # Check that uncommit keeps the pending merges in the same order
 
251
        # though it will also filter out ones in the ancestry
199
252
        wt = self.create_simple_tree()
200
253
 
201
254
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
203
256
 
204
257
        tree2.commit('unchanged', rev_id='b3')
205
258
        tree3.commit('unchanged', rev_id='c3')
206
 
        
 
259
 
207
260
        wt.merge_from_branch(tree2.branch)
208
 
        wt.merge_from_branch(tree3.branch)
 
261
        wt.merge_from_branch(tree3.branch, force=True)
209
262
        wt.commit('merge b3, c3', rev_id='a3')
210
263
 
211
264
        tree2.commit('unchanged', rev_id='b4')
212
265
        tree3.commit('unchanged', rev_id='c4')
213
266
 
214
267
        wt.merge_from_branch(tree3.branch)
215
 
        wt.merge_from_branch(tree2.branch)
 
268
        wt.merge_from_branch(tree2.branch, force=True)
216
269
        wt.commit('merge b4, c4', rev_id='a4')
217
270
 
218
271
        self.assertEqual(['a4'], wt.get_parent_ids())
220
273
        os.chdir('tree')
221
274
        out, err = self.run_bzr('uncommit --force -r 2')
222
275
 
223
 
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())
 
276
        self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
 
277
 
 
278
    def test_uncommit_nonascii(self):
 
279
        tree = self.make_branch_and_tree('tree')
 
280
        tree.commit(u'\u1234 message')
 
281
        out, err = self.run_bzr('uncommit --force tree', encoding='ascii')
 
282
        self.assertContainsRe(out, r'\? message')