~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/blackbox/test_merge.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-10-02 17:28:44 UTC
  • mfrom: (3744.2.2 merge_reprocess)
  • Revision ID: pqm@pqm.ubuntu.com-20081002172844-d6df1l8dzpsqzyup
(jam) For 'bzr merge' enable '--reprocess' by default whenever
        '--show-base' is not set.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
        tree.commit(message='setup')
45
45
        return tree
46
46
 
 
47
    def create_conflicting_branches(self):
 
48
        """Create two branches which have overlapping modifications.
 
49
 
 
50
        :return: (tree, other_branch) Where merging other_branch causes a file
 
51
            conflict.
 
52
        """
 
53
        builder = self.make_branch_builder('branch')
 
54
        builder.build_snapshot('rev1', None,
 
55
            [('add', ('', 'root-id', 'directory', None)),
 
56
             ('add', ('fname', 'f-id', 'file', 'a\nb\nc\n'))])
 
57
        builder.build_snapshot('rev2other', ['rev1'],
 
58
            [('modify', ('f-id', 'a\nB\nD\n'))])
 
59
        other = builder.get_branch().bzrdir.sprout('other').open_branch()
 
60
        builder.build_snapshot('rev2this', ['rev1'],
 
61
            [('modify', ('f-id', 'a\nB\nC\n'))])
 
62
        tree = builder.get_branch().create_checkout('tree', lightweight=True)
 
63
        return tree, other
 
64
 
47
65
    def test_merge_reprocess(self):
48
66
        d = BzrDir.create_standalone_workingtree('.')
49
67
        d.commit('h')
101
119
        self.run_bzr('merge ../b -r last:1')
102
120
        self.assertEqual([a_tip], a.get_parent_ids())
103
121
 
 
122
    def test_merge_defaults_to_reprocess(self):
 
123
        tree, other = self.create_conflicting_branches()
 
124
        # The default merge algorithm should enable 'reprocess' because
 
125
        # 'show-base' is not set
 
126
        self.run_bzr('merge ../other', working_dir='tree',
 
127
                     retcode=1)
 
128
        self.assertEqualDiff('a\n'
 
129
                             'B\n'
 
130
                             '<<<<<<< TREE\n'
 
131
                             'C\n'
 
132
                             '=======\n'
 
133
                             'D\n'
 
134
                             '>>>>>>> MERGE-SOURCE\n',
 
135
                             tree.get_file_text('f-id'))
 
136
 
 
137
    def test_merge_explicit_reprocess_show_base(self):
 
138
        tree, other = self.create_conflicting_branches()
 
139
        # Explicitly setting --reprocess, and --show-base is an error
 
140
        self.run_bzr_error(['Cannot do conflict reduction and show base'],
 
141
                           'merge ../other --reprocess --show-base',
 
142
                           working_dir='tree')
 
143
 
 
144
    def test_merge_override_reprocess(self):
 
145
        tree, other = self.create_conflicting_branches()
 
146
        # Explicitly disable reprocess
 
147
        self.run_bzr('merge ../other --no-reprocess', working_dir='tree',
 
148
                     retcode=1)
 
149
        self.assertEqualDiff('a\n'
 
150
                             '<<<<<<< TREE\n'
 
151
                             'B\n'
 
152
                             'C\n'
 
153
                             '=======\n'
 
154
                             'B\n'
 
155
                             'D\n'
 
156
                             '>>>>>>> MERGE-SOURCE\n',
 
157
                             tree.get_file_text('f-id'))
 
158
 
 
159
    def test_merge_override_show_base(self):
 
160
        tree, other = self.create_conflicting_branches()
 
161
        # Setting '--show-base' will auto-disable '--reprocess'
 
162
        self.run_bzr('merge ../other --show-base', working_dir='tree',
 
163
                     retcode=1)
 
164
        self.assertEqualDiff('a\n'
 
165
                             '<<<<<<< TREE\n'
 
166
                             'B\n'
 
167
                             'C\n'
 
168
                             '||||||| BASE-REVISION\n'
 
169
                             'b\n'
 
170
                             'c\n'
 
171
                             '=======\n'
 
172
                             'B\n'
 
173
                             'D\n'
 
174
                             '>>>>>>> MERGE-SOURCE\n',
 
175
                             tree.get_file_text('f-id'))
 
176
 
104
177
    def test_merge_with_missing_file(self):
105
178
        """Merge handles missing file conflicts"""
106
179
        self.build_tree_contents([