/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/test_missing.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2005-2009, 2011 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
from .. import (
 
18
    missing,
 
19
    tests,
 
20
    )
 
21
from ..missing import (
 
22
    iter_log_revisions,
 
23
    )
 
24
from . import TestCaseWithTransport
 
25
 
 
26
 
 
27
class TestMissing(TestCaseWithTransport):
 
28
 
 
29
    def assertUnmerged(self, expected, source, target, restrict='all',
 
30
                       backward=False):
 
31
        unmerged = missing.find_unmerged(source, target, restrict=restrict,
 
32
                                         backward=backward)
 
33
        self.assertEqual(expected, unmerged)
 
34
 
 
35
    def test_find_unmerged(self):
 
36
        original_tree = self.make_branch_and_tree('original')
 
37
        original = original_tree.branch
 
38
        puller_tree = self.make_branch_and_tree('puller')
 
39
        puller = puller_tree.branch
 
40
        merger_tree = self.make_branch_and_tree('merger')
 
41
        merger = merger_tree.branch
 
42
        self.assertUnmerged(([], []), original, puller)
 
43
        original_tree.commit('a', rev_id=b'a')
 
44
        self.assertUnmerged(([('1', b'a', 0)], []), original, puller)
 
45
        puller_tree.pull(original)
 
46
        self.assertUnmerged(([], []), original, puller)
 
47
        merger_tree.pull(original)
 
48
        original_tree.commit('b', rev_id=b'b')
 
49
        original_tree.commit('c', rev_id=b'c')
 
50
        self.assertUnmerged(([('2', b'b', 0), ('3', b'c', 0)], []),
 
51
                            original, puller)
 
52
        self.assertUnmerged(([('3', b'c', 0), ('2', b'b', 0)], []),
 
53
                            original, puller, backward=True)
 
54
 
 
55
        puller_tree.pull(original)
 
56
        self.assertUnmerged(([], []), original, puller)
 
57
        self.assertUnmerged(([('2', b'b', 0), ('3', b'c', 0)], []),
 
58
                            original, merger)
 
59
        merger_tree.merge_from_branch(original)
 
60
        self.assertUnmerged(([('2', b'b', 0), ('3', b'c', 0)], []),
 
61
                            original, merger)
 
62
        merger_tree.commit('d', rev_id=b'd')
 
63
        self.assertUnmerged(([], [('2', b'd', 0)]), original, merger)
 
64
 
 
65
    def test_iter_log_revisions(self):
 
66
        base_tree = self.make_branch_and_tree('base')
 
67
        self.build_tree(['base/a'])
 
68
        base_tree.add(['a'], [b'a-id'])
 
69
        base_tree.commit('add a', rev_id=b'b-1')
 
70
 
 
71
        child_tree = base_tree.controldir.sprout('child').open_workingtree()
 
72
 
 
73
        self.build_tree(['child/b'])
 
74
        child_tree.add(['b'], [b'b-id'])
 
75
        child_tree.commit('adding b', rev_id=b'c-2')
 
76
 
 
77
        child_tree.remove(['a'])
 
78
        child_tree.commit('removing a', rev_id=b'c-3')
 
79
 
 
80
        self.build_tree_contents([('child/b', b'new contents for b\n')])
 
81
        child_tree.commit('modifying b', rev_id=b'c-4')
 
82
 
 
83
        child_tree.rename_one('b', 'c')
 
84
        child_tree.commit('rename b=>c', rev_id=b'c-5')
 
85
 
 
86
        base_extra, child_extra = missing.find_unmerged(base_tree.branch,
 
87
                                                        child_tree.branch)
 
88
        results = list(iter_log_revisions(base_extra,
 
89
                                          base_tree.branch.repository,
 
90
                                          verbose=True))
 
91
        self.assertEqual([], results)
 
92
 
 
93
        results = list(iter_log_revisions(child_extra,
 
94
                                          child_tree.branch.repository,
 
95
                                          verbose=True))
 
96
        self.assertEqual(4, len(results))
 
97
 
 
98
        r0, r1, r2, r3 = results
 
99
 
 
100
        self.assertEqual([('2', b'c-2'), ('3', b'c-3'),
 
101
                          ('4', b'c-4'), ('5', b'c-5'), ],
 
102
                         [(r.revno, r.rev.revision_id) for r in results])
 
103
 
 
104
        delta0 = r0.delta
 
105
        self.assertNotEqual(None, delta0)
 
106
        self.assertEqual([('b', 'file')], [(c.path[1], c.kind[1]) for c in delta0.added])
 
107
        self.assertEqual([], delta0.removed)
 
108
        self.assertEqual([], delta0.renamed)
 
109
        self.assertEqual([], delta0.copied)
 
110
        self.assertEqual([], delta0.modified)
 
111
 
 
112
        delta1 = r1.delta
 
113
        self.assertNotEqual(None, delta1)
 
114
        self.assertEqual([], delta1.added)
 
115
        self.assertEqual([('a', 'file')], [(c.path[0], c.kind[0]) for c in delta1.removed])
 
116
        self.assertEqual([], delta1.renamed)
 
