~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: John Arbash Meinel
  • Date: 2010-08-02 17:16:12 UTC
  • mto: This revision was merged to the branch mainline in revision 5369.
  • Revision ID: john@arbash-meinel.com-20100802171612-rdh5ods70w2bl3j7
We also have to re-implement it for _simple_set_pyx.pyx

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 ScriptRunner
25
26
 
26
27
 
27
28
class TestUncommit(TestCaseWithTransport):
32
33
        wt.add(['a', 'b', 'c'])
33
34
        wt.commit('initial commit', rev_id='a1')
34
35
 
35
 
        open('tree/a', 'wb').write('new contents of a\n')
 
36
        self.build_tree_contents([('tree/a', 'new contents of a\n')])
36
37
        wt.commit('second commit', rev_id='a2')
37
38
 
38
39
        return wt
60
61
        out, err = self.run_bzr('status')
61
62
        self.assertEquals(out, 'modified:\n  a\n')
62
63
 
 
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
 
63
70
    def test_uncommit_checkout(self):
64
71
        wt = self.create_simple_tree()
65
72
        checkout_tree = wt.branch.create_checkout('checkout')
97
104
        uncommit.uncommit(b)
98
105
        self.assertEqual(len(b.revision_history()), 2)
99
106
        self.assertEqual(len(t_a.branch.revision_history()), 2)
100
 
        # update A's tree to not have the uncomitted revision referenced.
 
107
        # update A's tree to not have the uncommitted revision referenced.
101
108
        t_a.update()
102
109
        t_a.commit('commit 3b')
103
110
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
104
111
        b.pull(t_a.branch)
105
112
        uncommit.uncommit(b)
106
113
 
 
114
    def test_uncommit_bound_local(self):
 
115
        t_a = self.make_branch_and_tree('a')
 
116
        rev_id1 = t_a.commit('commit 1')
 
117
        rev_id2 = t_a.commit('commit 2')
 
118
        rev_id3 = t_a.commit('commit 3')
 
119
        b = t_a.branch.create_checkout('b').branch
 
120
 
 
121
        out, err = self.run_bzr(['uncommit', '--local', 'b', '--force'])
 
122
        self.assertEqual(rev_id3, t_a.last_revision())
 
123
        self.assertEqual((3, rev_id3), t_a.branch.last_revision_info())
 
124
        self.assertEqual((2, rev_id2), b.last_revision_info())
 
125
 
107
126
    def test_uncommit_revision(self):
108
127
        wt = self.create_simple_tree()
109
128
 
155
174
        wt = self.create_simple_tree()
156
175
 
157
176
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
158
 
 
159
177
        tree2.commit('unchanged', rev_id='b3')
160
178
 
 
179
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
180
        tree3.commit('unchanged', rev_id='c3')
 
181
 
161
182
        wt.merge_from_branch(tree2.branch)
162
183
        wt.commit('merge b3', rev_id='a3')
163
184
 
164
 
        tree2.commit('unchanged', rev_id='b4')
165
 
 
166
 
        wt.merge_from_branch(tree2.branch)
167
 
        wt.commit('merge b4', rev_id='a4')
 
185
        wt.merge_from_branch(tree3.branch)
 
186
        wt.commit('merge c3', rev_id='a4')
168
187
 
169
188
        self.assertEqual(['a4'], wt.get_parent_ids())
170
189
 
171
190
        os.chdir('tree')
172
191
        out, err = self.run_bzr('uncommit --force -r 2')
173
192
 
174
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
193
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
175
194
 
176
195
    def test_uncommit_merge_plus_pending(self):
177
196
        wt = self.create_simple_tree()
178
197
 
179
198
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
180
 
 
181
199
        tree2.commit('unchanged', rev_id='b3')
 
200
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
201
        tree3.commit('unchanged', rev_id='c3')
 
202
 
182
203
        wt.branch.fetch(tree2.branch)
183
204
        wt.set_pending_merges(['b3'])
184
205
        wt.commit('merge b3', rev_id='a3')
185
206
 
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())
 
207
 
 
208
        wt.merge_from_branch(tree3.branch)
 
209
 
 
210
        self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
191
211
 
192
212
        os.chdir('tree')
193
213
        out, err = self.run_bzr('uncommit --force -r 2')
194
214
 
195
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
215
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
 
216
 
 
217
    def test_uncommit_shows_log_with_revision_id(self):
 
218
        wt = self.create_simple_tree()
 
219
 
 
220
        script = ScriptRunner()
 
221
        script.run_script(self, """
 
222
$ cd tree
 
223
$ bzr uncommit --force 
 
224
    2 ...
 
225
      second commit
 
226
...
 
227
The above revision(s) will be removed.
 
228
You can restore the old tip by running:
 
229
  bzr pull . -r revid:a2
 
230
""")
196
231
 
197
232
    def test_uncommit_octopus_merge(self):
198
233
        # Check that uncommit keeps the pending merges in the same order
 
234
        # though it will also filter out ones in the ancestry
199
235
        wt = self.create_simple_tree()
200
236
 
201
237
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
203
239
 
204
240
        tree2.commit('unchanged', rev_id='b3')
205
241
        tree3.commit('unchanged', rev_id='c3')
206
 
        
 
242
 
207
243
        wt.merge_from_branch(tree2.branch)
208
 
        wt.merge_from_branch(tree3.branch)
 
244
        wt.merge_from_branch(tree3.branch, force=True)
209
245
        wt.commit('merge b3, c3', rev_id='a3')
210
246
 
211
247
        tree2.commit('unchanged', rev_id='b4')
212
248
        tree3.commit('unchanged', rev_id='c4')
213
249
 
214
250
        wt.merge_from_branch(tree3.branch)
215
 
        wt.merge_from_branch(tree2.branch)
 
251
        wt.merge_from_branch(tree2.branch, force=True)
216
252
        wt.commit('merge b4, c4', rev_id='a4')
217
253
 
218
254
        self.assertEqual(['a4'], wt.get_parent_ids())
220
256
        os.chdir('tree')
221
257
        out, err = self.run_bzr('uncommit --force -r 2')
222
258
 
223
 
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())
 
259
        self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
 
260
 
 
261
    def test_uncommit_nonascii(self):
 
262
        tree = self.make_branch_and_tree('tree')
 
263
        tree.commit(u'\u1234 message')
 
264
        out, err = self.run_bzr('uncommit --force tree', encoding='ascii')
 
265
        self.assertContainsRe(out, r'\? message')