48
48
self.assertContainsRe(out, 'second commit')
50
50
# Nothing has changed
51
self.assertEqual('a2', wt.last_revision())
51
self.assertEqual(['a2'], wt.get_parent_ids())
53
53
# Uncommit, don't prompt
54
54
out, err = self.run_bzr('uncommit', '--force')
56
56
self.assertContainsRe(out, 'second commit')
58
58
# This should look like we are back in revno 1
59
self.assertEqual('a1', wt.last_revision())
59
self.assertEqual(['a1'], wt.get_parent_ids())
60
60
out, err = self.run_bzr('status')
61
61
self.assertEquals(out, 'modified:\n a\n')
66
66
checkout_tree = wt.bzrdir.sprout('checkout').open_workingtree()
67
67
checkout_tree.branch.bind(wt.branch)
69
self.assertEqual('a2', checkout_tree.last_revision())
69
self.assertEqual(['a2'], checkout_tree.get_parent_ids())
71
71
os.chdir('checkout')
72
72
out, err = self.run_bzr('uncommit', '--dry-run', '--force')
74
74
self.assertNotContainsRe(out, 'initial commit')
75
75
self.assertContainsRe(out, 'second commit')
77
self.assertEqual('a2', checkout_tree.last_revision())
77
self.assertEqual(['a2'], checkout_tree.get_parent_ids())
79
79
out, err = self.run_bzr('uncommit', '--force')
80
80
self.assertNotContainsRe(out, 'initial commit')
83
83
# uncommit in a checkout should uncommit the parent branch
84
84
# (but doesn't effect the other working tree)
85
self.assertEquals('a1', checkout_tree.last_revision())
85
self.assertEquals(['a1'], checkout_tree.get_parent_ids())
86
86
self.assertEquals('a1', wt.branch.last_revision())
87
self.assertEquals('a2', wt.last_revision())
87
self.assertEquals(['a2'], wt.get_parent_ids())
89
89
def test_uncommit_bound(self):
91
91
a = BzrDirMetaFormat1().initialize('a')
92
92
a.create_repository()
94
t = a.create_workingtree()
98
b = t.bzrdir.sprout('b').open_branch()
94
t_a = a.create_workingtree()
95
t_a.commit('commit 1')
96
t_a.commit('commit 2')
97
t_a.commit('commit 3')
98
b = t_a.bzrdir.sprout('b').open_branch()
100
100
uncommit.uncommit(b)
101
t.set_last_revision(t.branch.last_revision())
102
101
self.assertEqual(len(b.revision_history()), 2)
103
self.assertEqual(len(t.branch.revision_history()), 2)
104
t.commit('commit 3b')
102
self.assertEqual(len(t_a.branch.revision_history()), 2)
103
# update A's tree to not have the uncomitted revision referenced.
105
t_a.commit('commit 3b')
105
106
self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
107
108
uncommit.uncommit(b)
109
110
def test_uncommit_revision(self):
115
116
self.assertNotContainsRe(out, 'initial commit')
116
117
self.assertContainsRe(out, 'second commit')
117
self.assertEqual('a1', wt.last_revision())
118
self.assertEqual(['a1'], wt.get_parent_ids())
118
119
self.assertEqual('a1', wt.branch.last_revision())
120
121
def test_uncommit_neg_1(self):
131
132
tree2.commit('unchanged', rev_id='b3')
132
133
tree2.commit('unchanged', rev_id='b4')
134
wt.branch.fetch(tree2.branch)
135
wt.set_pending_merges(['b4'])
135
wt.merge_from_branch(tree2.branch)
136
136
wt.commit('merge b4', rev_id='a3')
138
self.assertEqual('a3', wt.last_revision())
139
self.assertEqual([], wt.pending_merges())
138
self.assertEqual(['a3'], wt.get_parent_ids())
142
141
out, err = self.run_bzr('uncommit', '--force')
144
self.assertEqual('a2', wt.last_revision())
145
self.assertEqual(['b4'], wt.pending_merges())
143
self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
147
145
def test_uncommit_pending_merge(self):
148
146
wt = self.create_simple_tree()
156
154
out, err = self.run_bzr('uncommit', '--force')
157
self.assertEqual('a1', wt.last_revision())
158
self.assertEqual(['b3'], wt.pending_merges())
155
self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
160
157
def test_uncommit_multiple_merge(self):
161
158
wt = self.create_simple_tree()
163
160
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
165
162
tree2.commit('unchanged', rev_id='b3')
166
wt.branch.fetch(tree2.branch)
167
wt.set_pending_merges(['b3'])
164
wt.merge_from_branch(tree2.branch)
168
165
wt.commit('merge b3', rev_id='a3')
170
167
tree2.commit('unchanged', rev_id='b4')
171
wt.branch.fetch(tree2.branch)
172
wt.set_pending_merges(['b4'])
169
wt.merge_from_branch(tree2.branch)
173
170
wt.commit('merge b4', rev_id='a4')
175
self.assertEqual('a4', wt.last_revision())
176
self.assertEqual([], wt.pending_merges())
172
self.assertEqual(['a4'], wt.get_parent_ids())
179
175
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
181
self.assertEqual('a2', wt.last_revision())
182
self.assertEqual(['b3', 'b4'], wt.pending_merges())
177
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
184
179
def test_uncommit_merge_plus_pending(self):
185
180
wt = self.create_simple_tree()
195
190
wt.branch.fetch(tree2.branch)
196
191
wt.set_pending_merges(['b4'])
198
self.assertEqual('a3', wt.last_revision())
199
self.assertEqual(['b4'], wt.pending_merges())
193
self.assertEqual(['a3', 'b4'], wt.get_parent_ids())
202
196
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
204
self.assertEqual('a2', wt.last_revision())
205
self.assertEqual(['b3', 'b4'], wt.pending_merges())
198
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
207
200
def test_uncommit_octopus_merge(self):
208
201
# Check that uncommit keeps the pending merges in the same order
214
207
tree2.commit('unchanged', rev_id='b3')
215
208
tree3.commit('unchanged', rev_id='c3')
216
wt.branch.fetch(tree2.branch)
217
wt.branch.fetch(tree3.branch)
218
wt.set_pending_merges(['b3', 'c3'])
210
wt.merge_from_branch(tree2.branch)
211
wt.merge_from_branch(tree3.branch)
219
212
wt.commit('merge b3, c3', rev_id='a3')
221
214
tree2.commit('unchanged', rev_id='b4')
222
215
tree3.commit('unchanged', rev_id='c4')
223
wt.branch.fetch(tree2.branch)
224
wt.branch.fetch(tree3.branch)
225
wt.set_pending_merges(['c4', 'b4'])
217
wt.merge_from_branch(tree3.branch)
218
wt.merge_from_branch(tree2.branch)
226
219
wt.commit('merge b4, c4', rev_id='a4')
228
self.assertEqual('a4', wt.last_revision())
229
self.assertEqual([], wt.pending_merges())
221
self.assertEqual(['a4'], wt.get_parent_ids())
232
224
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
234
self.assertEqual('a2', wt.last_revision())
235
self.assertEqual(['b3', 'c3', 'c4', 'b4'], wt.pending_merges())
226
self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())