~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Ian Clatworthy
  • Date: 2007-08-13 14:33:10 UTC
  • mto: (2733.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 2734.
  • Revision ID: ian.clatworthy@internode.on.net-20070813143310-twhj4la0qnupvze8
Added Quick Start Summary

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Test the uncommit command."""
18
18
 
19
19
import os
20
20
 
21
 
from bzrlib import uncommit
 
21
from bzrlib import uncommit, workingtree
22
22
from bzrlib.bzrdir import BzrDirMetaFormat1
23
 
from bzrlib.errors import BoundBranchOutOfDate
 
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
 
    )
29
25
 
30
26
 
31
27
class TestUncommit(TestCaseWithTransport):
36
32
        wt.add(['a', 'b', 'c'])
37
33
        wt.commit('initial commit', rev_id='a1')
38
34
 
39
 
        self.build_tree_contents([('tree/a', 'new contents of a\n')])
 
35
        open('tree/a', 'wb').write('new contents of a\n')
40
36
        wt.commit('second commit', rev_id='a2')
41
37
 
42
38
        return wt
64
60
        out, err = self.run_bzr('status')
65
61
        self.assertEquals(out, 'modified:\n  a\n')
66
62
 
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
 
 
87
63
    def test_uncommit_checkout(self):
88
64
        wt = self.create_simple_tree()
89
65
        checkout_tree = wt.branch.create_checkout('checkout')
121
97
        uncommit.uncommit(b)
122
98
        self.assertEqual(len(b.revision_history()), 2)
123
99
        self.assertEqual(len(t_a.branch.revision_history()), 2)
124
 
        # update A's tree to not have the uncommitted revision referenced.
 
100
        # update A's tree to not have the uncomitted revision referenced.
125
101
        t_a.update()
126
102
        t_a.commit('commit 3b')
127
103
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
128
104
        b.pull(t_a.branch)
129
105
        uncommit.uncommit(b)
130
106
 
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
 
 
143
107
    def test_uncommit_revision(self):
144
108
        wt = self.create_simple_tree()
145
109
 
191
155
        wt = self.create_simple_tree()
192
156
 
193
157
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
 
158
 
194
159
        tree2.commit('unchanged', rev_id='b3')
195
160
 
196
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
197
 
        tree3.commit('unchanged', rev_id='c3')
198
 
 
199
161
        wt.merge_from_branch(tree2.branch)
200
162
        wt.commit('merge b3', rev_id='a3')
201
163
 
202
 
        wt.merge_from_branch(tree3.branch)
203
 
        wt.commit('merge c3', rev_id='a4')
 
164
        tree2.commit('unchanged', rev_id='b4')
 
165
 
 
166
        wt.merge_from_branch(tree2.branch)
 
167
        wt.commit('merge b4', rev_id='a4')
204
168
 
205
169
        self.assertEqual(['a4'], wt.get_parent_ids())
206
170
 
207
171
        os.chdir('tree')
208
172
        out, err = self.run_bzr('uncommit --force -r 2')
209
173
 
210
 
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
 
174
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
211
175
 
212
176
    def test_uncommit_merge_plus_pending(self):
213
177
        wt = self.create_simple_tree()
214
178
 
215
179
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
 
180
 
216
181
        tree2.commit('unchanged', rev_id='b3')
217
 
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
218
 
        tree3.commit('unchanged', rev_id='c3')
219
 
 
220
182
        wt.branch.fetch(tree2.branch)
221
183
        wt.set_pending_merges(['b3'])
222
184
        wt.commit('merge b3', rev_id='a3')
223
185
 
224
 
 
225
 
        wt.merge_from_branch(tree3.branch)
226
 
 
227
 
        self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
 
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())
228
191
 
229
192
        os.chdir('tree')
230
193
        out, err = self.run_bzr('uncommit --force -r 2')
231
194
 
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
 
""")
 
195
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
248
196
 
249
197
    def test_uncommit_octopus_merge(self):
250
198
        # Check that uncommit keeps the pending merges in the same order
251
 
        # though it will also filter out ones in the ancestry
252
199
        wt = self.create_simple_tree()
253
200
 
254
201
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
256
203
 
257
204
        tree2.commit('unchanged', rev_id='b3')
258
205
        tree3.commit('unchanged', rev_id='c3')
259
 
 
 
206
        
260
207
        wt.merge_from_branch(tree2.branch)
261
 
        wt.merge_from_branch(tree3.branch, force=True)
 
208
        wt.merge_from_branch(tree3.branch)
262
209
        wt.commit('merge b3, c3', rev_id='a3')
263
210
 
264
211
        tree2.commit('unchanged', rev_id='b4')
265
212
        tree3.commit('unchanged', rev_id='c4')
266
213
 
267
214
        wt.merge_from_branch(tree3.branch)
268
 
        wt.merge_from_branch(tree2.branch, force=True)
 
215
        wt.merge_from_branch(tree2.branch)
269
216
        wt.commit('merge b4, c4', rev_id='a4')
270
217
 
271
218
        self.assertEqual(['a4'], wt.get_parent_ids())
273
220
        os.chdir('tree')
274
221
        out, err = self.run_bzr('uncommit --force -r 2')
275
222
 
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')
283
 
 
284
 
    def test_uncommit_removes_tags(self):
285
 
        tree = self.make_branch_and_tree('tree')
286
 
        revid = tree.commit('message')
287
 
        tree.branch.tags.set_tag("atag", revid)
288
 
        out, err = self.run_bzr('uncommit --force tree')
289
 
        self.assertEquals({}, tree.branch.tags.get_tag_dict())
290
 
 
291
 
    def test_uncommit_keep_tags(self):
292
 
        tree = self.make_branch_and_tree('tree')
293
 
        revid = tree.commit('message')
294
 
        tree.branch.tags.set_tag("atag", revid)
295
 
        out, err = self.run_bzr('uncommit --keep-tags --force tree')
296
 
        self.assertEquals({"atag": revid}, tree.branch.tags.get_tag_dict())
 
223
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())