~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2011-02-26 15:39:49 UTC
  • mto: (5691.1.1 bzr.dev)
  • mto: This revision was merged to the branch mainline in revision 5692.
  • Revision ID: jelmer@samba.org-20110226153949-o0fk909b30g7z570
Fix the use of "bzr tags" in branches with ghosts in their mainline /and/ tags on revisions not in the branch ancestry.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 by 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
42
46
        wt = self.create_simple_tree()
43
47
 
44
48
        os.chdir('tree')
45
 
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
 
49
        out, err = self.run_bzr('uncommit --dry-run --force')
46
50
        self.assertContainsRe(out, 'Dry-run')
47
51
        self.assertNotContainsRe(out, 'initial commit')
48
52
        self.assertContainsRe(out, 'second commit')
49
53
 
50
54
        # Nothing has changed
51
 
        self.assertEqual('a2', wt.last_revision())
 
55
        self.assertEqual(['a2'], wt.get_parent_ids())
52
56
 
53
57
        # Uncommit, don't prompt
54
 
        out, err = self.run_bzr('uncommit', '--force')
 
58
        out, err = self.run_bzr('uncommit --force')
55
59
        self.assertNotContainsRe(out, 'initial commit')
56
60
        self.assertContainsRe(out, 'second commit')
57
61
 
58
62
        # This should look like we are back in revno 1
59
 
        self.assertEqual('a1', wt.last_revision())
 
63
        self.assertEqual(['a1'], wt.get_parent_ids())
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
 
 
66
 
        checkout_tree = wt.bzrdir.sprout('checkout').open_workingtree()
67
 
        checkout_tree.branch.bind(wt.branch)
68
 
 
69
 
        self.assertEqual('a2', checkout_tree.last_revision())
 
89
        checkout_tree = wt.branch.create_checkout('checkout')
 
90
 
 
91
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
70
92
 
71
93
        os.chdir('checkout')
72
 
        out, err = self.run_bzr('uncommit', '--dry-run', '--force')
 
94
        out, err = self.run_bzr('uncommit --dry-run --force')
73
95
        self.assertContainsRe(out, 'Dry-run')
74
96
        self.assertNotContainsRe(out, 'initial commit')
75
97
        self.assertContainsRe(out, 'second commit')
76
98
 
77
 
        self.assertEqual('a2', checkout_tree.last_revision())
 
99
        self.assertEqual(['a2'], checkout_tree.get_parent_ids())
78
100
 
79
 
        out, err = self.run_bzr('uncommit', '--force')
 
101
        out, err = self.run_bzr('uncommit --force')
80
102
        self.assertNotContainsRe(out, 'initial commit')
81
103
        self.assertContainsRe(out, 'second commit')
82
104
 
83
105
        # uncommit in a checkout should uncommit the parent branch
84
106
        # (but doesn't effect the other working tree)
85
 
        self.assertEquals('a1', checkout_tree.last_revision())
 
107
        self.assertEquals(['a1'], checkout_tree.get_parent_ids())
86
108
        self.assertEquals('a1', wt.branch.last_revision())
87
 
        self.assertEquals('a2', wt.last_revision())
 
109
        self.assertEquals(['a2'], wt.get_parent_ids())
88
110
 
89
111
    def test_uncommit_bound(self):
90
112
        os.mkdir('a')
95
117
        t_a.commit('commit 1')
96
118
        t_a.commit('commit 2')
97
119
        t_a.commit('commit 3')
98
 
        b = t_a.bzrdir.sprout('b').open_branch()
99
 
        b.bind(t_a.branch)
 
120
        b = t_a.branch.create_checkout('b').branch
100
121
        uncommit.uncommit(b)
101
122
        self.assertEqual(len(b.revision_history()), 2)
102
123
        self.assertEqual(len(t_a.branch.revision_history()), 2)
103
 
        # update A's tree to not have the uncomitted revision referenced.
 
124
        # update A's tree to not have the uncommitted revision referenced.
104
125
        t_a.update()
105
126
        t_a.commit('commit 3b')
106
127
        self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
107
128
        b.pull(t_a.branch)
108
129
        uncommit.uncommit(b)
109
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
 
110
143
    def test_uncommit_revision(self):
111
144
        wt = self.create_simple_tree()
112
145
 
113
146
        os.chdir('tree')
114
 
        out, err = self.run_bzr('uncommit', '-r1', '--force')
 
147
        out, err = self.run_bzr('uncommit -r1 --force')
115
148
 
116
149
        self.assertNotContainsRe(out, 'initial commit')
117
150
        self.assertContainsRe(out, 'second commit')
118
 
        self.assertEqual('a1', wt.last_revision())
 
151
        self.assertEqual(['a1'], wt.get_parent_ids())
119
152
        self.assertEqual('a1', wt.branch.last_revision())
120
153
 
121
154
    def test_uncommit_neg_1(self):
122
155
        wt = self.create_simple_tree()
123
156
        os.chdir('tree')
124
 
        out, err = self.run_bzr('uncommit', '-r', '-1', retcode=1)
 
157
        out, err = self.run_bzr('uncommit -r -1', retcode=1)
