41
42
wt = self.create_simple_tree()
44
out, err = self.run_bzr('uncommit', '--dry-run', '--force')
45
out, err = self.run_bzr('uncommit --dry-run --force')
45
46
self.assertContainsRe(out, 'Dry-run')
46
47
self.assertNotContainsRe(out, 'initial commit')
47
48
self.assertContainsRe(out, 'second commit')
49
50
# Nothing has changed
50
self.assertEqual('a2', wt.last_revision())
51
self.assertEqual(['a2'], wt.get_parent_ids())
52
53
# Uncommit, don't prompt
53
out, err = self.run_bzr('uncommit', '--force')
54
out, err = self.run_bzr('uncommit --force')
54
55
self.assertNotContainsRe(out, 'initial commit')
55
56
self.assertContainsRe(out, 'second commit')
57
58
# This should look like we are back in revno 1
58
self.assertEqual('a1', wt.last_revision())
59
self.assertEqual(['a1'], wt.get_parent_ids())
59
60
out, err = self.run_bzr('status')
60
61
self.assertEquals(out, 'modified:\n a\n')
63
def test_uncommit_no_history(self):
64
wt = self.make_branch_and_tree('tree')
65
out, err = self.run_bzr('uncommit --force', retcode=1)
66
self.assertEqual('', err)
67
self.assertEqual('No revisions to uncommit.\n', out)
62
69
def test_uncommit_checkout(self):
63
70
wt = self.create_simple_tree()
65
checkout_tree = wt.bzrdir.sprout('checkout').open_workingtree()
66
checkout_tree.branch.bind(wt.branch)
68
self.assertEqual('a2', checkout_tree.last_revision())
71
checkout_tree = wt.branch.create_checkout('checkout')
73
self.assertEqual(['a2'], checkout_tree.get_parent_ids())
70
75
os.chdir('checkout')
71
out, err = self.run_bzr('uncommit', '--dry-run', '--force')
76
out, err = self.run_bzr('uncommit --dry-run --force')
72
77
self.assertContainsRe(out, 'Dry-run')
73
78
self.assertNotContainsRe(out, 'initial commit')
74
79
self.assertContainsRe(out, 'second commit')
76
self.assertEqual('a2', checkout_tree.last_revision())
81
self.assertEqual(['a2'], checkout_tree.get_parent_ids())
78
out, err = self.run_bzr('uncommit', '--force')
83
out, err = self.run_bzr('uncommit --force')
79
84
self.assertNotContainsRe(out, 'initial commit')
80
85
self.assertContainsRe(out, 'second commit')
82
87
# uncommit in a checkout should uncommit the parent branch
83
88
# (but doesn't effect the other working tree)
84
self.assertEquals('a1', checkout_tree.last_revision())
89
self.assertEquals(['a1'], checkout_tree.get_parent_ids())
85
90
self.assertEquals('a1', wt.branch.last_revision())
86
self.assertEquals('a2', wt.last_revision())
91
self.assertEquals(['a2'], wt.get_parent_ids())
88
93
def test_uncommit_bound(self):
90
95
a = BzrDirMetaFormat1().initialize('a')
91
96
a.create_repository()
93
t = a.create_workingtree()
97
b = t.bzrdir.sprout('b').open_branch()
98
t_a = a.create_workingtree()
99
t_a.commit('commit 1')
100
t_a.commit('commit 2')
101
t_a.commit('commit 3')
102
b = t_a.branch.create_checkout('b').branch
99
103
uncommit.uncommit(b)
100
t.set_last_revision(t.branch.last_revision())
101
104
self.assertEqual(len(b.revision_history()), 2)
102
self.assertEqual(len(t.branch.revision_history()), 2)
103
t.commit('commit 3b')
105
self.assertEqual(len(t_a.branch.revision_history()), 2)
106
# update A's tree to not have the uncommitted revision referenced.
108
t_a.commit('commit 3b')
104
109
self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
106
111
uncommit.uncommit(b)
113
def test_uncommit_bound_local(self):
114
t_a = self.make_branch_and_tree('a')
115
rev_id1 = t_a.commit('commit 1')
116
rev_id2 = t_a.commit('commit 2')
117
rev_id3 = t_a.commit('commit 3')
118
b = t_a.branch.create_checkout('b').branch
120
out, err = self.run_bzr(['uncommit', '--local', 'b', '--force'])
121
self.assertEqual(rev_id3, t_a.last_revision())
122
self.assertEqual((3, rev_id3), t_a.branch.last_revision_info())
123
self.assertEqual((2, rev_id2), b.last_revision_info())
108
125
def test_uncommit_revision(self):
109
126
wt = self.create_simple_tree()
112
out, err = self.run_bzr('uncommit', '-r1', '--force')
129
out, err = self.run_bzr('uncommit -r1 --force')
114
131
self.assertNotContainsRe(out, 'initial commit')
115
132
self.assertContainsRe(out, 'second commit')
116
self.assertEqual('a1', wt.last_revision())
133
self.assertEqual(['a1'], wt.get_parent_ids())
117
134
self.assertEqual('a1', wt.branch.last_revision())
119
136
def test_uncommit_neg_1(self):
120
137
wt = self.create_simple_tree()
122
out, err = self.run_bzr('uncommit', '-r', '-1', retcode=1)
139
out, err = self.run_bzr('uncommit -r -1', retcode=1)
123
140
self.assertEqual('No revisions to uncommit.\n', out)
125
142
def test_uncommit_merges(self):
130
147
tree2.commit('unchanged', rev_id='b3')
131
148
tree2.commit('unchanged', rev_id='b4')
133
wt.branch.fetch(tree2.branch)
134
wt.set_pending_merges(['b4'])
150
wt.merge_from_branch(tree2.branch)
135
151
wt.commit('merge b4', rev_id='a3')
137
self.assertEqual('a3', wt.last_revision())
138
self.assertEqual([], wt.pending_merges())
141
out, err = self.run_bzr('uncommit', '--force')
143
self.assertEqual('a2', wt.last_revision())
144
self.assertEqual(['b4'], wt.pending_merges())
153
self.assertEqual(['a3'], wt.get_parent_ids())
156
out, err = self.run_bzr('uncommit --force')
158
self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
160
def test_uncommit_pending_merge(self):
161
wt = self.create_simple_tree()
162
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
163
tree2.commit('unchanged', rev_id='b3')
165
wt.branch.fetch(tree2.branch)
166
wt.set_pending_merges(['b3'])
169
out, err = self.run_bzr('uncommit --force')
170
self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
146
172
def test_uncommit_multiple_merge(self):
147
173
wt = self.create_simple_tree()
149
175
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
151
tree2.commit('unchanged', rev_id='b3')
176
tree2.commit('unchanged', rev_id='b3')
178
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
179
tree3.commit('unchanged', rev_id='c3')
181
wt.merge_from_branch(tree2.branch)
182
wt.commit('merge b3', rev_id='a3')
184
wt.merge_from_branch(tree3.branch)
185
wt.commit('merge c3', rev_id='a4')
187
self.assertEqual(['a4'], wt.get_parent_ids())
190
out, err = self.run_bzr('uncommit --force -r 2')
192
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
194
def test_uncommit_merge_plus_pending(self):
195
wt = self.create_simple_tree()
197
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
198
tree2.commit('unchanged', rev_id='b3')
199
tree3 = wt.bzrdir.sprout('tree3').open_workingtree()
200
tree3.commit('unchanged', rev_id='c3')
152
202
wt.branch.fetch(tree2.branch)
153
203
wt.set_pending_merges(['b3'])
154
204
wt.commit('merge b3', rev_id='a3')
156
tree2.commit('unchanged', rev_id='b4')
157
wt.branch.fetch(tree2.branch)
158
wt.set_pending_merges(['b4'])
159
wt.commit('merge b4', rev_id='a4')
161
self.assertEqual('a4', wt.last_revision())
162
self.assertEqual([], wt.pending_merges())
207
wt.merge_from_branch(tree3.branch)
209
self.assertEqual(['a3', 'c3'], wt.get_parent_ids())
165
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
167
self.assertEqual('a2', wt.last_revision())
168
self.assertEqual(['b3', 'b4'], wt.pending_merges())
212
out, err = self.run_bzr('uncommit --force -r 2')
214
self.assertEqual(['a2', 'b3', 'c3'], wt.get_parent_ids())
216
def test_uncommit_shows_log_with_revision_id(self):
217
wt = self.create_simple_tree()
219
out, err = self.run_bzr('uncommit --force', working_dir='tree')
220
self.assertContainsRe(out, r'second commit')
221
self.assertContainsRe(err, r'You can restore the old tip by running')
222
self.assertContainsRe(err, r'bzr pull . -r revid:a2')
170
224
def test_uncommit_octopus_merge(self):
171
225
# Check that uncommit keeps the pending merges in the same order
226
# though it will also filter out ones in the ancestry
172
227
wt = self.create_simple_tree()
174
229
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
177
232
tree2.commit('unchanged', rev_id='b3')
178
233
tree3.commit('unchanged', rev_id='c3')
179
wt.branch.fetch(tree2.branch)
180
wt.branch.fetch(tree3.branch)
181
wt.set_pending_merges(['b3', 'c3'])
235
wt.merge_from_branch(tree2.branch)
236
wt.merge_from_branch(tree3.branch, force=True)
182
237
wt.commit('merge b3, c3', rev_id='a3')
184
239
tree2.commit('unchanged', rev_id='b4')
185
240
tree3.commit('unchanged', rev_id='c4')
186
wt.branch.fetch(tree2.branch)
187
wt.branch.fetch(tree3.branch)
188
wt.set_pending_merges(['c4', 'b4'])
242
wt.merge_from_branch(tree3.branch)
243
wt.merge_from_branch(tree2.branch, force=True)
189
244
wt.commit('merge b4, c4', rev_id='a4')
191
self.assertEqual('a4', wt.last_revision())
192
self.assertEqual([], wt.pending_merges())
246
self.assertEqual(['a4'], wt.get_parent_ids())
195
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
197
self.assertEqual('a2', wt.last_revision())
198
self.assertEqual(['b3', 'c3', 'c4', 'b4'], wt.pending_merges())
249
out, err = self.run_bzr('uncommit --force -r 2')
251
self.assertEqual(['a2', 'c4', 'b4'], wt.get_parent_ids())
253
def test_uncommit_nonascii(self):
254
tree = self.make_branch_and_tree('tree')
255
tree.commit(u'\u1234 message')
256
out, err = self.run_bzr('uncommit --force tree', encoding='ascii')
257
self.assertContainsRe(out, r'\? message')