~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_missing.py

  • Committer: Vincent Ladeuil
  • Date: 2011-08-12 09:49:24 UTC
  • mfrom: (6015.9.10 2.4)
  • mto: This revision was merged to the branch mainline in revision 6066.
  • Revision ID: v.ladeuil+lp@free.fr-20110812094924-knc5s0g7vs31a2f1
Merge 2.4 into trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 Canonical Ltd
 
1
# Copyright (C) 2005-2009, 2011 Canonical Ltd
2
2
#
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
12
12
#
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
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
 
 
17
 
import os
18
 
 
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
16
 
20
17
from bzrlib import (
21
18
    missing,
25
22
    iter_log_revisions,
26
23
    )
27
24
from bzrlib.tests import TestCaseWithTransport
28
 
from bzrlib.workingtree import WorkingTree
29
25
 
30
26
 
31
27
class TestMissing(TestCaseWithTransport):
32
28
 
33
 
    def assertUnmerged(self, expected, source, target, restrict='all'):
34
 
        unmerged = missing.find_unmerged(source, target, restrict=restrict)
 
29
    def assertUnmerged(self, expected, source, target, restrict='all',
 
30
                       backward=False):
 
31
        unmerged = missing.find_unmerged(source, target, restrict=restrict,
 
32
                                         backward=backward)
35
33
        self.assertEqual(expected, unmerged)
36
34
 
37
35
    def test_find_unmerged(self):
51
49
        original_tree.commit('c', rev_id='c')
52
50
        self.assertUnmerged(([('2', 'b'), ('3', 'c')], []),
53
51
                            original, puller)
 
52
        self.assertUnmerged(([('3', 'c'), ('2', 'b')], []),
 
53
                            original, puller, backward=True)
54
54
 
55
55
        puller_tree.pull(original)
56
56
        self.assertUnmerged(([], []), original, puller)
134
134
class TestFindUnmerged(tests.TestCaseWithTransport):
135
135
 
136
136
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
137
 
                       restrict, include_merges=False):
 
137
            restrict='all', include_merges=False, backward=False,
 
138
            local_revid_range=None, remote_revid_range=None):
138
139
        """Check the output of find_unmerged_mainline_revisions"""
139
140
        local_extra, remote_extra = missing.find_unmerged(
140
 
                                        local_branch, remote_branch, restrict,
141
 
                                        include_merges=include_merges)
 
141
            local_branch, remote_branch, restrict,
 
142
            include_merges=include_merges, backward=backward,
 
143
            local_revid_range=local_revid_range,
 
144
            remote_revid_range=remote_revid_range)
142
145
        self.assertEqual(local, local_extra)
143
146
        self.assertEqual(remote, remote_extra)
144
147
 
147
150
        rev1 = tree.commit('one')
148
151
        tree.lock_read()
149
152
        self.addCleanup(tree.unlock)
150
 
        self.assertUnmerged([], [], tree.branch, tree.branch, 'all')
 
153
        self.assertUnmerged([], [], tree.branch, tree.branch)
 
154
        self.assertUnmerged([], [], tree.branch, tree.branch,
 
155
            local_revid_range=(rev1, rev1))
151
156
 
152
157
    def test_one_ahead(self):
153
158
        tree = self.make_branch_and_tree('tree')
154
159
        rev1 = tree.commit('one')
155
160
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
156
161
        rev2 = tree2.commit('two')
157
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch, 'all')
158
 
        self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch, 'all')
 
162
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
 
163
        self.assertUnmerged([('2', rev2)], [], tree2.branch, tree.branch)
159
164
 
160
165
    def test_restrict(self):
161
166
        tree = self.make_branch_and_tree('tree')
162
167
        rev1 = tree.commit('one')
163
168
        tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
164
169
        rev2 = tree2.commit('two')
165
 
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch, 'all')
 
170
        self.assertUnmerged([], [('2', rev2)], tree.branch, tree2.branch)
166
171
        self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
167
172
        self.assertUnmerged(None, [('2', rev2)], tree.branch, tree2.branch,
168
173
                                               'remote')
176
181
        tree.merge_from_branch(tree2.branch)
177
182
        rev4 = tree.commit('four')
178
183
 
179
 
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch, 'all')
 
184
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch)
 
185
        self.assertUnmerged([('2', rev4)], [], tree.branch, tree2.branch,
 
186
            local_revid_range=(rev4, rev4))
 
187
        self.assertUnmerged([], [], tree.branch, tree2.branch,
 
188
            local_revid_range=(rev1, rev1))
180
189
 
181
190
    def test_include_merges(self):
182
191
        tree = self.make_branch_and_tree('tree')
193
202
        tree2.merge_from_branch(tree3.branch)
