/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 bzrlib/tests/per_merger.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
"""Implementation tests for breezy.merge.Merger."""
 
17
"""Implementation tests for bzrlib.merge.Merger."""
18
18
 
19
19
import os
20
20
 
21
 
from ..conflicts import TextConflict
22
 
from .. import (
 
21
from bzrlib.conflicts import TextConflict
 
22
from bzrlib import (
23
23
    errors,
24
24
    merge as _mod_merge,
25
25
    )
26
 
from . import (
 
26
from bzrlib.tests import (
27
27
    multiply_tests,
28
28
    TestCaseWithTransport,
29
29
    )
30
 
from .test_merge_core import MergeBuilder
31
 
from ..transform import TreeTransform
32
 
 
33
 
 
34
 
 
35
 
def load_tests(loader, standard_tests, pattern):
 
30
from bzrlib.tests.test_merge_core import MergeBuilder
 
31
from bzrlib.transform import TreeTransform
 
32
 
 
33
 
 
34
 
 
35
def load_tests(standard_tests, module, loader):
36
36
    """Multiply tests for tranport implementations."""
37
37
    result = loader.suiteClass()
38
38
    scenarios = [
44
44
class TestMergeImplementation(TestCaseWithTransport):
45
45
 
46
46
    def do_merge(self, target_tree, source_tree, **kwargs):
47
 
        merger = _mod_merge.Merger.from_revision_ids(
 
47
        merger = _mod_merge.Merger.from_revision_ids(None,
48
48
            target_tree, source_tree.last_revision(),
49
49
            other_branch=source_tree.branch)
50
50
        merger.merge_type=self.merge_type
57
57
        this_tree.lock_write()
58
58
        self.addCleanup(this_tree.unlock)
59
59
        self.build_tree_contents([
60
 
            ('this/file1', b'a\nb\n'),
61
 
            ('this/file2', b'a\nb\n')
 
60
            ('this/file1', 'a\nb\n'),
 
61
            ('this/file2', 'a\nb\n')
62
62
        ])
63
63
        this_tree.add(['file1', 'file2'])
64
64
        this_tree.commit('Added files')
65
 
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
 
65
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
66
66
        self.build_tree_contents([
67
 
            ('other/file1', b'a\nb\nc\n'),
68
 
            ('other/file2', b'a\nb\nc\n')
 
67
            ('other/file1', 'a\nb\nc\n'),
 
68
            ('other/file2', 'a\nb\nc\n')
69
69
        ])
70
70
        other_tree.commit('modified both')
71
71
        self.build_tree_contents([
72
 
            ('this/file1', b'd\na\nb\n'),
73
 
            ('this/file2', b'd\na\nb\n')
 
72
            ('this/file1', 'd\na\nb\n'),
 
73
            ('this/file2', 'd\na\nb\n')
74
74
        ])
75
75
        this_tree.commit('modified both')
76
76
        self.do_merge(this_tree, other_tree, interesting_files=['file1'])
77
 
        self.assertFileEqual(b'd\na\nb\nc\n', 'this/file1')
78
 
        self.assertFileEqual(b'd\na\nb\n', 'this/file2')
 
77
        self.assertFileEqual('d\na\nb\nc\n', 'this/file1')
 
78
        self.assertFileEqual('d\na\nb\n', 'this/file2')
79
79
 
80
80
    def test_merge_move_and_change(self):
81
81
        this_tree = self.make_branch_and_tree('this')
82
82
        this_tree.lock_write()
83
83
        self.addCleanup(this_tree.unlock)
84
84
        self.build_tree_contents([
85
 
            ('this/file1', b'line 1\nline 2\nline 3\nline 4\n'),
 
85
            ('this/file1', 'line 1\nline 2\nline 3\nline 4\n'),
86
86
        ])
87
87
        this_tree.add('file1',)
88
88
        this_tree.commit('Added file')
89
 
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
 
89
        other_tree = this_tree.bzrdir.sprout('other').open_workingtree()
90
90
        self.build_tree_contents([
91
 
            ('other/file1', b'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
 
91
            ('other/file1', 'line 1\nline 2 to 2.1\nline 3\nline 4\n'),
92
92
        ])
93
93
        other_tree.commit('Changed 2 to 2.1')
94
94
        self.build_tree_contents([
95
 
            ('this/file1', b'line 1\nline 3\nline 2\nline 4\n'),
 
95
            ('this/file1', 'line 1\nline 3\nline 2\nline 4\n'),
96
96
        ])
97
97
        this_tree.commit('Swapped 2 & 3')
98
98
        self.do_merge(this_tree, other_tree)
100
100
            self.expectFailure(
101
101
                "lca merge doesn't conflict for move and change",
102
102
                self.assertFileEqual,
103
 
                b'line 1\n'
104
 
                b'<<<<<<< TREE\n'
105
 
                b'line 3\n'
106
 
                b'line 2\n'
107
 
                b'=======\n'
108
 
                b'line 2 to 2.1\n'
109
 
                b'line 3\n'
110
 
                b'>>>>>>> MERGE-SOURCE\n'
111
 
                b'line 4\n', 'this/file1')
 
103
                'line 1\n'
 
104
                '<<<<<<< TREE\n'
 
105
                'line 3\n'
 
106
                'line 2\n'
 
107
                '=======\n'
 
108
                'line 2 to 2.1\n'
 
109
                'line 3\n'
 
110
                '>>>>>>> MERGE-SOURCE\n'
 
111
                'line 4\n', 'this/file1')
112
112
        else:
113
 
            self.assertFileEqual(b'line 1\n'
114
 
                b'<<<<<<< TREE\n'
115
 
                b'line 3\n'
116
 
                b'line 2\n'
117
 
                b'=======\n'
118
 
                b'line 2 to 2.1\n'
119
 
                b'line 3\n'
120
 
                b'>>>>>>> MERGE-SOURCE\n'
121
 
                b'line 4\n', 'this/file1')
 
113
            self.assertFileEqual('line 1\n'
 
114
                '<<<<<<< TREE\n'
 
115
                'line 3\n'
 
116
                'line 2\n'
 
117
                '=======\n'
 
118
                'line 2 to 2.1\n'
 
119
                'line 3\n'
 
120
                '>>>>>>> MERGE-SOURCE\n'
 
121
                'line 4\n', 'this/file1')
122
122
 
123
123
    def test_modify_conflicts_with_delete(self):
124
124
        # If one side deletes a line, and the other modifies that line, then
125
125
        # the modification should be considered a conflict
126
126
        builder = self.make_branch_builder('test')
127
127
        builder.start_series()
128
 
        builder.build_snapshot(None,
 
128
        builder.build_snapshot('BASE-id', None,
129
129
            [('add', ('', None, 'directory', None)),
130
 
             ('add', ('foo', b'foo-id', 'file', b'a\nb\nc\nd\ne\n')),
131
 
            ], revision_id=b'BASE-id')
 
130
             ('add', ('foo', 'foo-id', 'file', 'a\nb\nc\nd\ne\n')),
 
131
            ])
132
132
        # Delete 'b\n'
133
 
        builder.build_snapshot([b'BASE-id'],
134
 
            [('modify', ('foo', b'a\nc\nd\ne\n'))],
135
 
            revision_id=b'OTHER-id')
 
133
        builder.build_snapshot('OTHER-id', ['BASE-id'],
 
134
            [('modify', ('foo-id', 'a\nc\nd\ne\n'))])
136
135
        # Modify 'b\n', add 'X\n'
137
 
        builder.build_snapshot([b'BASE-id'],
138
 
            [('modify', ('foo', b'a\nb2\nc\nd\nX\ne\n'))],
139
 
            revision_id=b'THIS-id')
 
136
        builder.build_snapshot('THIS-id', ['BASE-id'],
 
137
            [('modify', ('foo-id', 'a\nb2\nc\nd\nX\ne\n'))])
140
138
        builder.finish_series()
141
139
        branch = builder.get_branch()
142
 
        this_tree = branch.controldir.create_workingtree()
 
140
        this_tree = branch.bzrdir.create_workingtree()
143
141
        this_tree.lock_write()
144
142
        self.addCleanup(this_tree.unlock)
145
 
        other_tree = this_tree.controldir.sprout('other', b'OTHER-id').open_workingtree()
 
143
        other_tree = this_tree.bzrdir.sprout('other',
 
144
                                             'OTHER-id').open_workingtree()
146
145
        self.do_merge(this_tree, other_tree)
147
146
        if self.merge_type is _mod_merge.LCAMerger:
148
147
            self.expectFailure("lca merge doesn't track deleted lines",
149
148
                self.assertFileEqual,
150
 
                    b'a\n'
151
 
                    b'<<<<<<< TREE\n'
152
 
                    b'b2\n'
153
 
                    b'=======\n'
154
 
                    b'>>>>>>> MERGE-SOURCE\n'
155
 
                    b'c\n'
156
 
                    b'd\n'
157
 
                    b'X\n'
158
 
                    b'e\n', 'test/foo')
 
149
                    'a\n'
 
150
                    '<<<<<<< TREE\n'
 
151
                    'b2\n'
 
152
                    '=======\n'
 
153
                    '>>>>>>> MERGE-SOURCE\n'
 
154
                    'c\n'
 
155
                    'd\n'
 
156
                    'X\n'
 
157
                    'e\n', 'test/foo')
159
158
        else:
160
159
            self.assertFileEqual(
161
 
                b'a\n'
162
 
                b'<<<<<<< TREE\n'
163
 
                b'b2\n'
164
 
                b'=======\n'
165
 
                b'>>>>>>> MERGE-SOURCE\n'
166
 
                b'c\n'
167
 
                b'd\n'
168
 
                b'X\n'
169
 
                b'e\n', 'test/foo')
 
160
                'a\n'
 
161
                '<<<<<<< TREE\n'
 
162
                'b2\n'
 
163
                '=======\n'
 
164
                '>>>>>>> MERGE-SOURCE\n'
 
165
                'c\n'
 
166
                'd\n'
 
167
                'X\n'
 
168
                'e\n', 'test/foo')
170
169
 
171
170
    def get_limbodir_deletiondir(self, wt):
172
171
        transform = TreeTransform(wt)
299
298
        return builder
300
299
 
301
300
    def create_file_needing_contents_merge(self, builder, file_id):
302
 
        builder.add_file(file_id, builder.tree_root, "name1", b"text1", True)
 
301
        builder.add_file(file_id, builder.tree_root, "name1", "text1", True)
303
302
        builder.change_contents(file_id, other="text4", this="text3")
304
303
 
305
304
    def test_change_vs_change(self):
306
305
        """Hook is used for (changed, changed)"""
307
306
        self.install_hook_success()
308
307
        builder = self.make_merge_builder()
309
 
        builder.add_file("1", builder.tree_root, "name1", b"text1", True)
 
308
        builder.add_file("1", builder.tree_root, "name1", "text1", True)
310
309
        builder.change_contents("1", other="text4", this="text3")
311
310
        conflicts = builder.merge(self.merge_type)
312
311
        self.assertEqual(conflicts, [])
313
312
        self.assertEqual(
314
 
            builder.this.get_file('name1').read(), 'text-merged-by-hook')
 
313
            builder.this.get_file('1').read(), 'text-merged-by-hook')
