28
31
class TestMissing(TestCaseWithTransport):
33
def assertUnmerged(self, expected, source, target, restrict='all'):
34
unmerged = missing.find_unmerged(source, target, restrict=restrict)
35
self.assertEqual(expected, unmerged)
30
37
def test_find_unmerged(self):
31
38
original_tree = self.make_branch_and_tree('original')
32
39
original = original_tree.branch
34
41
puller = puller_tree.branch
35
42
merger_tree = self.make_branch_and_tree('merger')
36
43
merger = merger_tree.branch
37
self.assertEqual(find_unmerged(original, puller), ([], []))
44
self.assertUnmerged(([], []), original, puller)
38
45
original_tree.commit('a', rev_id='a')
39
self.assertEqual(find_unmerged(original, puller), ([(1, u'a')], []))
46
self.assertUnmerged(([(1, 'a')], []), original, puller)
40
47
puller_tree.pull(original)
41
self.assertEqual(find_unmerged(original, puller), ([], []))
48
self.assertUnmerged(([], []), original, puller)
42
49
merger_tree.pull(original)
43
50
original_tree.commit('b', rev_id='b')
44
51
original_tree.commit('c', rev_id='c')
45
self.assertEqual(find_unmerged(original, puller), ([(2, u'b'),
52
self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
48
55
puller_tree.pull(original)
49
self.assertEqual(find_unmerged(original, puller), ([], []))
50
self.assertEqual(find_unmerged(original, merger), ([(2, u'b'),
56
self.assertUnmerged(([], []), original, puller)
57
self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
52
59
merger_tree.merge_from_branch(original)
53
self.assertEqual(find_unmerged(original, merger), ([(2, u'b'),
60
self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
55
62
merger_tree.commit('d', rev_id='d')
56
self.assertEqual(find_unmerged(original, merger), ([], [(2, 'd')]))
63
self.assertUnmerged(([], [(2, 'd')]), original, merger)
58
65
def test_iter_log_revisions(self):
59
66
base_tree = self.make_branch_and_tree('base')
76
83
child_tree.rename_one('b', 'c')
77
84
child_tree.commit('rename b=>c', rev_id='c-5')
79
base_extra, child_extra = find_unmerged(base_tree.branch,
86
base_extra, child_extra = missing.find_unmerged(base_tree.branch,
81
88
results = list(iter_log_revisions(base_extra,
82
89
base_tree.branch.repository,
123
130
self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
125
132
self.assertEqual([], delta3.modified)
135
class TestFindUnmerged(tests.TestCaseWithTransport):
137
def assertUnmerged(self, local, remote, local_branch, remote_branch,
139
"""Check the output of find_unmerged_mainline_revisions"""
140
local_extra, remote_extra = missing.find_unmerged(
141
local_branch, remote_branch, restrict)
142
self.assertEqual(local, local_extra)
143
self.assertEqual(remote, remote_extra)
145
def test_same_branch(self):
146
tree = self.make_branch_and_tree('tree')
147
rev1 = tree.commit('one')
149
self.addCleanup(tree.unlock)
150
self.assertUnmerged([], [], tree.branch, tree.branch, 'all')
152
def test_one_ahead(self):
153
tree = self.make_branch_and_tree('tree')
154
rev1 = tree.commit('one')
155
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
156
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')
164
def test_restrict(self):
165
tree = self.make_branch_and_tree('tree')
166
rev1 = tree.commit('one')
167
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
168
rev2 = tree2.commit('two')
170
self.addCleanup(tree.unlock)
172
self.addCleanup(tree2.unlock)
173
self.assertUnmerged([], [(2, rev2)], tree.branch, tree2.branch, 'all')
174
self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
175
self.assertUnmerged(None, [(2, rev2)], tree.branch, tree2.branch,
178
def test_merged(self):
179
tree = self.make_branch_and_tree('tree')
180
rev1 = tree.commit('one')
181
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
182
rev2 = tree2.commit('two')
183
rev3 = tree2.commit('three')
184
tree.merge_from_branch(tree2.branch)
185
rev4 = tree.commit('four')
188
self.addCleanup(tree.unlock)
190
self.addCleanup(tree2.unlock)
192
self.assertUnmerged([(2, rev4)], [], tree.branch, tree2.branch, 'all')