194
203
        rev6 = tree2.commit('six', rev_id='rev6')
195
204
 
196
 
        self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3',0 ),
 
205
        self.assertUnmerged([], [('2', 'rev2', 0), ('3', 'rev3', 0),
197
206
                                 ('4', 'rev6', 0),
198
207
                                 ('3.1.1', 'rev4', 1), ('3.1.2', 'rev5', 1),
199
208
                                 ],
200
 
                            tree.branch, tree2.branch, 'all',
 
209
                            tree.branch, tree2.branch,
201
210
                            include_merges=True)
202
211
 
203
 
    # TODO: test_dont_include_already_merged_merges ?
 
212
        self.assertUnmerged([], [('4', 'rev6', 0),
 
213
                                 ('3.1.2', 'rev5', 1), ('3.1.1', 'rev4', 1),
 
214
                                 ('3', 'rev3', 0), ('2', 'rev2', 0),
 
215
                                 ],
 
216
                            tree.branch, tree2.branch,
 
217
                            include_merges=True,
 
218
                            backward=True)
 
219
 
 
220
        self.assertUnmerged([], [('4', 'rev6', 0)],
 
221
            tree.branch, tree2.branch,
 
222
            include_merges=True, remote_revid_range=(rev6, rev6))
 
223
 
 
224
        self.assertUnmerged([], [('3', 'rev3', 0), ('3.1.1', 'rev4', 1)],
 
225
                    tree.branch, tree2.branch,
 
226
                    include_merges=True, remote_revid_range=(rev3, rev4))
 
227
 
 
228
        self.assertUnmerged([], [('4', 'rev6', 0), ('3.1.2', 'rev5', 1)],
 
229
                    tree.branch, tree2.branch,
 
230
                    include_merges=True, remote_revid_range=(rev5, rev6))
 
231
 
 
232
    def test_revision_range(self):
 
233
        local = self.make_branch_and_tree('local')
 
234
        lrevid1 = local.commit('one')
 
235
        remote = local.bzrdir.sprout('remote').open_workingtree()
 
236
        rrevid2 = remote.commit('two')
 
237
        rrevid3 = remote.commit('three')
 
238
        rrevid4 = remote.commit('four')
 
239
        lrevid2 = local.commit('two')
 
240
        lrevid3 = local.commit('three')
 
241
        lrevid4 = local.commit('four')
 
242
        local_extra = [('2', lrevid2), ('3', lrevid3), ('4', lrevid4)]
 
243
        remote_extra = [('2', rrevid2), ('3', rrevid3), ('4', rrevid4)]
 
244
 
 
245
        # control
 
246
        self.assertUnmerged(local_extra, remote_extra,
 
247
            local.branch, remote.branch)
 
248
        self.assertUnmerged(local_extra, remote_extra,
 
249
            local.branch, remote.branch, local_revid_range=(None, None),
 
250
            remote_revid_range=(None, None))
 
251
 
 
252
        # exclude local revisions
 
253
        self.assertUnmerged([('2', lrevid2)], remote_extra,
 
254
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid2))
 
255
        self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], remote_extra,
 
256
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid3))
 
257
        self.assertUnmerged([('2', lrevid2), ('3', lrevid3)], None,
 
258
            local.branch, remote.branch, 'local',
 
259
            local_revid_range=(lrevid2, lrevid3))
 
260
 
 
261
        # exclude remote revisions
 
262
        self.assertUnmerged(local_extra, [('2', rrevid2)],
 
263
            local.branch, remote.branch, remote_revid_range=(None, rrevid2))
 
264
        self.assertUnmerged(local_extra, [('2', rrevid2)],
 
265
            local.branch, remote.branch, remote_revid_range=(lrevid1, rrevid2))
 
266
        self.assertUnmerged(local_extra, [('2', rrevid2)],
 
267
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid2))
 
268
        self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
 
269
            local.branch, remote.branch, remote_revid_range=(None, rrevid3))
 
270
        self.assertUnmerged(local_extra, [('2', rrevid2), ('3', rrevid3)],
 
271
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid3))
 
272
        self.assertUnmerged(local_extra, [('3', rrevid3)],
 
273
            local.branch, remote.branch, remote_revid_range=(rrevid3, rrevid3))
 
274
        self.assertUnmerged(None, [('2', rrevid2), ('3', rrevid3)],
 
275
            local.branch, remote.branch, 'remote',
 
276
            remote_revid_range=(rrevid2, rrevid3))
 
277
 
 
278
        # exclude local and remote revisions
 
279
        self.assertUnmerged([('3', lrevid3)], [('3', rrevid3)],
 
280
            local.branch, remote.branch, local_revid_range=(lrevid3, lrevid3),
 
281
            remote_revid_range=(rrevid3, rrevid3))