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
17
17
"""Test the uncommit command."""
103
104
uncommit.uncommit(b)
104
105
self.assertEqual(len(b.revision_history()), 2)
105
106
self.assertEqual(len(t_a.branch.revision_history()), 2)
106
# update A's tree to not have the uncomitted revision referenced.
107
# update A's tree to not have the uncommitted revision referenced.
108
109
t_a.commit('commit 3b')
109
110
self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
110
111
b.pull(t_a.branch)
111
112
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())
113
126
def test_uncommit_revision(self):
114
127
wt = self.create_simple_tree()
161
174
wt = self.create_simple_tree()
163
176
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
165
177
tree2.commit('unchanged', rev_id='b3')
179
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
180
tree3.commit('unchanged', rev_id='c3')
167
182
wt.merge_from_branch(tree2.branch)
168
183
wt.commit('merge b3', rev_id='a3')
170
tree2.commit('unchanged', rev_id='b4')
172
wt.merge_from_branch(tree2.branch)
173
wt.commit('merge b4', rev_id='a4')
185
wt.merge_from_branch(tree3.branch)
186
wt.commit('merge c3', rev_id='a4')
175
188
self.assertEqual(['a4'], wt.get_parent_ids())
178
191
out, err = self.run_bzr('uncommit --force -r 2')
180
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
193
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
182
195
def test_uncommit_merge_plus_pending(self):
183
196
wt = self.create_simple_tree()
185
198
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
187
199
tree2.commit('unchanged', rev_id='b3')
200
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
201
tree3.commit('unchanged', rev_id='c3')
188
203
wt.branch.fetch(tree2.branch)
189
204
wt.set_pending_merges(['b3'])
190
205
wt.commit('merge b3', rev_id='a3')
192
tree2.commit('unchanged', rev_id='b4')
193
wt.branch.fetch(tree2.branch)
194
wt.set_pending_merges(['b4'])
196
self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
208
wt.merge_from_branch(tree3.branch)
210
self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
199
213
out, err = self.run_bzr('uncommit --force -r 2')
201
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
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
203
232
def test_uncommit_octopus_merge(self):
204
233
# Check that uncommit keeps the pending merges in the same order
234
# though it will also filter out ones in the ancestry
205
235
wt = self.create_simple_tree()
207
237
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
210
240
tree2.commit('unchanged', rev_id='b3')
211
241
tree3.commit('unchanged', rev_id='c3')
213
243
wt.merge_from_branch(tree2.branch)
214
wt.merge_from_branch(tree3.branch)
244
wt.merge_from_branch(tree3.branch, force=True)
215
245
wt.commit('merge b3, c3', rev_id='a3')
217
247
tree2.commit('unchanged', rev_id='b4')
218
248
tree3.commit('unchanged', rev_id='c4')
220
250
wt.merge_from_branch(tree3.branch)
221
wt.merge_from_branch(tree2.branch)
251
wt.merge_from_branch(tree2.branch, force=True)
222
252
wt.commit('merge b4, c4', rev_id='a4')
224
254
self.assertEqual(['a4'], wt.get_parent_ids())
227
257
out, err = self.run_bzr('uncommit --force -r 2')
229
self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())
259
self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
231
261
def test_uncommit_nonascii(self):
232
262
tree = self.make_branch_and_tree('tree')