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."""
61
60
out, err = self.run_bzr('status')
62
61
self.assertEquals(out, 'modified:\n a\n')
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)
70
63
def test_uncommit_checkout(self):
71
64
wt = self.create_simple_tree()
72
65
checkout_tree = wt.branch.create_checkout('checkout')
104
97
uncommit.uncommit(b)
105
98
self.assertEqual(len(b.revision_history()), 2)
106
99
self.assertEqual(len(t_a.branch.revision_history()), 2)
107
# update A's tree to not have the uncommitted revision referenced.
100
# update A's tree to not have the uncomitted revision referenced.
109
102
t_a.commit('commit 3b')
110
103
self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
111
104
b.pull(t_a.branch)
112
105
uncommit.uncommit(b)
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
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())
126
107
def test_uncommit_revision(self):
127
108
wt = self.create_simple_tree()
174
155
wt = self.create_simple_tree()
176
157
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
177
159
tree2.commit('unchanged', rev_id='b3')
179
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
180
tree3.commit('unchanged', rev_id='c3')
182
161
wt.merge_from_branch(tree2.branch)
183
162
wt.commit('merge b3', rev_id='a3')
185
wt.merge_from_branch(tree3.branch)
186
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')
188
169
self.assertEqual(['a4'], wt.get_parent_ids())
191
172
out, err = self.run_bzr('uncommit --force -r 2')
193
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
174
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
195
176
def test_uncommit_merge_plus_pending(self):
196
177
wt = self.create_simple_tree()
198
179
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
199
181
tree2.commit('unchanged', rev_id='b3')
200
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
201
tree3.commit('unchanged', rev_id='c3')
203
182
wt.branch.fetch(tree2.branch)
204
183
wt.set_pending_merges(['b3'])
205
184
wt.commit('merge b3', rev_id='a3')
208
wt.merge_from_branch(tree3.branch)
210
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())
213
193
out, err = self.run_bzr('uncommit --force -r 2')
215
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
217
def test_uncommit_shows_log_with_revision_id(self):
218
wt = self.create_simple_tree()
220
script = ScriptRunner()
221
script.run_script(self, """
223
$ bzr uncommit --force
227
The above revision(s) will be removed.
228
You can restore the old tip by running:
229
bzr pull . -r revid:a2
195
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
232
197
def test_uncommit_octopus_merge(self):
233
198
# Check that uncommit keeps the pending merges in the same order
234
# though it will also filter out ones in the ancestry
235
199
wt = self.create_simple_tree()
237
201
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
240
204
tree2.commit('unchanged', rev_id='b3')
241
205
tree3.commit('unchanged', rev_id='c3')
243
207
wt.merge_from_branch(tree2.branch)
244
wt.merge_from_branch(tree3.branch, force=True)
208
wt.merge_from_branch(tree3.branch)
245
209
wt.commit('merge b3, c3', rev_id='a3')
247
211
tree2.commit('unchanged', rev_id='b4')
248
212
tree3.commit('unchanged', rev_id='c4')
250
214
wt.merge_from_branch(tree3.branch)
251
wt.merge_from_branch(tree2.branch, force=True)
215
wt.merge_from_branch(tree2.branch)
252
216
wt.commit('merge b4, c4', rev_id='a4')
254
218
self.assertEqual(['a4'], wt.get_parent_ids())
257
221
out, err = self.run_bzr('uncommit --force -r 2')
259
self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
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')
223
self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())