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')
62
63
def test_uncommit_checkout(self):
63
64
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())
65
checkout_tree = wt.branch.create_checkout('checkout')
67
self.assertEqual(['a2'], checkout_tree.get_parent_ids())
70
69
os.chdir('checkout')
71
70
out, err = self.run_bzr('uncommit', '--dry-run', '--force')
73
72
self.assertNotContainsRe(out, 'initial commit')
74
73
self.assertContainsRe(out, 'second commit')
76
self.assertEqual('a2', checkout_tree.last_revision())
75
self.assertEqual(['a2'], checkout_tree.get_parent_ids())
78
77
out, err = self.run_bzr('uncommit', '--force')
79
78
self.assertNotContainsRe(out, 'initial commit')
82
81
# uncommit in a checkout should uncommit the parent branch
83
82
# (but doesn't effect the other working tree)
84
self.assertEquals('a1', checkout_tree.last_revision())
83
self.assertEquals(['a1'], checkout_tree.get_parent_ids())
85
84
self.assertEquals('a1', wt.branch.last_revision())
86
self.assertEquals('a2', wt.last_revision())
85
self.assertEquals(['a2'], wt.get_parent_ids())
88
87
def test_uncommit_bound(self):
90
89
a = BzrDirMetaFormat1().initialize('a')
91
90
a.create_repository()
93
t = a.create_workingtree()
97
b = t.bzrdir.sprout('b').open_branch()
92
t_a = a.create_workingtree()
93
t_a.commit('commit 1')
94
t_a.commit('commit 2')
95
t_a.commit('commit 3')
96
b = t_a.branch.create_checkout('b').branch
99
97
uncommit.uncommit(b)
100
t.set_last_revision(t.branch.last_revision())
101
98
self.assertEqual(len(b.revision_history()), 2)
102
self.assertEqual(len(t.branch.revision_history()), 2)
103
t.commit('commit 3b')
99
self.assertEqual(len(t_a.branch.revision_history()), 2)
100
# update A's tree to not have the uncomitted revision referenced.
102
t_a.commit('commit 3b')
104
103
self.assertRaises(BoundBranchOutOfDate, uncommit.uncommit, b)
106
105
uncommit.uncommit(b)
108
107
def test_uncommit_revision(self):
114
113
self.assertNotContainsRe(out, 'initial commit')
115
114
self.assertContainsRe(out, 'second commit')
116
self.assertEqual('a1', wt.last_revision())
115
self.assertEqual(['a1'], wt.get_parent_ids())
117
116
self.assertEqual('a1', wt.branch.last_revision())
119
118
def test_uncommit_neg_1(self):
130
129
tree2.commit('unchanged', rev_id='b3')
131
130
tree2.commit('unchanged', rev_id='b4')
133
wt.branch.fetch(tree2.branch)
134
wt.set_pending_merges(['b4'])
132
wt.merge_from_branch(tree2.branch)
135
133
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())
135
self.assertEqual(['a3'], wt.get_parent_ids())
138
out, err = self.run_bzr('uncommit', '--force')
140
self.assertEqual(['a2', 'b4'], wt.get_parent_ids())
142
def test_uncommit_pending_merge(self):
143
wt = self.create_simple_tree()
144
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
145
tree2.commit('unchanged', rev_id='b3')
147
wt.branch.fetch(tree2.branch)
148
wt.set_pending_merges(['b3'])
151
out, err = self.run_bzr('uncommit', '--force')
152
self.assertEqual(['a1', 'b3'], wt.get_parent_ids())
146
154
def test_uncommit_multiple_merge(self):
147
155
wt = self.create_simple_tree()
149
157
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
151
159
tree2.commit('unchanged', rev_id='b3')
152
wt.branch.fetch(tree2.branch)
153
wt.set_pending_merges(['b3'])
161
wt.merge_from_branch(tree2.branch)
154
162
wt.commit('merge b3', rev_id='a3')
156
164
tree2.commit('unchanged', rev_id='b4')
157
wt.branch.fetch(tree2.branch)
158
wt.set_pending_merges(['b4'])
166
wt.merge_from_branch(tree2.branch)
159
167
wt.commit('merge b4', rev_id='a4')
161
self.assertEqual('a4', wt.last_revision())
162
self.assertEqual([], wt.pending_merges())
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())
169
self.assertEqual(['a4'], wt.get_parent_ids())
172
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
174
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
176
def test_uncommit_merge_plus_pending(self):
177
wt = self.create_simple_tree()
179
tree2 = wt.bzrdir.sprout('tree2').open_workingtree()
181
tree2.commit('unchanged', rev_id='b3')
182
wt.branch.fetch(tree2.branch)
183
wt.set_pending_merges(['b3'])
184
wt.commit('merge b3', rev_id='a3')
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())
193
out, err = self.run_bzr('uncommit', '--force', '-r', '2')
195
self.assertEqual(['a2', 'b3', 'b4'], wt.get_parent_ids())
170
197
def test_uncommit_octopus_merge(self):
171
198
# Check that uncommit keeps the pending merges in the same order
177
204
tree2.commit('unchanged', rev_id='b3')
178
205
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'])
207
wt.merge_from_branch(tree2.branch)
208
wt.merge_from_branch(tree3.branch)
182
209
wt.commit('merge b3, c3', rev_id='a3')
184
211
tree2.commit('unchanged', rev_id='b4')
185
212
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'])
214
wt.merge_from_branch(tree3.branch)
215
wt.merge_from_branch(tree2.branch)
189
216
wt.commit('merge b4, c4', rev_id='a4')
191
self.assertEqual('a4', wt.last_revision())
192
self.assertEqual([], wt.pending_merges())
218
self.assertEqual(['a4'], wt.get_parent_ids())
195
221
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())
223
self.assertEqual(['a2', 'b3', 'c3', 'c4', 'b4'], wt.get_parent_ids())