117
        self.assertEqual([], delta1.copied)
 
118
        self.assertEqual([], delta1.modified)
 
119
 
 
120
        delta2 = r2.delta
 
121
        self.assertNotEqual(None, delta2)
 
122
        self.assertEqual([], delta2.added)
 
123
        self.assertEqual([], delta2.removed)
 
124
        self.assertEqual([], delta2.renamed)
 
125
        self.assertEqual([], delta2.copied)
 
126
        self.assertEqual(
 
127
            [('b', 'file', True, False)],
 
128
            [(c.path[1], c.kind[1], c.changed_content, c.meta_modified()) for c in delta2.modified])
 
129
 
 
130
        delta3 = r3.delta
 
131
        self.assertNotEqual(None, delta3)
 
132
        self.assertEqual([], delta3.added)
 
133
        self.assertEqual([], delta3.copied)
 
134
        self.assertEqual([], delta3.removed)
 
135
        self.assertEqual(
 
136
            [('b', 'c', 'file', False, False)],
 
137
            [(c.path[0], c.path[1], c.kind[1], c.changed_content, c.meta_modified())
 
138
                for c in delta3.renamed])
 
139
        self.assertEqual([], delta3.modified)
 
140
 
 
141
 
 
142
class TestFindUnmerged(tests.TestCaseWithTransport):
 
143
 
 
144
    def assertUnmerged(self, local, remote, local_branch, remote_branch,
 
145
                       restrict='all', include_merged=False, backward=False,
 
146
                       local_revid_range=None, remote_revid_range=None):
 
147
        """Check the output of find_unmerged_mainline_revisions"""
 
148
        local_extra, remote_extra = missing.find_unmerged(
 
149
            local_branch, remote_branch, restrict,
 
150
            include_merged=include_merged, backward=backward,
 
151
            local_revid_range=local_revid_range,
 
152
            remote_revid_range=remote_revid_range)
 
153
        self.assertEqual(local, local_extra)
 
154
        self.assertEqual(remote, remote_extra)
 
155
 
 
156
    def test_same_branch(self):
 
157
        tree = self.make_branch_and_tree('tree')
 
158
        rev1 = tree.commit('one')
 
159
        tree.lock_read()
 
160
        self.addCleanup(tree.unlock)
 
161
        self.assertUnmerged([], [], tree.branch, tree.branch)
 
162
        self.assertUnmerged([], [], tree.branch, tree.branch,
 
163
                            local_revid_range=(rev1, rev1))
 
164
 
 
165
    def test_one_ahead(self):
 
166
        tree = self.make_branch_and_tree('tree')
 
167
        tree.commit('one')
 
168
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
 
169
        rev2 = tree2.commit('two')
 
170
        self.assertUnmerged([], [('2', rev2, 0)], tree.branch, tree2.branch)
 
171
        self.assertUnmerged([('2', rev2, 0)], [], tree2.branch, tree.branch)
 
172
 
 
173
    def test_restrict(self):
 
174
        tree = self.make_branch_and_tree('tree')
 
175
        tree.commit('one')
 
176
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
 
177
        rev2 = tree2.commit('two')
 
178
        self.assertUnmerged([], [('2', rev2, 0)], tree.branch, tree2.branch)
 
179
        self.assertUnmerged([], None, tree.branch, tree2.branch, 'local')
 
180
        self.assertUnmerged(None, [('2', rev2, 0)], tree.branch, tree2.branch,
 
181
                            'remote')
 
182
 
 
183
    def test_merged(self):
 
184
        tree = self.make_branch_and_tree('tree')
 
185
        rev1 = tree.commit('one')
 
186
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
 
187
        tree2.commit('two')
 
188
        tree2.commit('three')
 
189
        tree.merge_from_branch(tree2.branch)
 
190
        rev4 = tree.commit('four')
 
191
 
 
192
        self.assertUnmerged([('2', rev4, 0)], [], tree.branch, tree2.branch)
 
193
        self.assertUnmerged([('2', rev4, 0)], [], tree.branch, tree2.branch,
 
194
                            local_revid_range=(rev4, rev4))
 
195
        self.assertUnmerged([], [], tree.branch, tree2.branch,
 
196
                            local_revid_range=(rev1, rev1))
 
197
 
 
198
    def test_include_merged(self):
 
199
        tree = self.make_branch_and_tree('tree')
 
200
        tree.commit('one', rev_id=b'rev1')
 
201
 
 
202
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
 
203
        tree2.commit('two', rev_id=b'rev2')
 
204
        rev3 = tree2.commit('three', rev_id=b'rev3')
 
205
 
 
206
        tree3 = tree2.controldir.sprout('tree3').open_workingtree()
 
207
        rev4 = tree3.commit('four', rev_id=b'rev4')
 
208
        rev5 = tree3.commit('five', rev_id=b'rev5')
 
209
 
 
210
        tree2.merge_from_branch(tree3.branch)
 
211
        rev6 = tree2.commit('six', rev_id=b'rev6')
 
