31
31
class TestMissing(TestCaseWithTransport):
33
def assertUnmerged(self, expected, source, target, restrict='all'):
34
unmerged = missing.find_unmerged(source, target, restrict=restrict)
33
def assertUnmerged(self, expected, source, target, restrict='all',
35
unmerged = missing.find_unmerged(source, target, restrict=restrict,
35
37
self.assertEqual(expected, unmerged)
37
39
def test_find_unmerged(self):
38
40
original_tree = self.make_branch_and_tree('original')
39
41
original = original_tree.branch
43
45
merger = merger_tree.branch
44
46
self.assertUnmerged(([], []), original, puller)
45
47
original_tree.commit('a', rev_id='a')
46
self.assertUnmerged(([(1, 'a')], []), original, puller)
48
self.assertUnmerged(([('1', 'a')], []), original, puller)
47
49
puller_tree.pull(original)
48
50
self.assertUnmerged(([], []), original, puller)
49
51
merger_tree.pull(original)
50
52
original_tree.commit('b', rev_id='b')
51
53
original_tree.commit('c', rev_id='c')
52
self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
54
self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
56
self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
57
original, puller, backward=True)
55
59
puller_tree.pull(original)
56
60
self.assertUnmerged(([], []), original, puller)
57
self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
61
self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
59
63
merger_tree.merge_from_branch(original)
60
self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
64
self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
62
66
merger_tree.commit('d', rev_id='d')
63
self.assertUnmerged(([], [(2, 'd')]), original, merger)
67
self.assertUnmerged(([], [('2', 'd')]), original, merger)
65
69
def test_iter_log_revisions(self):
66
70
base_tree = self.make_branch_and_tree('base')
86
90
base_extra, child_extra = missing.find_unmerged(base_tree.branch,
88
results = list(iter_log_revisions(base_extra,
92
results = list(iter_log_revisions(base_extra,
89
93
base_tree.branch.repository,
91
95
self.assertEqual([], results)
98
102
r0,r1,r2,r3 = results
100
self.assertEqual((2, 'c-2'), (r0.revno, r0.rev.revision_id))
101
self.assertEqual((3, 'c-3'), (r1.revno, r1.rev.revision_id))
102
self.assertEqual((4, 'c-4'), (r2.revno, r2.rev.revision_id))
103
self.assertEqual((5, 'c-5'), (r3.revno, r3.rev.revision_id))
104
self.assertEqual([('2', 'c-2'), ('3', 'c-3'),
105
('4', 'c-4'), ('5', 'c-5'),],
106
[(r.revno, r.rev.revision_id) for r in results])
105
108
delta0 = r0.delta
106
109
self.assertNotEqual(None, delta0)
135
138
class TestFindUnmerged(tests.TestCaseWithTransport):
137
140
def assertUnmerged(self, local, remote, local_branch, remote_branch,
141
restrict, include_merges=False,
139
143
"""Check the output of find_unmerged_mainline_revisions"""
140
144
local_extra, remote_extra = missing.find_unmerged(
141
local_branch, remote_branch, restrict)
145
local_branch, remote_branch, restrict,
146
include_merges=include_merges,
142
148
self.assertEqual(local, local_extra)
143
149
self.assertEqual(remote, remote_extra)
154
160
rev1 = tree.commit('one')
155
161
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
156
162
rev2 = tree2.commit('two')
158
self.addCleanup(tree.unlock)
160
self.addCleanup(tree2.unlock)
161
self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
162
self.assertUnmerged([(2, rev2)], [], tree2.branch, tree.branch, 'all')
163
self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch, 'all')
164
self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch, 'all')
164
166
def test_restrict(self):
165
167
tree = self.make_branch_and_tree('tree')
166
168
rev1 = tree.commit('one')
167
169
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
168
170
rev2 = tree2.commit('two')
170
self.addCleanup(tree.unlock)
172
self.addCleanup(tree2.unlock)
173
self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
171
self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch, 'all')
174
172
self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
175
self.assertUnmerged(None, [(2, rev2)], tree.branch, tree2.branch,
173
self.assertUnmerged(None, [('2', rev2)], tree.branch, tree2.branch,
178
176
def test_merged(self):
184
182
tree.merge_from_branch(tree2.branch)
185
183
rev4 = tree.commit('four')
188
self.addCleanup(tree.unlock)
190
self.addCleanup(tree2.unlock)
192
self.assertUnmerged([(2, rev4)], [], tree.branch, tree2.branch, 'all')
185
self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch, 'all')
187
def test_include_merges(self):
188
tree = self.make_branch_and_tree('tree')
189
rev1 = tree.commit('one', rev_id='rev1')
191
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
192
rev2 = tree2.commit('two', rev_id='rev2')
193
rev3 = tree2.commit('three', rev_id='rev3')
195
tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
196
rev4 = tree3.commit('four', rev_id='rev4')
197
rev5 = tree3.commit('five', rev_id='rev5')
199
tree2.merge_from_branch(tree3.branch)
200
rev6 = tree2.commit('six', rev_id='rev6')
202
self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3',0 ),
204
('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
206
tree.branch, tree2.branch, 'all',
209
self.assertUnmerged([], [('4', 'rev6', 0),
210
('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
211
('3', 'rev3',0 ), ('2', 'rev2', 0),
213
tree.branch, tree2.branch, 'all',