20
from bzrlib.tests import TestCaseWithTransport
21
20
from bzrlib.branch import Branch
21
from bzrlib.errors import NoSuchRevision
22
22
from bzrlib.commit import commit
23
from bzrlib.fetch import fetch
24
23
from bzrlib.revision import (find_present_ancestors, combined_graph,
25
24
is_ancestor, MultipleRevisionSources)
25
from bzrlib.tests import TestCaseWithTransport
26
26
from bzrlib.trace import mutter
27
from bzrlib.errors import NoSuchRevision
27
from bzrlib.workingtree import WorkingTree
29
29
# XXX: Make this a method of a merge base case
30
30
def make_branches(self):
62
62
tree2.commit("Commit five", rev_id="b@u-0-4")
63
63
revisions_2 = br2.revision_history()
65
fetch(from_branch=br2, to_branch=br1)
66
66
tree1.add_pending_merge(revisions_2[4])
67
67
self.assertEquals(revisions_2[4], 'b@u-0-4')
68
68
tree1.commit("Commit six", rev_id="a@u-0-3")
69
69
tree1.commit("Commit seven", rev_id="a@u-0-4")
70
70
tree2.commit("Commit eight", rev_id="b@u-0-5")
72
fetch(from_branch=br2, to_branch=br1)
73
73
tree1.add_pending_merge(br2.revision_history()[5])
74
74
tree1.commit("Commit nine", rev_id="a@u-0-5")
75
75
# DO NOT FETCH HERE - we WANT a GHOST.
76
#fetch(from_branch=br1, to_branch=br2)
77
77
tree2.add_pending_merge(br1.revision_history()[4])
78
78
tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
144
144
from bzrlib.commit import commit
145
145
TestCaseWithTransport.setUp(self)
146
146
self.br1, self.br2 = make_branches(self)
148
self.br2.working_tree().commit("Commit eleven", rev_id="b@u-0-7")
149
self.br2.working_tree().commit("Commit twelve", rev_id="b@u-0-8")
150
self.br2.working_tree().commit("Commit thirtteen", rev_id="b@u-0-9")
152
fetch(from_branch=self.br2, to_branch=self.br1)
153
self.br1.working_tree().add_pending_merge(self.br2.revision_history()[6])
154
self.br1.working_tree().commit("Commit fourtten", rev_id="a@u-0-6")
156
fetch(from_branch=self.br1, to_branch=self.br2)
157
self.br2.working_tree().add_pending_merge(self.br1.revision_history()[6])
158
self.br2.working_tree().commit("Commit fifteen", rev_id="b@u-0-10")
147
wt1 = self.br1.bzrdir.open_workingtree()
148
wt2 = self.br2.bzrdir.open_workingtree()
149
wt2.commit("Commit eleven", rev_id="b@u-0-7")
150
wt2.commit("Commit twelve", rev_id="b@u-0-8")
151
wt2.commit("Commit thirtteen", rev_id="b@u-0-9")
153
self.br1.fetch(self.br2)
154
wt1.add_pending_merge(self.br2.revision_history()[6])
155
wt1.commit("Commit fourtten", rev_id="a@u-0-6")
157
self.br2.fetch(self.br1)
158
wt2.add_pending_merge(self.br1.revision_history()[6])
159
wt2.commit("Commit fifteen", rev_id="b@u-0-10")
160
161
from bzrlib.revision import MultipleRevisionSources
161
162
self.sources = MultipleRevisionSources(self.br1.repository,
210
211
class TestCommonAncestor(TestCaseWithTransport):
211
212
"""Test checking whether a revision is an ancestor of another revision"""
213
def test_old_common_ancestor(self):
214
"""Pick a resonable merge base using the old functionality"""
215
from bzrlib.revision import old_common_ancestor as common_ancestor
216
br1, br2 = make_branches(self)
217
revisions = br1.revision_history()
218
revisions_2 = br2.revision_history()
219
sources = br1.repository
221
expected_ancestors_list = {revisions[3]:(0, 0),
223
revisions_2[4]:(2, 1),
225
revisions_2[3]:(4, 2),
226
revisions[0]:(5, 3) }
227
ancestors_list = find_present_ancestors(revisions[3], sources)
228
self.assertEquals(len(expected_ancestors_list), len(ancestors_list))
229
for key, value in expected_ancestors_list.iteritems():
230
self.assertEqual(ancestors_list[key], value,
231
"key %r, %r != %r" % (key, ancestors_list[key],
234
self.assertEqual(common_ancestor(revisions[0], revisions[0], sources),
236
self.assertEqual(common_ancestor(revisions[1], revisions[2], sources),
238
self.assertEqual(common_ancestor(revisions[1], revisions[1], sources),
240
self.assertEqual(common_ancestor(revisions[2], revisions_2[4], sources),
242
self.assertEqual(common_ancestor(revisions[3], revisions_2[4], sources),
244
self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
246
fetch(from_branch=br2, to_branch=br1)
247
self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
248
revisions[4]) # revisions_2[5] is equally valid
249
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
252
214
def test_common_ancestor(self):
253
215
"""Pick a reasonable merge base"""
254
216
from bzrlib.revision import common_ancestor
281
243
self.assertEqual(common_ancestor(revisions[4], revisions_2[5], sources),
283
self.assertEqual(common_ancestor(revisions[5], revisions_2[6], sources),
284
revisions[4]) # revisions_2[5] is equally valid
285
self.assertEqual(common_ancestor(revisions_2[6], revisions[5], sources),
286
revisions[4]) # revisions_2[5] is equally valid
245
self.assertTrue(common_ancestor(revisions[5], revisions_2[6], sources) in
246
(revisions[4], revisions_2[5]))
247
self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
248
(revisions[4], revisions_2[5]))
249
self.assertEqual(None, common_ancestor(None, revisions[5], sources))
288
251
def test_combined(self):
289
252
"""combined_graph
299
262
self.assertEquals(combined_1[2], combined_2[2])
300
263
self.assertEquals(combined_1[3], combined_2[3])
301
264
self.assertEquals(combined_1, combined_2)
266
def test_get_history(self):
267
# TODO: test ghosts on the left hand branch's impact
268
# TODO: test ghosts on all parents, we should get some
269
# indicator. i.e. NULL_REVISION
271
tree = self.make_branch_and_tree('.')
272
tree.commit('1', rev_id = '1', allow_pointless=True)
273
tree.commit('2', rev_id = '2', allow_pointless=True)
274
tree.commit('3', rev_id = '3', allow_pointless=True)
275
rev = tree.branch.repository.get_revision('1')
276
history = rev.get_history(tree.branch.repository)
277
self.assertEqual([None, '1'], history)
278
rev = tree.branch.repository.get_revision('2')
279
history = rev.get_history(tree.branch.repository)
280
self.assertEqual([None, '1', '2'], history)
281
rev = tree.branch.repository.get_revision('3')
282
history = rev.get_history(tree.branch.repository)
283
self.assertEqual([None, '1', '2' ,'3'], history)
286
class TestMultipleRevisionSources(TestCaseWithTransport):
287
"""Tests for the MultipleRevisionSources adapter."""
289
def test_get_revision_graph_merges_ghosts(self):
290
# when we ask for the revision graph for B, which
291
# is in repo 1 with a ghost of A, and which is not
292
# in repo 2, which has A, the revision_graph()
293
# should return A and B both.
294
tree_1 = self.make_branch_and_tree('1')
295
tree_1.add_pending_merge('A')
296
tree_1.commit('foo', rev_id='B', allow_pointless=True)
297
tree_2 = self.make_branch_and_tree('2')
298
tree_2.commit('bar', rev_id='A', allow_pointless=True)
299
source = MultipleRevisionSources(tree_1.branch.repository,
300
tree_2.branch.repository)
301
self.assertEqual({'B':['A'],
303
source.get_revision_graph('B'))