315
314
 
316
315
    def test_change_vs_deleted(self):
317
316
        """Hook is used for (changed, deleted)"""
318
317
        self.install_hook_success()
319
318
        builder = self.make_merge_builder()
320
 
        builder.add_file("1", builder.tree_root, "name1", b"text1", True)
 
319
        builder.add_file("1", builder.tree_root, "name1", "text1", True)
321
320
        builder.change_contents("1", this="text2")
322
321
        builder.remove_file("1", other=True)
323
322
        conflicts = builder.merge(self.merge_type)
324
323
        self.assertEqual(conflicts, [])
325
324
        self.assertEqual(
326
 
            builder.this.get_file('name1').read(), 'text-merged-by-hook')
 
325
            builder.this.get_file('1').read(), 'text-merged-by-hook')
327
326
 
328
327
    def test_result_can_be_delete(self):
329
328
        """A hook's result can be the deletion of a file."""
345
344
        # The hook still gets to set the file contents in this case, so that it
346
345
        # can insert custom conflict markers.
347
346
        self.assertEqual(
348
 
            builder.this.get_file('name1').read(),
 
347
            builder.this.get_file('1').read(),
349
348
            'text-with-conflict-markers-from-hook')
350
349
 
351
350
    def test_can_access_this_other_and_base_versions(self):