125
158
        self.assertEqual('No revisions to uncommit.\n', out)
126
159
 
127
160
    def test_uncommit_merges(self):
132
165
        tree2.commit('unchanged', rev_id='b3')
133
166
        tree2.commit('unchanged', rev_id='b4')
134
167
 
135
 
        self.merge(tree2.branch, wt)
 
168
        wt.merge_from_branch(tree2.branch)
136
169
        wt.commit('merge b4', rev_id='a3')
137
170
 
138
171
        self.assertEqual(['a3'], wt.get_parent_ids())
139
172
 
140
173
        os.chdir('tree')
141
 
        out, err = self.run_bzr('uncommit', '--force')
 
174
        out, err = self.run_bzr('uncommit --force')
142
175
 
143
176
        self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
144
177
 
151
184
        wt.set_pending_merges(['b3'])
152
185
 
153
186
        os.chdir('tree')
154
 
        out, err = self.run_bzr('uncommit', '--force')
155
 
        self.assertEqual('a1', wt.last_revision())
156
 
        self.assertEqual(['b3'], wt.pending_merges())
 
187
        out, err = self.run_bzr('uncommit --force')
 
188
        self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
157
189
 
158
190
    def test_uncommit_multiple_merge(self):
159
191
        wt = self.create_simple_tree()
160
192
 
161
193
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
162
 
 
163
194
        tree2.commit('unchanged', rev_id='b3')
164
195
 
165
 
        self.merge(tree2.branch, wt)
 
196
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
197
        tree3.commit('unchanged', rev_id='c3')
 
198
 
 
199
        wt.merge_from_branch(tree2.branch)
166
200
        wt.commit('merge b3', rev_id='a3')
167
201
 
168
 
        tree2.commit('unchanged', rev_id='b4')
169
 
 
170
 
        self.merge(tree2.branch, wt)
171
 
        wt.commit('merge b4', rev_id='a4')
 
202
        wt.merge_from_branch(tree3.branch)
 
203
        wt.commit('merge c3', rev_id='a4')
172
204
 
173
205
        self.assertEqual(['a4'], wt.get_parent_ids())
174
206
 
175
207
        os.chdir('tree')
176
 
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
 
208
        out, err = self.run_bzr('uncommit --force -r 2')
177
209
 
178
 
        self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
 
210
        self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
179
211
 
180
212
    def test_uncommit_merge_plus_pending(self):
181
213
        wt = self.create_simple_tree()
182
214
 
183
215
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
184
 
 
185
216
        tree2.commit('unchanged', rev_id='b3')
 
217
        tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
 
218
        tree3.commit('unchanged', rev_id='c3')
 
219
 
186
220
        wt.branch.fetch(tree2.branch)
187
221
        wt.set_pending_merges(['b3'])
188
222
        wt.commit('merge b3', rev_id='a3')
189
223
 
190
 
        tree2.commit('unchanged', rev_id='b4')
191
 
        wt.branch.fetch(tree2.branch)
192
 
        wt.set_pending_merges(['b4'])
193
 
 
194
 
        self.assertEqual('a3', wt.last_revision())
195
 
        self.assertEqual(['b4'], wt.pending_merges())
 
224
 
 
225
        wt.merge_from_branch(tree3.branch)
 
226
 
 
227
        self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
196
228
 
197
229
        os.chdir('tree')
198
 
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
199
 
 
200
 
        self.assertEqual('a2', wt.last_revision())
201
 
        self.assertEqual(['b3', 'b4'], wt.pending_merges())
 
230
        out, err = self.run_bzr('uncommit --force -r 2')
 
231
 
 
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
""")
202
248
 
203
249
    def test_uncommit_octopus_merge(self):
204
250
        # Check that uncommit keeps the pending merges in the same order
 
251
        # though it will also filter out ones in the ancestry
205
252
        wt = self.create_simple_tree()
206
253
 
207
254
        tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
209
256
 
210
257
        tree2.commit('unchanged', rev_id='b3')
211
258
        tree3.commit('unchanged', rev_id='c3')
212
 
        
213
 
        self.merge(tree2.branch, wt)
214
 
        self.merge(tree3.branch, wt)
 
259
 
 
260
        wt.merge_from_branch(tree2.branch)
 
261
        wt.merge_from_branch(tree3.branch, force=True)
215
262
        wt.commit('merge b3, c3', rev_id='a3')
216
263
 
217
264
        tree2.commit('unchanged', rev_id='b4')
218
265
        tree3.commit('unchanged', rev_id='c4')
219
266
 
220
 
        self.merge(tree3.branch, wt)
221
 
        self.merge(tree2.branch, wt)
 
267
        wt.merge_from_branch(tree3.branch)
 
268
        wt.merge_from_branch(tree2.branch, force=True)
222
269
        wt.commit('merge b4, c4', rev_id='a4')
223
270
 
224
271
        self.assertEqual(['a4'], wt.get_parent_ids())
225
272
 
226
273
        os.chdir('tree')
227
 
        out, err = self.run_bzr('uncommit', '--force', '-r', '2')
228
 
 
229
 
        self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())
 
274
        out, err = self.run_bzr('uncommit --force -r 2')
 
275
 
 
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')