212
 
 
213
        self.assertUnmerged([], [('2', b'rev2', 0), ('3', b'rev3', 0),
 
214
                                 ('4', b'rev6', 0),
 
215
                                 ('3.1.1', b'rev4', 1), ('3.1.2', b'rev5', 1),
 
216
                                 ],
 
217
                            tree.branch, tree2.branch,
 
218
                            include_merged=True)
 
219
 
 
220
        self.assertUnmerged([], [('4', b'rev6', 0),
 
221
                                 ('3.1.2', b'rev5', 1), ('3.1.1', b'rev4', 1),
 
222
                                 ('3', b'rev3', 0), ('2', b'rev2', 0),
 
223
                                 ],
 
224
                            tree.branch, tree2.branch,
 
225
                            include_merged=True,
 
226
                            backward=True)
 
227
 
 
228
        self.assertUnmerged(
 
229
            [], [('4', b'rev6', 0)],
 
230
            tree.branch, tree2.branch,
 
231
            include_merged=True, remote_revid_range=(rev6, rev6))
 
232
 
 
233
        self.assertUnmerged(
 
234
            [], [('3', b'rev3', 0), ('3.1.1', b'rev4', 1)],
 
235
            tree.branch, tree2.branch,
 
236
            include_merged=True, remote_revid_range=(rev3, rev4))
 
237
 
 
238
        self.assertUnmerged(
 
239
            [], [('4', b'rev6', 0), ('3.1.2', b'rev5', 1)],
 
240
            tree.branch, tree2.branch,
 
241
            include_merged=True, remote_revid_range=(rev5, rev6))
 
242
 
 
243
    def test_revision_range(self):
 
244
        local = self.make_branch_and_tree('local')
 
245
        lrevid1 = local.commit('one')
 
246
        remote = local.controldir.sprout('remote').open_workingtree()
 
247
        rrevid2 = remote.commit('two')
 
248
        rrevid3 = remote.commit('three')
 
249
        rrevid4 = remote.commit('four')
 
250
        lrevid2 = local.commit('two')
 
251
        lrevid3 = local.commit('three')
 
252
        lrevid4 = local.commit('four')
 
253
        local_extra = [('2', lrevid2, 0), ('3', lrevid3, 0), ('4', lrevid4, 0)]
 
254
        remote_extra = [('2', rrevid2, 0), ('3', rrevid3, 0),
 
255
                        ('4', rrevid4, 0)]
 
256
 
 
257
        # control
 
258
        self.assertUnmerged(local_extra, remote_extra,
 
259
                            local.branch, remote.branch)
 
260
        self.assertUnmerged(local_extra, remote_extra,
 
261
                            local.branch, remote.branch, local_revid_range=(
 
262
                                None, None),
 
263
                            remote_revid_range=(None, None))
 
264
 
 
265
        # exclude local revisions
 
266
        self.assertUnmerged(
 
267
            [('2', lrevid2, 0)], remote_extra,
 
268
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid2))
 
269
        self.assertUnmerged(
 
270
            [('2', lrevid2, 0), ('3', lrevid3, 0)], remote_extra,
 
271
            local.branch, remote.branch, local_revid_range=(lrevid2, lrevid3))
 
272
        self.assertUnmerged(
 
273
            [('2', lrevid2, 0), ('3', lrevid3, 0)], None,
 
274
            local.branch, remote.branch, 'local',
 
275
            local_revid_range=(lrevid2, lrevid3))
 
276
 
 
277
        # exclude remote revisions
 
278
        self.assertUnmerged(
 
279
            local_extra, [('2', rrevid2, 0)],
 
280
            local.branch, remote.branch, remote_revid_range=(None, rrevid2))
 
281
        self.assertUnmerged(
 
282
            local_extra, [('2', rrevid2, 0)],
 
283
            local.branch, remote.branch, remote_revid_range=(lrevid1, rrevid2))
 
284
        self.assertUnmerged(
 
285
            local_extra, [('2', rrevid2, 0)],
 
286
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid2))
 
287
        self.assertUnmerged(
 
288
            local_extra, [('2', rrevid2, 0), ('3', rrevid3, 0)],
 
289
            local.branch, remote.branch, remote_revid_range=(None, rrevid3))
 
290
        self.assertUnmerged(
 
291
            local_extra, [('2', rrevid2, 0), ('3', rrevid3, 0)],
 
292
            local.branch, remote.branch, remote_revid_range=(rrevid2, rrevid3))
 
293
        self.assertUnmerged(
 
294
            local_extra, [('3', rrevid3, 0)],
 
295
            local.branch, remote.branch, remote_revid_range=(rrevid3, rrevid3))
 
296
        self.assertUnmerged(None, [('2', rrevid2, 0), ('3', rrevid3, 0)],
 
297
                            local.branch, remote.branch, 'remote',
 
298
                            remote_revid_range=(rrevid2, rrevid3))
 
299
 
 
300
        # exclude local and remote revisions
 
301
        self.assertUnmerged([('3', lrevid3, 0)], [('3', rrevid3, 0)],
 
302
                            local.branch, remote.branch, local_revid_range=(
 
303
                                lrevid3, lrevid3),
 
304
                            remote_revid_range=(rrevid3, rrevid3))