354
353
        """
355
354
        self.install_hook_log_lines()
356
355
        builder = self.make_merge_builder()
357
 
        builder.add_file("1", builder.tree_root, "name1", b"text1", True)
 
356
        builder.add_file("1", builder.tree_root, "name1", "text1", True)
358
357
        builder.change_contents("1", this="text2", other="text3")
359
358
        conflicts = builder.merge(self.merge_type)
360
359
        self.assertEqual(
369
368
        conflicts = builder.merge(self.merge_type)
370
369
        self.assertEqual(conflicts, [])
371
370
        self.assertEqual(
372
 
            builder.this.get_file('name1').read(), 'text-merged-by-hook')
 
371
            builder.this.get_file('1').read(), 'text-merged-by-hook')
373
372
        self.assertEqual([('inactive',), ('success',)], self.hook_log)
374
373
 
375
374
    def test_chain_when_not_applicable(self):
383
382
        conflicts = builder.merge(self.merge_type)
384
383
        self.assertEqual(conflicts, [])
385
384
        self.assertEqual(
386
 
            builder.this.get_file('name1').read(), 'text-merged-by-hook')
 
385
            builder.this.get_file('1').read(), 'text-merged-by-hook')
387
386
        self.assertEqual([('no-op',), ('success',)], self.hook_log)
388
387
 
389
388
    def test_chain_stops_after_success(self):