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
17
17
"""Test the uncommit command."""
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 (
31
27
class TestUncommit(TestCaseWithTransport):
64
60
out, err = self.run_bzr('status')
65
61
self.assertEquals(out, 'modified:\n a\n')
67
def test_uncommit_interactive(self):
68
"""Uncommit seeks confirmation, and doesn't proceed without it."""
69
wt = self.create_simple_tree()
74
The above revision(s) will be removed.
75
2>Uncommit these revisions? [y/n]:
79
self.assertEqual(['a2'], wt.get_parent_ids())
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)
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.
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)
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
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())
143
107
def test_uncommit_revision(self):
144
108
wt = self.create_simple_tree()
191
155
wt = self.create_simple_tree()
193
157
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
194
159
tree2.commit('unchanged', rev_id='b3')
196
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
197
tree3.commit('unchanged', rev_id='c3')
199
161
wt.merge_from_branch(tree2.branch)
200
162
wt.commit('merge b3', rev_id='a3')
202
wt.merge_from_branch(tree3.branch)
203
wt.commit('merge c3', rev_id='a4')
164
tree2.commit('unchanged', rev_id='b4')
166
wt.merge_from_branch(tree2.branch)
167
wt.commit('merge b4', rev_id='a4')
205
169
self.assertEqual(['a4'], wt.get_parent_ids())
208
172
out, err = self.run_bzr('uncommit --force -r 2')
210
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
174
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
212
176
def test_uncommit_merge_plus_pending(self):
213
177
wt = self.create_simple_tree()
215
179
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
216
181
tree2.commit('unchanged', rev_id='b3')
217
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
218
tree3.commit('unchanged', rev_id='c3')
220
182
wt.branch.fetch(tree2.branch)
221
183
wt.set_pending_merges(['b3'])
222
184
wt.commit('merge b3', rev_id='a3')
225
wt.merge_from_branch(tree3.branch)
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'])
190
self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
230
193
out, err = self.run_bzr('uncommit --force -r 2')
232
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
234
def test_uncommit_shows_log_with_revision_id(self):
235
wt = self.create_simple_tree()
237
script = ScriptRunner()
238
script.run_script(self, """
240
$ bzr uncommit --force
244
The above revision(s) will be removed.
245
You can restore the old tip by running:
246
bzr pull . -r revid:a2
195
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
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()
254
201
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
257
204
tree2.commit('unchanged', rev_id='b3')
258
205
tree3.commit('unchanged', rev_id='c3')
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')
264
211
tree2.commit('unchanged', rev_id='b4')
265
212
tree3.commit('unchanged', rev_id='c4')
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')
271
218
self.assertEqual(['a4'], wt.get_parent_ids())
274
221
out, err = self.run_bzr('uncommit --force -r 2')
276
self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
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')
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())
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())