1
# (C) 2005 Canonical Ltd
1
# Copyright (C) 2005 Canonical Ltd
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
24
from bzrlib.branch import Branch
21
25
from bzrlib.errors import NoSuchRevision
22
from bzrlib.commit import commit
23
26
from bzrlib.graph import Graph
24
27
from bzrlib.revision import (find_present_ancestors, combined_graph,
26
is_ancestor, MultipleRevisionSources)
27
from bzrlib.tests import TestCaseWithTransport
29
is_ancestor, MultipleRevisionSources,
31
from bzrlib.tests import TestCase, TestCaseWithTransport
28
32
from bzrlib.trace import mutter
29
33
from bzrlib.workingtree import WorkingTree
35
# We're allowed to test deprecated interfaces
36
warnings.filterwarnings('ignore',
37
'.*get_intervening_revisions was deprecated',
39
r'bzrlib\.tests\.test_revision')
31
41
# XXX: Make this a method of a merge base case
32
42
def make_branches(self):
33
43
"""Create two branches
60
70
tree2.commit("Commit four", rev_id="b@u-0-3")
61
71
tree2.commit("Commit five", rev_id="b@u-0-4")
62
72
revisions_2 = br2.revision_history()
73
self.assertEquals(revisions_2[-1], 'b@u-0-4')
65
tree1.add_pending_merge(revisions_2[4])
66
self.assertEquals(revisions_2[4], 'b@u-0-4')
75
tree1.merge_from_branch(br2)
67
76
tree1.commit("Commit six", rev_id="a@u-0-3")
68
77
tree1.commit("Commit seven", rev_id="a@u-0-4")
69
78
tree2.commit("Commit eight", rev_id="b@u-0-5")
79
self.assertEquals(br2.revision_history()[-1], 'b@u-0-5')
72
tree1.add_pending_merge(br2.revision_history()[5])
81
tree1.merge_from_branch(br2)
73
82
tree1.commit("Commit nine", rev_id="a@u-0-5")
74
# DO NOT FETCH HERE - we WANT a GHOST.
76
tree2.add_pending_merge(br1.revision_history()[4])
83
# DO NOT MERGE HERE - we WANT a GHOST.
84
tree2.add_parent_tree_id(br1.revision_history()[4])
77
85
tree2.commit("Commit ten - ghost merge", rev_id="b@u-0-6")
140
148
class TestIntermediateRevisions(TestCaseWithTransport):
143
from bzrlib.commit import commit
144
151
TestCaseWithTransport.setUp(self)
145
152
self.br1, self.br2 = make_branches(self)
146
153
wt1 = self.br1.bzrdir.open_workingtree()
149
156
wt2.commit("Commit twelve", rev_id="b@u-0-8")
150
157
wt2.commit("Commit thirtteen", rev_id="b@u-0-9")
152
self.br1.fetch(self.br2)
153
wt1.add_pending_merge(self.br2.revision_history()[6])
159
wt1.merge_from_branch(self.br2)
154
160
wt1.commit("Commit fourtten", rev_id="a@u-0-6")
156
self.br2.fetch(self.br1)
157
wt2.add_pending_merge(self.br1.revision_history()[6])
162
wt2.merge_from_branch(self.br1)
158
163
wt2.commit("Commit fifteen", rev_id="b@u-0-10")
160
165
from bzrlib.revision import MultipleRevisionSources
216
221
self.assertTrue(common_ancestor(revisions_2[6], revisions[5], sources),
217
222
(revisions[4], revisions_2[5]))
218
223
self.assertEqual(None, common_ancestor(None, revisions[5], sources))
224
self.assertEqual(NULL_REVISION,
225
common_ancestor(NULL_REVISION, NULL_REVISION, sources))
226
self.assertEqual(NULL_REVISION,
227
common_ancestor(revisions[0], NULL_REVISION, sources))
228
self.assertEqual(NULL_REVISION,
229
common_ancestor(NULL_REVISION, revisions[0], sources))
220
231
def test_combined(self):
221
232
"""combined_graph
224
235
br1, br2 = make_branches(self)
225
236
source = MultipleRevisionSources(br1.repository, br2.repository)
226
combined_1 = combined_graph(br1.last_revision(),
237
combined_1 = combined_graph(br1.last_revision(),
227
238
br2.last_revision(), source)
228
239
combined_2 = combined_graph(br2.last_revision(),
229
240
br1.last_revision(), source)
276
287
# in repo 2, which has A, the revision_graph()
277
288
# should return A and B both.
278
289
tree_1 = self.make_branch_and_tree('1')
279
tree_1.add_pending_merge('A')
290
tree_1.set_parent_ids(['A'], allow_leftmost_as_ghost=True)
280
291
tree_1.commit('foo', rev_id='B', allow_pointless=True)
281
292
tree_2 = self.make_branch_and_tree('2')
282
293
tree_2.commit('bar', rev_id='A', allow_pointless=True)