63
62
revisions_2 = br2.revision_history()
65
64
fetch(from_branch=br2, to_branch=br1)
66
br1.working_tree().add_pending_merge(revisions_2[4])
67
self.assertEquals(revisions_2[4], 'b@u-0-4')
65
br1.add_pending_merge(revisions_2[4])
66
assert revisions_2[4] == 'b@u-0-4'
68
67
commit(br1, "Commit six", rev_id="a@u-0-3")
69
68
commit(br1, "Commit seven", rev_id="a@u-0-4")
70
69
commit(br2, "Commit eight", rev_id="b@u-0-5")
72
71
fetch(from_branch=br2, to_branch=br1)
73
br1.working_tree().add_pending_merge(br2.revision_history()[5])
72
br1.add_pending_merge(br2.revision_history()[5])
74
73
commit(br1, "Commit nine", rev_id="a@u-0-5")
75
# DO NOT FETCH HERE - we WANT a GHOST.
74
# disabled - it makes testing fetch too hard,
75
# but can be easily reenabled (without the fetch
76
# when GHOSTS are supported. RBC 20050928
76
77
#fetch(from_branch=br1, to_branch=br2)
77
br2.working_tree().add_pending_merge(br1.revision_history()[4])
78
commit(br2, "Commit ten - ghost merge", rev_id="b@u-0-6")
78
#br2.add_pending_merge(br1.revision_history()[4])
79
commit(br2, "Commit ten - no merge", rev_id="b@u-0-6")
81
#fetch(from_branch=br2, to_branch=br1)
83
86
class TestIsAncestor(TestCaseInTempDir):
84
87
def test_recorded_ancestry(self):
85
88
"""Test that commit records all ancestors"""
86
br1, br2 = make_branches(self)
89
br1, br2 = make_branches()
87
90
d = [('a@u-0-0', ['a@u-0-0']),
88
91
('a@u-0-1', ['a@u-0-0', 'a@u-0-1']),
89
92
('a@u-0-2', ['a@u-0-0', 'a@u-0-1', 'a@u-0-2']),
120
123
def test_is_ancestor(self):
121
124
"""Test checking whether a revision is an ancestor of another revision"""
122
br1, br2 = make_branches(self)
125
br1, br2 = make_branches()
123
126
revisions = br1.revision_history()
124
127
revisions_2 = br2.revision_history()
127
self.assert_(is_ancestor(revisions[0], revisions[0], br1))
128
self.assert_(is_ancestor(revisions[1], revisions[0], sources))
129
self.assert_(not is_ancestor(revisions[0], revisions[1], sources))
130
self.assert_(is_ancestor(revisions_2[3], revisions[0], sources))
130
assert is_ancestor(revisions[0], revisions[0], br1)
131
assert is_ancestor(revisions[1], revisions[0], sources)
132
assert not is_ancestor(revisions[0], revisions[1], sources)
133
assert is_ancestor(revisions_2[3], revisions[0], sources)
131
134
# disabled mbp 20050914, doesn't seem to happen anymore
132
135
## self.assertRaises(NoSuchRevision, is_ancestor, revisions_2[3],
133
136
## revisions[0], br1)
134
self.assert_(is_ancestor(revisions[3], revisions_2[4], sources))
135
self.assert_(is_ancestor(revisions[3], revisions_2[4], br1))
136
self.assert_(is_ancestor(revisions[3], revisions_2[3], sources))
137
## self.assert_(not is_ancestor(revisions[3], revisions_2[3], br1))
137
assert is_ancestor(revisions[3], revisions_2[4], sources)
138
assert is_ancestor(revisions[3], revisions_2[4], br1)
139
assert is_ancestor(revisions[3], revisions_2[3], sources)
140
## assert not is_ancestor(revisions[3], revisions_2[3], br1)
140
144
class TestIntermediateRevisions(TestCaseInTempDir):
143
147
from bzrlib.commit import commit
144
148
TestCaseInTempDir.setUp(self)
145
self.br1, self.br2 = make_branches(self)
149
self.br1, self.br2 = make_branches()
147
self.br2.working_tree().commit("Commit eleven", rev_id="b@u-0-7")
148
self.br2.working_tree().commit("Commit twelve", rev_id="b@u-0-8")
149
self.br2.working_tree().commit("Commit thirtteen", rev_id="b@u-0-9")
151
self.br2.commit("Commit eleven", rev_id="b@u-0-7")
152
self.br2.commit("Commit twelve", rev_id="b@u-0-8")
153
self.br2.commit("Commit thirtteen", rev_id="b@u-0-9")
151
155
fetch(from_branch=self.br2, to_branch=self.br1)
152
self.br1.working_tree().add_pending_merge(self.br2.revision_history()[6])
153
self.br1.working_tree().commit("Commit fourtten", rev_id="a@u-0-6")
156
self.br1.add_pending_merge(self.br2.revision_history()[6])
157
self.br1.commit("Commit fourtten", rev_id="a@u-0-6")
155
159
fetch(from_branch=self.br1, to_branch=self.br2)
156
self.br2.working_tree().add_pending_merge(self.br1.revision_history()[6])
157
self.br2.working_tree().commit("Commit fifteen", rev_id="b@u-0-10")
160
self.br2.add_pending_merge(self.br1.revision_history()[6])
161
self.br2.commit("Commit fifteen", rev_id="b@u-0-10")
159
163
from bzrlib.revision import MultipleRevisionSources
160
164
self.sources = MultipleRevisionSources(self.br1, self.br2)
167
171
def test_intervene(self):
168
172
"""Find intermediate revisions, without requiring history"""
169
173
from bzrlib.errors import NotAncestor, NoSuchRevision
170
self.assertEquals(len(self.intervene('a@u-0-0', 'a@u-0-0')), 0)
174
assert len(self.intervene('a@u-0-0', 'a@u-0-0')) == 0
171
175
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-1'), ['a@u-0-1'])
172
176
self.assertEqual(self.intervene('a@u-0-0', 'a@u-0-2'),
173
177
['a@u-0-1', 'a@u-0-2'])
182
186
self.br1.revision_history()),
183
187
['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
185
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6',
186
self.br1.revision_history()),
187
['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
189
self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'),
190
['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
189
print ("testrevision.py 191 - intervene appears to return b..6 even"
190
"though it is not reachable!")
191
# self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-6',
192
# self.br1.revision_history()),
193
# ['a@u-0-1', 'a@u-0-2', 'a@u-0-3', 'a@u-0-4',
195
# self.assertEqual(self.intervene('a@u-0-0', 'b@u-0-5'),
196
# ['a@u-0-1', 'a@u-0-2', 'b@u-0-3', 'b@u-0-4',
192
198
self.assertEqual(self.intervene('b@u-0-3', 'b@u-0-6',
193
199
self.br2.revision_history()),
194
200
['b@u-0-4', 'b@u-0-5', 'b@u-0-6'])
211
217
def test_old_common_ancestor(self):
212
218
"""Pick a resonable merge base using the old functionality"""
213
219
from bzrlib.revision import old_common_ancestor as common_ancestor
214
br1, br2 = make_branches(self)
220
br1, br2 = make_branches()
215
221
revisions = br1.revision_history()
216
222
revisions_2 = br2.revision_history()
223
229
revisions_2[3]:(4, 2),
224
230
revisions[0]:(5, 3) }
225
231
ancestors_list = find_present_ancestors(revisions[3], sources)
226
self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
232
assert len(expected_ancestors_list) == len(ancestors_list)
227
233
for key, value in expected_ancestors_list.iteritems():
228
234
self.assertEqual(ancestors_list[key], value,
229
235
"key %r, %r != %r" % (key, ancestors_list[key],
244
250
fetch(from_branch=br2, to_branch=br1)
245
251
self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
246
revisions[4]) # revisions_2[5] is equally valid
247
253
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
250
256
def test_common_ancestor(self):
251
257
"""Pick a reasonable merge base"""
252
258
from bzrlib.revision import common_ancestor
253
br1, br2 = make_branches(self)
259
br1, br2 = make_branches()
254
260
revisions = br1.revision_history()
255
261
revisions_2 = br2.revision_history()
256
262
sources = MultipleRevisionSources(br1, br2)
257
264
expected_ancestors_list = {revisions[3]:(0, 0),
258
265
revisions[2]:(1, 1),
259
266
revisions_2[4]:(2, 1),
261
268
revisions_2[3]:(4, 2),
262
269
revisions[0]:(5, 3) }
263
270
ancestors_list = find_present_ancestors(revisions[3], sources)
264
self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
271
assert len(expected_ancestors_list) == len(ancestors_list)
265
272
for key, value in expected_ancestors_list.iteritems():
266
273
self.assertEqual(ancestors_list[key], value,
267
274
"key %r, %r != %r" % (key, ancestors_list[key],
269
277
self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
271
279
self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
279
287
self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
281
289
self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
282
revisions[4]) # revisions_2[5] is equally valid
283
291
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
284
revisions[4]) # revisions_2[5] is equally valid
286
294
def test_combined(self):
287
295
"""combined_graph
288
296
Ensure it's not order-sensitive
290
br1, br2 = make_branches(self)
298
br1, br2 = make_branches()
291
299
source = MultipleRevisionSources(br1, br2)
292
300
combined_1 = combined_graph(br1.last_revision(),
293
301
br2.last_revision(), source)
294
302
combined_2 = combined_graph(br2.last_revision(),
295
303
br1.last_revision(), source)
296
self.assertEquals(combined_1[1], combined_2[1])
297
self.assertEquals(combined_1[2], combined_2[2])
298
self.assertEquals(combined_1[3], combined_2[3])
299
self.assertEquals(combined_1, combined_2)
304
assert combined_1[1] == combined_2[1]
305
assert combined_1[2] == combined_2[2]
306
assert combined_1[3] == combined_2[3]
307
assert combined_1 == combined_2