~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_missing.py

Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
 
31
31
class TestMissing(TestCaseWithTransport):
32
32
 
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',
 
34
                       backward=False):
 
35
        unmerged = missing.find_unmerged(source, target, restrict=restrict,
 
36
                                         backward=backward)
35
37
        self.assertEqual(expected, unmerged)
36
 
            
 
38
 
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')], []),
53
55
                            original, puller)
 
56
        self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
 
57
                            original, puller, backward=True)
54
58
 
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')], []),
58
62
                            original, merger)
59
63
        merger_tree.merge_from_branch(original)
60
 
        self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
 
64
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
61
65
                            original, merger)
62
66
        merger_tree.commit('d', rev_id='d')
63
 
        self.assertUnmerged(([], [(2, 'd')]), original, merger)
 
67
        self.assertUnmerged(([], [('2', 'd')]), original, merger)
64
68
 
65
69
    def test_iter_log_revisions(self):
66
70
        base_tree = self.make_branch_and_tree('base')
85
89
 
86
90
        base_extra, child_extra = missing.find_unmerged(base_tree.branch,
87
91
                                                        child_tree.branch)
88
 
        results = list(iter_log_revisions(base_extra, 
 
92
        results = list(iter_log_revisions(base_extra,
89
93
                            base_tree.branch.repository,
90
94
                            verbose=True))
91
95
        self.assertEqual([], results)
97
101
 
98
102
        r0,r1,r2,r3 = results
99
103
 
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])
104
107
 
105
108
        delta0 = r0.delta
106
109
        self.assertNotEqual(None, delta0)
135
138
class TestFindUnmerged(tests.TestCaseWithTransport):
136
139
 
137
140
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
138
 
                       restrict):
 
141
                       restrict, include_merges=False,
 
142
                       backward=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,
 
147
                                        backward=backward)
142
148
        self.assertEqual(local, local_extra)
143
149
        self.assertEqual(remote, remote_extra)
144
150
 
154
160
        rev1 = tree.commit('one')
155
161
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
156
162
        rev2 = tree2.commit('two')
157
 
        tree.lock_read()
158
 
        self.addCleanup(tree.unlock)
159
 
        tree2.lock_read()
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')
163
165
 
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')
169
 
        tree.lock_read()
170
 
        self.addCleanup(tree.unlock)
171
 
        tree2.lock_read()
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,
176
174
                                               'remote')
177
175
 
178
176
    def test_merged(self):
184
182
        tree.merge_from_branch(tree2.branch)
185
183
        rev4 = tree.commit('four')
186
184
 
187
 
        tree.lock_read()
188
 
        self.addCleanup(tree.unlock)
189
 
        tree2.lock_read()
190
 
        self.addCleanup(tree2.unlock)
191
 
 
192
 
        self.assertUnmerged([(2, rev4)], [], tree.branch, tree2.branch, 'all')
 
185
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch, 'all')
 
186
 
 
187
    def test_include_merges(self):
 
188
        tree = self.make_branch_and_tree('tree')
 
189
        rev1 = tree.commit('one', rev_id='rev1')
 
190
 
 
191
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
 
192
        rev2 = tree2.commit('two', rev_id='rev2')
 
193
        rev3 = tree2.commit('three', rev_id='rev3')
 
194
 
 
195
        tree3 = tree2.bzrdir.sprout('tree3').open_workingtree()
 
196
        rev4 = tree3.commit('four', rev_id='rev4')
 
197
        rev5 = tree3.commit('five', rev_id='rev5')
 
198
 
 
199
        tree2.merge_from_branch(tree3.branch)
 
200
        rev6 = tree2.commit('six', rev_id='rev6')
 
201
 
 
202
        self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3',0 ),
 
203
                                 ('4', 'rev6', 0),
 
204
                                 ('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
 
205
                                 ],
 
206
                            tree.branch, tree2.branch, 'all',
 
207
                            include_merges=True)
 
208
 
 
209
        self.assertUnmerged([], [('4', 'rev6', 0),
 
210
                                 ('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
 
211
                                 ('3', 'rev3',0 ), ('2', 'rev2', 0),
 
212
                                 ],
 
213
                            tree.branch, tree2.branch, 'all',
 
214
                            include_merges=True,
 
215
                            backward=True)