43
37
puller = puller_tree.branch
44
38
merger_tree = self.make_branch_and_tree('merger')
45
39
merger = merger_tree.branch
46
self.assertUnmerged(([], []), original, puller)
40
self.assertEqual(find_unmerged(original, puller), ([], []))
47
41
original_tree.commit('a', rev_id='a')
48
self.assertUnmerged(([('1', 'a')], []), original, puller)
42
self.assertEqual(find_unmerged(original, puller), ([(1, u'a')], []))
49
43
puller_tree.pull(original)
50
self.assertUnmerged(([], []), original, puller)
44
self.assertEqual(find_unmerged(original, puller), ([], []))
51
45
merger_tree.pull(original)
52
46
original_tree.commit('b', rev_id='b')
53
47
original_tree.commit('c', rev_id='c')
54
self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
56
self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
57
original, puller, backward=True)
48
self.assertEqual(find_unmerged(original, puller), ([(2, u'b'),
59
51
puller_tree.pull(original)
60
self.assertUnmerged(([], []), original, puller)
61
self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
63
merger_tree.merge_from_branch(original)
64
self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
52
self.assertEqual(find_unmerged(original, puller), ([], []))
53
self.assertEqual(find_unmerged(original, merger), ([(2, u'b'),
55
merge(['original', -1], [None, None], this_dir='merger')
56
self.assertEqual(find_unmerged(original, merger), ([(2, u'b'),
66
58
merger_tree.commit('d', rev_id='d')
67
self.assertUnmerged(([], [('2', 'd')]), original, merger)
59
self.assertEqual(find_unmerged(original, merger), ([], [(2, 'd')]))
61
def test_iter_log_data(self):
62
base_tree = self.make_branch_and_tree('base')
63
self.build_tree(['base/a'])
64
base_tree.add(['a'], ['a-id'])
65
base_tree.commit('add a', rev_id='b-1')
67
child_tree = base_tree.bzrdir.sprout('child').open_workingtree()
69
self.build_tree(['child/b'])
70
child_tree.add(['b'], ['b-id'])
71
child_tree.commit('adding b', rev_id='c-2')
73
child_tree.remove(['a'])
74
child_tree.commit('removing a', rev_id='c-3')
76
self.build_tree_contents([('child/b', 'new contents for b\n')])
77
child_tree.commit('modifying b', rev_id='c-4')
79
child_tree.rename_one('b', 'c')
80
child_tree.commit('rename b=>c', rev_id='c-5')
82
base_extra, child_extra = find_unmerged(base_tree.branch,
84
results = list(self.applyDeprecated(zero_seventeen, iter_log_data,
86
base_tree.branch.repository,
88
self.assertEqual([], results)
90
results = list(self.applyDeprecated(zero_seventeen, iter_log_data,
92
child_tree.branch.repository,
94
self.assertEqual(4, len(results))
98
self.assertEqual((2, 'c-2'), (r0[0], r0[1].revision_id))
99
self.assertEqual((3, 'c-3'), (r1[0], r1[1].revision_id))
100
self.assertEqual((4, 'c-4'), (r2[0], r2[1].revision_id))
101
self.assertEqual((5, 'c-5'), (r3[0], r3[1].revision_id))
104
self.assertNotEqual(None, delta0)
105
self.assertEqual([('b', 'b-id', 'file')], delta0.added)
106
self.assertEqual([], delta0.removed)
107
self.assertEqual([], delta0.renamed)
108
self.assertEqual([], delta0.modified)
111
self.assertNotEqual(None, delta1)
112
self.assertEqual([], delta1.added)
113
self.assertEqual([('a', 'a-id', 'file')], delta1.removed)
114
self.assertEqual([], delta1.renamed)
115
self.assertEqual([], delta1.modified)
118
self.assertNotEqual(None, delta2)
119
self.assertEqual([], delta2.added)
120
self.assertEqual([], delta2.removed)
121
self.assertEqual([], delta2.renamed)
122
self.assertEqual([('b', 'b-id', 'file', True, False)], delta2.modified)
125
self.assertNotEqual(None, delta3)
126
self.assertEqual([], delta3.added)
127
self.assertEqual([], delta3.removed)
128
self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
130
self.assertEqual([], delta3.modified)
69
132
def test_iter_log_revisions(self):
70
133
base_tree = self.make_branch_and_tree('base')
133
197
self.assertEqual([('b', 'c', 'b-id', 'file', False, False)],
135
199
self.assertEqual([], delta3.modified)
138
class TestFindUnmerged(tests.TestCaseWithTransport):
140
def assertUnmerged(self, local, remote, local_branch, remote_branch,
141
restrict='all', include_merges=False, backward=False,
142
local_revid_range=None, remote_revid_range=None):
143
"""Check the output of find_unmerged_mainline_revisions"""
144
local_extra, remote_extra = missing.find_unmerged(
145
local_branch, remote_branch, restrict,
146
include_merges=include_merges, backward=backward,
147
local_revid_range=local_revid_range,
148
remote_revid_range=remote_revid_range)
149
self.assertEqual(local, local_extra)
150
self.assertEqual(remote, remote_extra)
152
def test_same_branch(self):
153
tree = self.make_branch_and_tree('tree')
154
rev1 = tree.commit('one')
156
self.addCleanup(tree.unlock)
157
self.assertUnmerged([], [], tree.branch, tree.branch)
158
self.assertUnmerged([], [], tree.branch, tree.branch,
159
local_revid_range=(rev1, rev1))
161
def test_one_ahead(self):
162
tree = self.make_branch_and_tree('tree')
163
rev1 = tree.commit('one')
164
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
165
rev2 = tree2.commit('two')
166
self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
167
self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch)
169
def test_restrict(self):
170
tree = self.make_branch_and_tree('tree')
171
rev1 = tree.commit('one')
172
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
173
rev2 = tree2.commit('two')
174
self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
175
self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
176
self.assertUnmerged(None, [('2', rev2)], tree.branch, tree2.branch,
179
def test_merged(self):
180
tree = self.make_branch_and_tree('tree')
181
rev1 = tree.commit('one')
182
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
183
rev2 = tree2.commit('two')
184
rev3 = tree2.commit('three')
185
tree.merge_from_branch(tree2.branch)
186
rev4 = tree.commit('four')
188
self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch)
189
self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch,
190
local_revid_range=(rev4, rev4))
191
self.assertUnmerged([], [], tree.branch, tree2.branch,
192
local_revid_range=(rev1, rev1))
194
def test_include_merges(self):
195
tree = self.make_branch_and_tree('tree')
196
rev1 = tree.commit('one', rev_id='rev1')
198
tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
199
rev2 = tree2.commit('two', rev_id='rev2')
200
rev3 = tree2.commit('three', rev_id='rev3')
202
tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
203
rev4 = tree3.commit('four', rev_id='rev4')
204
rev5 = tree3.commit('five', rev_id='rev5')
206
tree2.merge_from_branch(tree3.branch)
207
rev6 = tree2.commit('six', rev_id='rev6')
209
self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3', 0),
211
('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
213
tree.branch, tree2.branch,
216
self.assertUnmerged([], [('4', 'rev6', 0),
217
('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
218
('3', 'rev3', 0), ('2', 'rev2', 0),
220
tree.branch, tree2.branch,
224
self.assertUnmerged([], [('4', 'rev6', 0)],
225
tree.branch, tree2.branch,
226
include_merges=True, remote_revid_range=(rev6, rev6))
228
self.assertUnmerged([], [('3', 'rev3', 0), ('3.1.1', 'rev4', 1)],
229
tree.branch, tree2.branch,
230
include_merges=True, remote_revid_range=(rev3, rev4))
232
self.assertUnmerged([], [('4', 'rev6', 0), ('3.1.2', 'rev5', 1)],
233
tree.branch, tree2.branch,
234
include_merges=True, remote_revid_range=(rev5, rev6))
236
def test_revision_range(self):
237
local = self.make_branch_and_tree('local')
238
lrevid1 = local.commit('one')
239
remote = local.bzrdir.sprout('remote').open_workingtree()
240
rrevid2 = remote.commit('two')
241
rrevid3 = remote.commit('three')
242
rrevid4 = remote.commit('four')
243
lrevid2 = local.commit('two')
244
lrevid3 = local.commit('three')
245
lrevid4 = local.commit('four')
246
local_extra = [('2', lrevid2), ('3', lrevid3), ('4', lrevid4)]
247
remote_extra = [('2', rrevid2), ('3', rrevid3), ('4', rrevid4)]
250
self.assertUnmerged(local_extra, remote_extra,
251
local.branch, remote.branch)
252
self.assertUnmerged(local_extra, remote_extra,
253
local.branch, remote.branch, local_revid_range=(None, None),
254
remote_revid_range=(None, None))
256
# exclude local revisions
257
self.assertUnmerged([('2', lrevid2)], remote_extra,
258
local.branch, remote.branch, local_revid_range=(lrevid2, lrevid2))
259
self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], remote_extra,
260
local.branch, remote.branch, local_revid_range=(lrevid2, lrevid3))
261
self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], None,
262
local.branch, remote.branch, 'local',
263
local_revid_range=(lrevid2, lrevid3))
265
# exclude remote revisions
266
self.assertUnmerged(local_extra, [('2', rrevid2)],
267
local.branch, remote.branch, remote_revid_range=(None, rrevid2))
268
self.assertUnmerged(local_extra, [('2', rrevid2)],
269
local.branch, remote.branch, remote_revid_range=(lrevid1, rrevid2))
270
self.assertUnmerged(local_extra, [('2', rrevid2)],
271
local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid2))
272
self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
273
local.branch, remote.branch, remote_revid_range=(None, rrevid3))
274
self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
275
local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid3))
276
self.assertUnmerged(local_extra, [('3', rrevid3)],
277
local.branch, remote.branch, remote_revid_range=(rrevid3, rrevid3))
278
self.assertUnmerged(None, [('2', rrevid2), ('3', rrevid3)],
279
local.branch, remote.branch, 'remote',
280
remote_revid_range=(rrevid2, rrevid3))
282
# exclude local and remote revisions
283
self.assertUnmerged([('3', lrevid3)], [('3', rrevid3)],
284
local.branch, remote.branch, local_revid_range=(lrevid3, lrevid3),
285
remote_revid_range=(rrevid3, rrevid3))