/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
6614.1.3 by Vincent Ladeuil
Fix assertEquals being deprecated by using assertEqual.
1
# Copyright (C) 2005-2012, 2016 Canonical Ltd
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
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
4183.7.1 by Sabin Iacob
update FSF mailing address
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
1773.4.1 by Martin Pool
Add pyflakes makefile target; fix many warnings
16
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
17
import os
18
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
19
from .. import (
5246.2.34 by Andrew Bennetts
Delete test_merge_into, and put those tests directly in test_merge.
20
    branch as _mod_branch,
21
    cleanup,
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
22
    conflicts,
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
23
    errors,
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
24
    memorytree,
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
25
    merge as _mod_merge,
26
    option,
5246.2.34 by Andrew Bennetts
Delete test_merge_into, and put those tests directly in test_merge.
27
    revision as _mod_revision,
3514.4.19 by John Arbash Meinel
Add the _lca_multi_way function, and explicit tests.
28
    tests,
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
29
    transform,
6670.4.1 by Jelmer Vernooij
Update imports.
30
    )
31
from ..bzr import (
32
    inventory,
33
    knit,
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
34
    versionedfile,
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
35
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
36
from ..conflicts import ConflictList, TextConflict
37
from ..errors import UnrelatedBranches, NoCommits
38
from ..merge import transform_tree, merge_inner, _PlanMerge
39
from ..osutils import basename, pathjoin, file_kind
40
from . import (
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
41
    features,
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
42
    TestCaseWithMemoryTransport,
43
    TestCaseWithTransport,
44
    test_merge_core,
45
    )
6624 by Jelmer Vernooij
Merge Python3 porting work ('py3 pokes')
46
from ..workingtree import WorkingTree
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
47
4634.101.8 by John Arbash Meinel
Add the criss-cross flip-flop 'bug' for weave merge.
48
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
49
class TestMerge(TestCaseWithTransport):
974.1.56 by aaron.bentley at utoronto
Added merge test
50
    """Test appending more than one revision"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
51
974.1.56 by aaron.bentley at utoronto
Added merge test
52
    def test_pending(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
53
        wt = self.make_branch_and_tree('.')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
54
        rev_a = wt.commit("lala!")
55
        self.assertEqual([rev_a], wt.get_parent_ids())
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
56
        self.assertRaises(errors.PointlessMerge, wt.merge_from_branch,
57
                          wt.branch)
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
58
        self.assertEqual([rev_a], wt.get_parent_ids())
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
59
        return wt
974.1.80 by Aaron Bentley
Improved merge error handling and testing
60
1558.4.11 by Aaron Bentley
Allow merge against self, make fetching self a noop
61
    def test_undo(self):
62
        wt = self.make_branch_and_tree('.')
63
        wt.commit("lala!")
64
        wt.commit("haha!")
65
        wt.commit("blabla!")
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
66
        wt.merge_from_branch(wt.branch, wt.branch.get_rev_id(2),
67
                             wt.branch.get_rev_id(1))
1558.4.11 by Aaron Bentley
Allow merge against self, make fetching self a noop
68
974.1.80 by Aaron Bentley
Improved merge error handling and testing
69
    def test_nocommits(self):
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
70
        wt = self.test_pending()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
71
        wt2 = self.make_branch_and_tree('branch2')
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
72
        self.assertRaises(NoCommits, wt.merge_from_branch, wt2.branch)
73
        return wt, wt2
974.1.80 by Aaron Bentley
Improved merge error handling and testing
74
75
    def test_unrelated(self):
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
76
        wt, wt2 = self.test_nocommits()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
77
        wt2.commit("blah")
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
78
        self.assertRaises(UnrelatedBranches, wt.merge_from_branch, wt2.branch)
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
79
        return wt2
974.1.80 by Aaron Bentley
Improved merge error handling and testing
80
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
81
    def test_merge_one_file(self):
82
        """Do a partial merge of a tree which should not affect tree parents."""
1645.1.1 by Aaron Bentley
Implement single-file merge
83
        wt1 = self.make_branch_and_tree('branch1')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
84
        tip = wt1.commit('empty commit')
1645.1.1 by Aaron Bentley
Implement single-file merge
85
        wt2 = self.make_branch_and_tree('branch2')
86
        wt2.pull(wt1.branch)
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
87
        with file('branch1/foo', 'wb') as f:
88
            f.write('foo')
89
        with file('branch1/bar', 'wb') as f:
90
            f.write('bar')
1645.1.1 by Aaron Bentley
Implement single-file merge
91
        wt1.add('foo')
92
        wt1.add('bar')
93
        wt1.commit('add foobar')
6423.1.1 by Vincent Ladeuil
Cleanup old blackbox tests and then some. Remove os.chdir() calls, caught a few bugs, make sure we don't leave file handles opened.
94
        self.run_bzr('merge ../branch1/baz', retcode=3, working_dir='branch2')
95
        self.run_bzr('merge ../branch1/foo', working_dir='branch2')
96
        self.assertPathExists('branch2/foo')
97
        self.assertPathDoesNotExist('branch2/bar')
98
        wt2 = WorkingTree.open('branch2')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
99
        self.assertEqual([tip], wt2.get_parent_ids())
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
100
974.1.88 by Aaron Bentley
Set a pending_merge if the merge base is forced to revno 0
101
    def test_pending_with_null(self):
1551.8.25 by Aaron Bentley
Fix deprecated use of pending_merges
102
        """When base is forced to revno 0, parent_ids are set"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
103
        wt2 = self.test_unrelated()
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
104
        wt1 = WorkingTree.open('.')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
105
        br1 = wt1.branch
1534.1.31 by Robert Collins
Deprecated fetch.fetch and fetch.greedy_fetch for branch.fetch, and move the Repository.fetch internals to InterRepo and InterWeaveRepo.
106
        br1.fetch(wt2.branch)
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
107
        # merge all of branch 2 into branch 1 even though they
1390 by Robert Collins
pair programming worx... merge integration and weave
108
        # are not related.
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
109
        wt1.merge_from_branch(wt2.branch, wt2.last_revision(), 'null:')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
110
        self.assertEqual([br1.last_revision(), wt2.branch.last_revision()],
111
            wt1.get_parent_ids())
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
112
        return (wt1, wt2.branch)
974.1.89 by Aaron Bentley
Fixed merging with multiple roots, by using null as graph root.
113
114
    def test_two_roots(self):
115
        """Merge base is sane when two unrelated branches are merged"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
116
        wt1, br2 = self.test_pending_with_null()
117
        wt1.commit("blah")
3228.4.15 by John Arbash Meinel
Stop using common_ancestor
118
        wt1.lock_read()
119
        try:
120
            last = wt1.branch.last_revision()
121
            last2 = br2.last_revision()
122
            graph = wt1.branch.repository.get_graph()
123
            self.assertEqual(last2, graph.find_unique_lca(last, last2))
124
        finally:
125
            wt1.unlock()
1185.46.1 by Aaron Bentley
Test case when file to be renamed is also deleted
126
5954.4.2 by Aaron Bentley
Support merging into null tree.
127
    def test_merge_into_null_tree(self):
128
        wt = self.make_branch_and_tree('tree')
129
        null_tree = wt.basis_tree()
130
        self.build_tree(['tree/file'])
131
        wt.add('file')
132
        wt.commit('tree with root')
133
        merger = _mod_merge.Merge3Merger(null_tree, null_tree, null_tree, wt,
134
                                         this_branch=wt.branch,
135
                                         do_merge=False)
136
        with merger.make_preview_transform() as tt:
137
            self.assertEqual([], tt.find_conflicts())
138
            preview = tt.get_preview_tree()
139
            self.assertEqual(wt.get_root_id(), preview.get_root_id())
140
6011.1.1 by Aaron Bentley
Merging an unrelated tree retains root.
141
    def test_merge_unrelated_retains_root(self):
142
        wt = self.make_branch_and_tree('tree')
6024.1.2 by Aaron Bentley
Explicitly test transform in test case.
143
        other_tree = self.make_branch_and_tree('other')
144
        self.addCleanup(other_tree.lock_read().unlock)
6011.1.7 by Vincent Ladeuil
Change test order to get a better diff.
145
        merger = _mod_merge.Merge3Merger(wt, wt, wt.basis_tree(), other_tree,
146
                                         this_branch=wt.branch,
147
                                         do_merge=False)
6024.1.2 by Aaron Bentley
Explicitly test transform in test case.
148
        with transform.TransformPreview(wt) as merger.tt:
149
            merger._compute_transform()
150
            new_root_id = merger.tt.final_file_id(merger.tt.root)
151
            self.assertEqual(wt.get_root_id(), new_root_id)
6011.1.7 by Vincent Ladeuil
Change test order to get a better diff.
152
1185.46.1 by Aaron Bentley
Test case when file to be renamed is also deleted
153
    def test_create_rename(self):
154
        """Rename an inventory entry while creating the file"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
155
        tree =self.make_branch_and_tree('.')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
156
        with file('name1', 'wb') as f: f.write('Hello')
1185.46.1 by Aaron Bentley
Test case when file to be renamed is also deleted
157
        tree.add('name1')
158
        tree.commit(message="hello")
159
        tree.rename_one('name1', 'name2')
160
        os.unlink('name2')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
161
        transform_tree(tree, tree.branch.basis_tree())
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
162
163
    def test_layered_rename(self):
164
        """Rename both child and parent at same time"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
165
        tree =self.make_branch_and_tree('.')
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
166
        os.mkdir('dirname1')
167
        tree.add('dirname1')
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
168
        filename = pathjoin('dirname1', 'name1')
6437.20.3 by Wouter van Heyst
mechanically replace file().write() pattern with a with-keyword version
169
        with file(filename, 'wb') as f: f.write('Hello')
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
170
        tree.add(filename)
171
        tree.commit(message="hello")
1185.31.32 by John Arbash Meinel
Updated the bzr sourcecode to use bzrlib.osutils.pathjoin rather than os.path.join to enforce internal use of / instead of \
172
        filename2 = pathjoin('dirname1', 'name2')
1185.46.2 by Aaron Bentley
Added test for renaming both parent and child
173
        tree.rename_one(filename, filename2)
174
        tree.rename_one('dirname1', 'dirname2')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
175
        transform_tree(tree, tree.branch.basis_tree())
1551.2.23 by Aaron Bentley
Got merge_inner's ignore_zero parameter working
176
177
    def test_ignore_zero_merge_inner(self):
1907.4.1 by Matthieu Moy
Fixed merge to work nicely with -r revno:N:path
178
        # Test that merge_inner's ignore zero parameter is effective
1551.2.23 by Aaron Bentley
Got merge_inner's ignore_zero parameter working
179
        tree_a =self.make_branch_and_tree('a')
180
        tree_a.commit(message="hello")
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
181
        dir_b = tree_a.controldir.sprout('b')
1551.2.23 by Aaron Bentley
Got merge_inner's ignore_zero parameter working
182
        tree_b = dir_b.open_workingtree()
3146.4.4 by Aaron Bentley
Add write lock, so merge_inner works properly
183
        tree_b.lock_write()
184
        self.addCleanup(tree_b.unlock)
1551.2.23 by Aaron Bentley
Got merge_inner's ignore_zero parameter working
185
        tree_a.commit(message="hello again")
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
186
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
1551.2.23 by Aaron Bentley
Got merge_inner's ignore_zero parameter working
187
                    this_tree=tree_b, ignore_zero=True)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
188
        self.assertTrue('All changes applied successfully.\n' not in
4794.1.15 by Robert Collins
Review feedback.
189
            self.get_log())
2796.1.3 by Aaron Bentley
update new test case
190
        tree_b.revert()
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
191
        merge_inner(tree_b.branch, tree_a, tree_b.basis_tree(),
1551.2.23 by Aaron Bentley
Got merge_inner's ignore_zero parameter working
192
                    this_tree=tree_b, ignore_zero=False)
5784.1.1 by Martin Pool
Stop using failIf, failUnless, etc
193
        self.assertTrue('All changes applied successfully.\n' in self.get_log())
1551.7.10 by Aaron Bentley
Remerge doesn't clear unrelated conflicts
194
195
    def test_merge_inner_conflicts(self):
196
        tree_a = self.make_branch_and_tree('a')
197
        tree_a.set_conflicts(ConflictList([TextConflict('patha')]))
1551.7.11 by Aaron Bentley
Add WorkingTree.add_conflicts
198
        merge_inner(tree_a.branch, tree_a, tree_a, this_tree=tree_a)
1551.7.13 by Aaron Bentley
Switched from actual, expected to expected, actual, for John.
199
        self.assertEqual(1, len(tree_a.conflicts()))
1551.8.22 by Aaron Bentley
Improve message when OTHER deletes an in-use tree
200
201
    def test_rmdir_conflict(self):
202
        tree_a = self.make_branch_and_tree('a')
203
        self.build_tree(['a/b/'])
204
        tree_a.add('b', 'b-id')
205
        tree_a.commit('added b')
2255.7.12 by John Arbash Meinel
Some comments on merge code, fix merge tests that
206
        # basis_tree() is only guaranteed to be valid as long as it is actually
207
        # the basis tree. This mutates the tree after grabbing basis, so go to
208
        # the repository.
209
        base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
210
        tree_z = tree_a.controldir.sprout('z').open_workingtree()
1551.8.22 by Aaron Bentley
Improve message when OTHER deletes an in-use tree
211
        self.build_tree(['a/b/c'])
212
        tree_a.add('b/c')
213
        tree_a.commit('added c')
214
        os.rmdir('z/b')
215
        tree_z.commit('removed b')
216
        merge_inner(tree_z.branch, tree_a, base_tree, this_tree=tree_z)
217
        self.assertEqual([
218
            conflicts.MissingParent('Created directory', 'b', 'b-id'),
219
            conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],
220
            tree_z.conflicts())
2255.2.216 by Robert Collins
simplify merge_nested tests.
221
        merge_inner(tree_a.branch, tree_z.basis_tree(), base_tree,
1551.8.22 by Aaron Bentley
Improve message when OTHER deletes an in-use tree
222
                    this_tree=tree_a)
223
        self.assertEqual([
224
            conflicts.DeletingParent('Not deleting', 'b', 'b-id'),
225
            conflicts.UnversionedParent('Versioned directory', 'b', 'b-id')],
226
            tree_a.conflicts())
1551.10.2 by Aaron Bentley
Handle merge with dangling inventory entries
227
2100.3.29 by Aaron Bentley
Get merge working initially
228
    def test_nested_merge(self):
6700.1.3 by Jelmer Vernooij
Drop support for committing using record_entr_contents.
229
        self.knownFailure(
230
            'iter_changes doesn\'t work with changes in nested trees')
2255.2.194 by Robert Collins
[BROKEN] Many updates to stop using experimental formats in tests.
231
        tree = self.make_branch_and_tree('tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
232
            format='development-subtree')
2100.3.29 by Aaron Bentley
Get merge working initially
233
        sub_tree = self.make_branch_and_tree('tree/sub-tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
234
            format='development-subtree')
2100.3.29 by Aaron Bentley
Get merge working initially
235
        sub_tree.set_root_id('sub-tree-root')
236
        self.build_tree_contents([('tree/sub-tree/file', 'text1')])
237
        sub_tree.add('file')
238
        sub_tree.commit('foo')
239
        tree.add_reference(sub_tree)
240
        tree.commit('set text to 1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
241
        tree2 = tree.controldir.sprout('tree2').open_workingtree()
2255.2.217 by Martin Pool
docs
242
        # modify the file in the subtree
2100.3.29 by Aaron Bentley
Get merge working initially
243
        self.build_tree_contents([('tree2/sub-tree/file', 'text2')])
2255.2.217 by Martin Pool
docs
244
        # and merge the changes from the diverged subtree into the containing
245
        # tree
2255.2.216 by Robert Collins
simplify merge_nested tests.
246
        tree2.commit('changed file text')
2100.3.29 by Aaron Bentley
Get merge working initially
247
        tree.merge_from_branch(tree2.branch)
248
        self.assertFileEqual('text2', 'tree/sub-tree/file')
249
1551.10.2 by Aaron Bentley
Handle merge with dangling inventory entries
250
    def test_merge_with_missing(self):
251
        tree_a = self.make_branch_and_tree('tree_a')
252
        self.build_tree_contents([('tree_a/file', 'content_1')])
253
        tree_a.add('file')
254
        tree_a.commit('commit base')
2255.7.12 by John Arbash Meinel
Some comments on merge code, fix merge tests that
255
        # basis_tree() is only guaranteed to be valid as long as it is actually
4595.13.2 by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006)
256
        # the basis tree. This test commits to the tree after grabbing basis,
257
        # so we go to the repository.
2255.7.12 by John Arbash Meinel
Some comments on merge code, fix merge tests that
258
        base_tree = tree_a.branch.repository.revision_tree(tree_a.last_revision())
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
259
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
1551.10.2 by Aaron Bentley
Handle merge with dangling inventory entries
260
        self.build_tree_contents([('tree_a/file', 'content_2')])
261
        tree_a.commit('commit other')
262
        other_tree = tree_a.basis_tree()
4595.13.2 by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006)
263
        # 'file' is now missing but isn't altered in any commit in b so no
264
        # change should be applied.
1551.10.2 by Aaron Bentley
Handle merge with dangling inventory entries
265
        os.unlink('tree_b/file')
266
        merge_inner(tree_b.branch, other_tree, base_tree, this_tree=tree_b)
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
267
268
    def test_merge_kind_change(self):
269
        tree_a = self.make_branch_and_tree('tree_a')
270
        self.build_tree_contents([('tree_a/file', 'content_1')])
271
        tree_a.add('file', 'file-id')
272
        tree_a.commit('added file')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
273
        tree_b = tree_a.controldir.sprout('tree_b').open_workingtree()
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
274
        os.unlink('tree_a/file')
275
        self.build_tree(['tree_a/file/'])
276
        tree_a.commit('changed file to directory')
277
        tree_b.merge_from_branch(tree_a.branch)
278
        self.assertEqual('directory', file_kind('tree_b/file'))
2748.3.2 by Aaron Bentley
Fix revert, remove-tree, and various tests to use None for 'no files specified'
279
        tree_b.revert()
1959.4.6 by Aaron Bentley
Ensure merge works across kind changes
280
        self.assertEqual('file', file_kind('tree_b/file'))
281
        self.build_tree_contents([('tree_b/file', 'content_2')])
282
        tree_b.commit('content change')
283
        tree_b.merge_from_branch(tree_a.branch)
284
        self.assertEqual(tree_b.conflicts(),
285
                         [conflicts.ContentsConflict('file',
286
                          file_id='file-id')])
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
287
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
288
    def test_merge_type_registry(self):
289
        merge_type_option = option.Option.OPTIONS['merge-type']
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
290
        self.assertFalse('merge4' in [x[0] for x in
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
291
                        merge_type_option.iter_switches()])
292
        registry = _mod_merge.get_merge_type_registry()
6622.1.34 by Jelmer Vernooij
Rename brzlib => breezy.
293
        registry.register_lazy('merge4', 'breezy.merge', 'Merge4Merger',
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
294
                               'time-travelling merge')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
295
        self.assertTrue('merge4' in [x[0] for x in
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
296
                        merge_type_option.iter_switches()])
297
        registry.remove('merge4')
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
298
        self.assertFalse('merge4' in [x[0] for x in
2221.4.16 by Aaron Bentley
Add tests for get_merge_type_registry
299
                        merge_type_option.iter_switches()])
1551.16.2 by Aaron Bentley
Don't crash on merging renamed deleted files (#110279)
300
1551.16.3 by Aaron Bentley
Rename test case
301
    def test_merge_other_moves_we_deleted(self):
1551.16.2 by Aaron Bentley
Don't crash on merging renamed deleted files (#110279)
302
        tree_a = self.make_branch_and_tree('A')
303
        tree_a.lock_write()
304
        self.addCleanup(tree_a.unlock)
305
        self.build_tree(['A/a'])
306
        tree_a.add('a')
307
        tree_a.commit('1', rev_id='rev-1')
308
        tree_a.flush()
309
        tree_a.rename_one('a', 'b')
310
        tree_a.commit('2')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
311
        bzrdir_b = tree_a.controldir.sprout('B', revision_id='rev-1')
1551.16.2 by Aaron Bentley
Don't crash on merging renamed deleted files (#110279)
312
        tree_b = bzrdir_b.open_workingtree()
313
        tree_b.lock_write()
314
        self.addCleanup(tree_b.unlock)
315
        os.unlink('B/a')
316
        tree_b.commit('3')
317
        try:
318
            tree_b.merge_from_branch(tree_a.branch)
319
        except AttributeError:
320
            self.fail('tried to join a path when name was None')
2644.1.1 by Wouter van Heyst
Fix bug #127115 by checking for self.other_rev_id being None in Merger.set_pending()
321
4685.2.1 by Gary van der Merwe
Revert rename of test_merge_uncommitted_otherbasis_ancestor_of_thisbasis.
322
    def test_merge_uncommitted_otherbasis_ancestor_of_thisbasis(self):
2644.1.1 by Wouter van Heyst
Fix bug #127115 by checking for self.other_rev_id being None in Merger.set_pending()
323
        tree_a = self.make_branch_and_tree('a')
2644.1.2 by Wouter van Heyst
As Aaron explained #127115 is more general, failing whenever other's basis is an ancestor of this' basis.
324
        self.build_tree(['a/file_1', 'a/file_2'])
2644.1.1 by Wouter van Heyst
Fix bug #127115 by checking for self.other_rev_id being None in Merger.set_pending()
325
        tree_a.add(['file_1'])
326
        tree_a.commit('commit 1')
2644.1.2 by Wouter van Heyst
As Aaron explained #127115 is more general, failing whenever other's basis is an ancestor of this' basis.
327
        tree_a.add(['file_2'])
328
        tree_a.commit('commit 2')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
329
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
2644.1.2 by Wouter van Heyst
As Aaron explained #127115 is more general, failing whenever other's basis is an ancestor of this' basis.
330
        tree_b.rename_one('file_1', 'renamed')
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
331
        merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b)
1551.15.72 by Aaron Bentley
remove builtins._merge_helper
332
        merger.merge_type = _mod_merge.Merge3Merger
333
        merger.do_merge()
2644.1.2 by Wouter van Heyst
As Aaron explained #127115 is more general, failing whenever other's basis is an ancestor of this' basis.
334
        self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
335
3146.5.1 by Aaron Bentley
Make merge --uncommitted work with merge-type weave
336
    def test_merge_uncommitted_otherbasis_ancestor_of_thisbasis_weave(self):
337
        tree_a = self.make_branch_and_tree('a')
338
        self.build_tree(['a/file_1', 'a/file_2'])
339
        tree_a.add(['file_1'])
340
        tree_a.commit('commit 1')
341
        tree_a.add(['file_2'])
342
        tree_a.commit('commit 2')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
343
        tree_b = tree_a.controldir.sprout('b').open_workingtree()
3146.5.1 by Aaron Bentley
Make merge --uncommitted work with merge-type weave
344
        tree_b.rename_one('file_1', 'renamed')
4961.2.9 by Martin Pool
Rip out most remaining uses of DummyProgressBar
345
        merger = _mod_merge.Merger.from_uncommitted(tree_a, tree_b)
3146.5.1 by Aaron Bentley
Make merge --uncommitted work with merge-type weave
346
        merger.merge_type = _mod_merge.WeaveMerger
347
        merger.do_merge()
348
        self.assertEqual(tree_a.get_parent_ids(), [tree_b.last_revision()])
349
3062.2.7 by Aaron Bentley
Prevent reverse cherry-picking with weave
350
    def prepare_cherrypick(self):
3062.2.13 by Aaron Bentley
Update prepare_cherrypick docstring
351
        """Prepare a pair of trees for cherrypicking tests.
352
353
        Both trees have a file, 'file'.
354
        rev1 sets content to 'a'.
355
        rev2b adds 'b'.
356
        rev3b adds 'c'.
357
        A full merge of rev2b and rev3b into this_tree would add both 'b' and
358
        'c'.  A successful cherrypick of rev2b-rev3b into this_tree will add
359
        'c', but not 'b'.
360
        """
3062.2.6 by Aaron Bentley
Get cherrypick-on-weave working
361
        this_tree = self.make_branch_and_tree('this')
362
        self.build_tree_contents([('this/file', "a\n")])
363
        this_tree.add('file')
364
        this_tree.commit('rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
365
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
3062.2.6 by Aaron Bentley
Get cherrypick-on-weave working
366
        self.build_tree_contents([('other/file', "a\nb\n")])
367
        other_tree.commit('rev2b', rev_id='rev2b')
368
        self.build_tree_contents([('other/file', "c\na\nb\n")])
369
        other_tree.commit('rev3b', rev_id='rev3b')
370
        this_tree.lock_write()
371
        self.addCleanup(this_tree.unlock)
3062.2.7 by Aaron Bentley
Prevent reverse cherry-picking with weave
372
        return this_tree, other_tree
373
374
    def test_weave_cherrypick(self):
375
        this_tree, other_tree = self.prepare_cherrypick()
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
376
        merger = _mod_merge.Merger.from_revision_ids(
3062.2.6 by Aaron Bentley
Get cherrypick-on-weave working
377
            this_tree, 'rev3b', 'rev2b', other_tree.branch)
378
        merger.merge_type = _mod_merge.WeaveMerger
379
        merger.do_merge()
380
        self.assertFileEqual('c\na\n', 'this/file')
381
3062.2.7 by Aaron Bentley
Prevent reverse cherry-picking with weave
382
    def test_weave_cannot_reverse_cherrypick(self):
383
        this_tree, other_tree = self.prepare_cherrypick()
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
384
        merger = _mod_merge.Merger.from_revision_ids(
3062.2.7 by Aaron Bentley
Prevent reverse cherry-picking with weave
385
            this_tree, 'rev2b', 'rev3b', other_tree.branch)
386
        merger.merge_type = _mod_merge.WeaveMerger
387
        self.assertRaises(errors.CannotReverseCherrypick, merger.do_merge)
388
389
    def test_merge3_can_reverse_cherrypick(self):
390
        this_tree, other_tree = self.prepare_cherrypick()
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
391
        merger = _mod_merge.Merger.from_revision_ids(
3062.2.7 by Aaron Bentley
Prevent reverse cherry-picking with weave
392
            this_tree, 'rev2b', 'rev3b', other_tree.branch)
393
        merger.merge_type = _mod_merge.Merge3Merger
394
        merger.do_merge()
395
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
396
    def test_merge3_will_detect_cherrypick(self):
397
        this_tree = self.make_branch_and_tree('this')
398
        self.build_tree_contents([('this/file', "a\n")])
399
        this_tree.add('file')
400
        this_tree.commit('rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
401
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
402
        self.build_tree_contents([('other/file', "a\nb\n")])
403
        other_tree.commit('rev2b', rev_id='rev2b')
404
        self.build_tree_contents([('other/file', "a\nb\nc\n")])
405
        other_tree.commit('rev3b', rev_id='rev3b')
406
        this_tree.lock_write()
407
        self.addCleanup(this_tree.unlock)
408
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
409
        merger = _mod_merge.Merger.from_revision_ids(
3249.3.1 by John Arbash Meinel
Implement cherrypick support for Merge3
410
            this_tree, 'rev3b', 'rev2b', other_tree.branch)
411
        merger.merge_type = _mod_merge.Merge3Merger
412
        merger.do_merge()
413
        self.assertFileEqual('a\n'
414
                             '<<<<<<< TREE\n'
415
                             '=======\n'
416
                             'c\n'
417
                             '>>>>>>> MERGE-SOURCE\n',
418
                             'this/file')
419
5954.4.2 by Aaron Bentley
Support merging into null tree.
420
    def test_merge_reverse_revision_range(self):
421
        tree = self.make_branch_and_tree(".")
422
        tree.lock_write()
423
        self.addCleanup(tree.unlock)
424
        self.build_tree(['a'])
425
        tree.add('a')
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
426
        first_rev = tree.commit("added a")
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
427
        merger = _mod_merge.Merger.from_revision_ids(tree,
5954.4.2 by Aaron Bentley
Support merging into null tree.
428
                                          _mod_revision.NULL_REVISION,
429
                                          first_rev)
430
        merger.merge_type = _mod_merge.Merge3Merger
431
        merger.interesting_files = 'a'
432
        conflict_count = merger.do_merge()
433
        self.assertEqual(0, conflict_count)
434
435
        self.assertPathDoesNotExist("a")
436
        tree.revert()
437
        self.assertPathExists("a")
438
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
439
    def test_make_merger(self):
440
        this_tree = self.make_branch_and_tree('this')
441
        this_tree.commit('rev1', rev_id='rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
442
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
443
        this_tree.commit('rev2', rev_id='rev2a')
444
        other_tree.commit('rev2', rev_id='rev2b')
445
        this_tree.lock_write()
446
        self.addCleanup(this_tree.unlock)
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
447
        merger = _mod_merge.Merger.from_revision_ids(
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
448
            this_tree, 'rev2b', other_branch=other_tree.branch)
449
        merger.merge_type = _mod_merge.Merge3Merger
450
        tree_merger = merger.make_merger()
451
        self.assertIs(_mod_merge.Merge3Merger, tree_merger.__class__)
6410.1.1 by Jelmer Vernooij
Add other_branch argument to Merge3Merger.
452
        self.assertEqual('rev2b',
453
            tree_merger.other_tree.get_revision_id())
454
        self.assertEqual('rev1',
455
            tree_merger.base_tree.get_revision_id())
456
        self.assertEqual(other_tree.branch, tree_merger.other_branch)
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
457
458
    def test_make_preview_transform(self):
459
        this_tree = self.make_branch_and_tree('this')
460
        self.build_tree_contents([('this/file', '1\n')])
461
        this_tree.add('file', 'file-id')
462
        this_tree.commit('rev1', rev_id='rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
463
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
464
        self.build_tree_contents([('this/file', '1\n2a\n')])
465
        this_tree.commit('rev2', rev_id='rev2a')
466
        self.build_tree_contents([('other/file', '2b\n1\n')])
467
        other_tree.commit('rev2', rev_id='rev2b')
468
        this_tree.lock_write()
469
        self.addCleanup(this_tree.unlock)
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
470
        merger = _mod_merge.Merger.from_revision_ids(
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
471
            this_tree, 'rev2b', other_branch=other_tree.branch)
472
        merger.merge_type = _mod_merge.Merge3Merger
473
        tree_merger = merger.make_merger()
474
        tt = tree_merger.make_preview_transform()
3199.1.5 by Vincent Ladeuil
Fix two more leaking tmp dirs, by reworking TransformPreview lock handling.
475
        self.addCleanup(tt.finalize)
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
476
        preview_tree = tt.get_preview_tree()
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
477
        tree_file = this_tree.get_file('file')
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
478
        try:
479
            self.assertEqual('1\n2a\n', tree_file.read())
480
        finally:
481
            tree_file.close()
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
482
        preview_file = preview_tree.get_file('file')
3008.1.21 by Aaron Bentley
Make compute_transform private, test make_preview_transform
483
        try:
484
            self.assertEqual('2b\n1\n2a\n', preview_file.read())
485
        finally:
486
            preview_file.close()
487
3008.1.22 by Aaron Bentley
Get do_merge under test
488
    def test_do_merge(self):
489
        this_tree = self.make_branch_and_tree('this')
490
        self.build_tree_contents([('this/file', '1\n')])
491
        this_tree.add('file', 'file-id')
492
        this_tree.commit('rev1', rev_id='rev1')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
493
        other_tree = this_tree.controldir.sprout('other').open_workingtree()
3008.1.22 by Aaron Bentley
Get do_merge under test
494
        self.build_tree_contents([('this/file', '1\n2a\n')])
495
        this_tree.commit('rev2', rev_id='rev2a')
496
        self.build_tree_contents([('other/file', '2b\n1\n')])
497
        other_tree.commit('rev2', rev_id='rev2b')
498
        this_tree.lock_write()
499
        self.addCleanup(this_tree.unlock)
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
500
        merger = _mod_merge.Merger.from_revision_ids(
3008.1.22 by Aaron Bentley
Get do_merge under test
501
            this_tree, 'rev2b', other_branch=other_tree.branch)
502
        merger.merge_type = _mod_merge.Merge3Merger
503
        tree_merger = merger.make_merger()
504
        tt = tree_merger.do_merge()
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
505
        tree_file = this_tree.get_file('file')
3008.1.22 by Aaron Bentley
Get do_merge under test
506
        try:
507
            self.assertEqual('2b\n1\n2a\n', tree_file.read())
508
        finally:
509
            tree_file.close()
510
5993.2.3 by Jelmer Vernooij
Update NEWS, consistently use require_tree_root as argument everywhere.
511
    def test_merge_require_tree_root(self):
5993.2.2 by Jelmer Vernooij
Fix fixing up root ids.
512
        tree = self.make_branch_and_tree(".")
513
        tree.lock_write()
514
        self.addCleanup(tree.unlock)
515
        self.build_tree(['a'])
516
        tree.add('a')
6165.4.4 by Jelmer Vernooij
Avoid .revision_history().
517
        first_rev = tree.commit("added a")
5993.2.2 by Jelmer Vernooij
Fix fixing up root ids.
518
        old_root_id = tree.get_root_id()
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
519
        merger = _mod_merge.Merger.from_revision_ids(tree,
5993.2.2 by Jelmer Vernooij
Fix fixing up root ids.
520
                                          _mod_revision.NULL_REVISION,
521
                                          first_rev)
522
        merger.merge_type = _mod_merge.Merge3Merger
523
        conflict_count = merger.do_merge()
524
        self.assertEqual(0, conflict_count)
6619.3.12 by Jelmer Vernooij
Use 2to3 set_literal fixer.
525
        self.assertEqual({old_root_id}, tree.all_file_ids())
5993.2.2 by Jelmer Vernooij
Fix fixing up root ids.
526
        tree.set_parent_ids([])
527
1551.19.32 by Aaron Bentley
Don't traceback when adding files to a deleted root (abentley, #210092)
528
    def test_merge_add_into_deleted_root(self):
529
        # Yes, people actually do this.  And report bugs if it breaks.
530
        source = self.make_branch_and_tree('source', format='rich-root-pack')
531
        self.build_tree(['source/foo/'])
532
        source.add('foo', 'foo-id')
533
        source.commit('Add foo')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
534
        target = source.controldir.sprout('target').open_workingtree()
1551.19.32 by Aaron Bentley
Don't traceback when adding files to a deleted root (abentley, #210092)
535
        subtree = target.extract('foo-id')
536
        subtree.commit('Delete root')
537
        self.build_tree(['source/bar'])
538
        source.add('bar', 'bar-id')
539
        source.commit('Add bar')
540
        subtree.merge_from_branch(source.branch)
541
3649.3.1 by Jelmer Vernooij
Merging from a previously joined branch will no longer cause a traceback.
542
    def test_merge_joined_branch(self):
543
        source = self.make_branch_and_tree('source', format='rich-root-pack')
544
        self.build_tree(['source/foo'])
545
        source.add('foo')
546
        source.commit('Add foo')
547
        target = self.make_branch_and_tree('target', format='rich-root-pack')
548
        self.build_tree(['target/bla'])
549
        target.add('bla')
550
        target.commit('Add bla')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
551
        nested = source.controldir.sprout('target/subtree').open_workingtree()
3649.3.1 by Jelmer Vernooij
Merging from a previously joined branch will no longer cause a traceback.
552
        target.subsume(nested)
553
        target.commit('Join nested')
554
        self.build_tree(['source/bar'])
555
        source.add('bar')
556
        source.commit('Add bar')
557
        target.merge_from_branch(source.branch)
558
        target.commit('Merge source')
559
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
560
561
class TestPlanMerge(TestCaseWithMemoryTransport):
562
563
    def setUp(self):
6552.1.4 by Vincent Ladeuil
Remaining tests matching setup(self) that can be rewritten with super().
564
        super(TestPlanMerge, self).setUp()
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
565
        mapper = versionedfile.PrefixMapper()
566
        factory = knit.make_file_factory(True, mapper)
567
        self.vf = factory(self.get_transport())
568
        self.plan_merge_vf = versionedfile._PlanMergeVersionedFile('root')
569
        self.plan_merge_vf.fallback_versionedfiles.append(self.vf)
570
571
    def add_version(self, key, parents, text):
572
        self.vf.add_lines(key, parents, [c+'\n' for c in text])
573
3514.2.10 by John Arbash Meinel
Handle more edge cases.
574
    def add_rev(self, prefix, revision_id, parents, text):
575
        self.add_version((prefix, revision_id), [(prefix, p) for p in parents],
576
                         text)
577
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
578
    def add_uncommitted_version(self, key, parents, text):
579
        self.plan_merge_vf.add_lines(key, parents,
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
580
                                     [c+'\n' for c in text])
581
582
    def setup_plan_merge(self):
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
583
        self.add_rev('root', 'A', [], 'abc')
584
        self.add_rev('root', 'B', ['A'], 'acehg')
585
        self.add_rev('root', 'C', ['A'], 'fabg')
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
586
        return _PlanMerge('B', 'C', self.plan_merge_vf, ('root',))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
587
588
    def setup_plan_merge_uncommitted(self):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
589
        self.add_version(('root', 'A'), [], 'abc')
590
        self.add_uncommitted_version(('root', 'B:'), [('root', 'A')], 'acehg')
591
        self.add_uncommitted_version(('root', 'C:'), [('root', 'A')], 'fabg')
592
        return _PlanMerge('B:', 'C:', self.plan_merge_vf, ('root',))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
593
4634.101.8 by John Arbash Meinel
Add the criss-cross flip-flop 'bug' for weave merge.
594
    def test_base_from_plan(self):
595
        self.setup_plan_merge()
596
        plan = self.plan_merge_vf.plan_merge('B', 'C')
597
        pwm = versionedfile.PlanWeaveMerge(plan)
598
        self.assertEqual(['a\n', 'b\n', 'c\n'], pwm.base_from_plan())
599
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
600
    def test_unique_lines(self):
601
        plan = self.setup_plan_merge()
602
        self.assertEqual(plan._unique_lines(
603
            plan._get_matching_blocks('B', 'C')),
604
            ([1, 2, 3], [0, 2]))
605
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
606
    def test_plan_merge(self):
607
        self.setup_plan_merge()
608
        plan = self.plan_merge_vf.plan_merge('B', 'C')
609
        self.assertEqual([
610
                          ('new-b', 'f\n'),
611
                          ('unchanged', 'a\n'),
612
                          ('killed-a', 'b\n'),
613
                          ('killed-b', 'c\n'),
614
                          ('new-a', 'e\n'),
615
                          ('new-a', 'h\n'),
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
616
                          ('new-a', 'g\n'),
617
                          ('new-b', 'g\n')],
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
618
                         list(plan))
619
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
620
    def test_plan_merge_cherrypick(self):
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
621
        self.add_rev('root', 'A', [], 'abc')
622
        self.add_rev('root', 'B', ['A'], 'abcde')
623
        self.add_rev('root', 'C', ['A'], 'abcefg')
624
        self.add_rev('root', 'D', ['A', 'B', 'C'], 'abcdegh')
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
625
        my_plan = _PlanMerge('B', 'D', self.plan_merge_vf, ('root',))
3514.2.11 by John Arbash Meinel
Shortcut the case when one revision is in the ancestry of the other.
626
        # We shortcut when one text supersedes the other in the per-file graph.
627
        # We don't actually need to compare the texts at this point.
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
628
        self.assertEqual([
3514.2.11 by John Arbash Meinel
Shortcut the case when one revision is in the ancestry of the other.
629
                          ('new-b', 'a\n'),
630
                          ('new-b', 'b\n'),
631
                          ('new-b', 'c\n'),
632
                          ('new-b', 'd\n'),
633
                          ('new-b', 'e\n'),
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
634
                          ('new-b', 'g\n'),
635
                          ('new-b', 'h\n')],
636
                          list(my_plan.plan_merge()))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
637
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
638
    def test_plan_merge_no_common_ancestor(self):
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
639
        self.add_rev('root', 'A', [], 'abc')
640
        self.add_rev('root', 'B', [], 'xyz')
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
641
        my_plan = _PlanMerge('A', 'B', self.plan_merge_vf, ('root',))
642
        self.assertEqual([
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
643
                          ('new-a', 'a\n'),
644
                          ('new-a', 'b\n'),
645
                          ('new-a', 'c\n'),
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
646
                          ('new-b', 'x\n'),
647
                          ('new-b', 'y\n'),
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
648
                          ('new-b', 'z\n')],
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
649
                          list(my_plan.plan_merge()))
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
650
3514.2.10 by John Arbash Meinel
Handle more edge cases.
651
    def test_plan_merge_tail_ancestors(self):
652
        # The graph looks like this:
653
        #       A       # Common to all ancestors
654
        #      / \
655
        #     B   C     # Ancestors of E, only common to one side
656
        #     |\ /|
657
        #     D E F     # D, F are unique to G, H respectively
658
        #     |/ \|     # E is the LCA for G & H, and the unique LCA for
659
        #     G   H     # I, J
660
        #     |\ /|
661
        #     | X |
662
        #     |/ \|
663
        #     I   J     # criss-cross merge of G, H
664
        #
665
        # In this situation, a simple pruning of ancestors of E will leave D &
666
        # F "dangling", which looks like they introduce lines different from
667
        # the ones in E, but in actuality C&B introduced the lines, and they
668
        # are already present in E
669
670
        # Introduce the base text
671
        self.add_rev('root', 'A', [], 'abc')
672
        # Introduces a new line B
673
        self.add_rev('root', 'B', ['A'], 'aBbc')
674
        # Introduces a new line C
675
        self.add_rev('root', 'C', ['A'], 'abCc')
676
        # Introduce new line D
677
        self.add_rev('root', 'D', ['B'], 'DaBbc')
678
        # Merges B and C by just incorporating both
679
        self.add_rev('root', 'E', ['B', 'C'], 'aBbCc')
680
        # Introduce new line F
681
        self.add_rev('root', 'F', ['C'], 'abCcF')
682
        # Merge D & E by just combining the texts
683
        self.add_rev('root', 'G', ['D', 'E'], 'DaBbCc')
684
        # Merge F & E by just combining the texts
685
        self.add_rev('root', 'H', ['F', 'E'], 'aBbCcF')
686
        # Merge G & H by just combining texts
687
        self.add_rev('root', 'I', ['G', 'H'], 'DaBbCcF')
688
        # Merge G & H but supersede an old line in B
689
        self.add_rev('root', 'J', ['H', 'G'], 'DaJbCcF')
690
        plan = self.plan_merge_vf.plan_merge('I', 'J')
691
        self.assertEqual([
692
                          ('unchanged', 'D\n'),
693
                          ('unchanged', 'a\n'),
694
                          ('killed-b', 'B\n'),
695
                          ('new-b', 'J\n'),
696
                          ('unchanged', 'b\n'),
697
                          ('unchanged', 'C\n'),
698
                          ('unchanged', 'c\n'),
699
                          ('unchanged', 'F\n')],
700
                         list(plan))
701
702
    def test_plan_merge_tail_triple_ancestors(self):
703
        # The graph looks like this:
704
        #       A       # Common to all ancestors
705
        #      / \
706
        #     B   C     # Ancestors of E, only common to one side
707
        #     |\ /|
708
        #     D E F     # D, F are unique to G, H respectively
709
        #     |/|\|     # E is the LCA for G & H, and the unique LCA for
710
        #     G Q H     # I, J
711
        #     |\ /|     # Q is just an extra node which is merged into both
712
        #     | X |     # I and J
713
        #     |/ \|
714
        #     I   J     # criss-cross merge of G, H
715
        #
716
        # This is the same as the test_plan_merge_tail_ancestors, except we add
717
        # a third LCA that doesn't add new lines, but will trigger our more
718
        # involved ancestry logic
719
720
        self.add_rev('root', 'A', [], 'abc')
721
        self.add_rev('root', 'B', ['A'], 'aBbc')
722
        self.add_rev('root', 'C', ['A'], 'abCc')
723
        self.add_rev('root', 'D', ['B'], 'DaBbc')
724
        self.add_rev('root', 'E', ['B', 'C'], 'aBbCc')
725
        self.add_rev('root', 'F', ['C'], 'abCcF')
726
        self.add_rev('root', 'G', ['D', 'E'], 'DaBbCc')
727
        self.add_rev('root', 'H', ['F', 'E'], 'aBbCcF')
728
        self.add_rev('root', 'Q', ['E'], 'aBbCc')
729
        self.add_rev('root', 'I', ['G', 'Q', 'H'], 'DaBbCcF')
730
        # Merge G & H but supersede an old line in B
731
        self.add_rev('root', 'J', ['H', 'Q', 'G'], 'DaJbCcF')
732
        plan = self.plan_merge_vf.plan_merge('I', 'J')
733
        self.assertEqual([
734
                          ('unchanged', 'D\n'),
735
                          ('unchanged', 'a\n'),
736
                          ('killed-b', 'B\n'),
737
                          ('new-b', 'J\n'),
738
                          ('unchanged', 'b\n'),
739
                          ('unchanged', 'C\n'),
740
                          ('unchanged', 'c\n'),
741
                          ('unchanged', 'F\n')],
742
                         list(plan))
743
3514.2.14 by John Arbash Meinel
Bring in the code to collapse linear portions of the graph.
744
    def test_plan_merge_2_tail_triple_ancestors(self):
745
        # The graph looks like this:
746
        #     A   B     # 2 tails going back to NULL
747
        #     |\ /|
748
        #     D E F     # D, is unique to G, F to H
749
        #     |/|\|     # E is the LCA for G & H, and the unique LCA for
750
        #     G Q H     # I, J
751
        #     |\ /|     # Q is just an extra node which is merged into both
752
        #     | X |     # I and J
753
        #     |/ \|
754
        #     I   J     # criss-cross merge of G, H (and Q)
755
        #
756
757
        # This is meant to test after hitting a 3-way LCA, and multiple tail
758
        # ancestors (only have NULL_REVISION in common)
759
760
        self.add_rev('root', 'A', [], 'abc')
761
        self.add_rev('root', 'B', [], 'def')
762
        self.add_rev('root', 'D', ['A'], 'Dabc')
763
        self.add_rev('root', 'E', ['A', 'B'], 'abcdef')
764
        self.add_rev('root', 'F', ['B'], 'defF')
765
        self.add_rev('root', 'G', ['D', 'E'], 'Dabcdef')
766
        self.add_rev('root', 'H', ['F', 'E'], 'abcdefF')
767
        self.add_rev('root', 'Q', ['E'], 'abcdef')
768
        self.add_rev('root', 'I', ['G', 'Q', 'H'], 'DabcdefF')
769
        # Merge G & H but supersede an old line in B
770
        self.add_rev('root', 'J', ['H', 'Q', 'G'], 'DabcdJfF')
771
        plan = self.plan_merge_vf.plan_merge('I', 'J')
772
        self.assertEqual([
773
                          ('unchanged', 'D\n'),
774
                          ('unchanged', 'a\n'),
775
                          ('unchanged', 'b\n'),
776
                          ('unchanged', 'c\n'),
777
                          ('unchanged', 'd\n'),
778
                          ('killed-b', 'e\n'),
779
                          ('new-b', 'J\n'),
780
                          ('unchanged', 'f\n'),
781
                          ('unchanged', 'F\n')],
782
                         list(plan))
783
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
784
    def test_plan_merge_uncommitted_files(self):
3062.1.13 by Aaron Bentley
Make _PlanMerge an implementation detail of _PlanMergeVersionedFile
785
        self.setup_plan_merge_uncommitted()
786
        plan = self.plan_merge_vf.plan_merge('B:', 'C:')
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
787
        self.assertEqual([
788
                          ('new-b', 'f\n'),
789
                          ('unchanged', 'a\n'),
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
790
                          ('killed-a', 'b\n'),
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
791
                          ('killed-b', 'c\n'),
792
                          ('new-a', 'e\n'),
793
                          ('new-a', 'h\n'),
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
794
                          ('new-a', 'g\n'),
795
                          ('new-b', 'g\n')],
796
                         list(plan))
797
798
    def test_plan_merge_insert_order(self):
799
        """Weave merges are sensitive to the order of insertion.
3943.8.1 by Marius Kruger
remove all trailing whitespace from bzr source
800
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
801
        Specifically for overlapping regions, it effects which region gets put
802
        'first'. And when a user resolves an overlapping merge, if they use the
803
        same ordering, then the lines match the parents, if they don't only
804
        *some* of the lines match.
805
        """
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
806
        self.add_rev('root', 'A', [], 'abcdef')
807
        self.add_rev('root', 'B', ['A'], 'abwxcdef')
808
        self.add_rev('root', 'C', ['A'], 'abyzcdef')
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
809
        # Merge, and resolve the conflict by adding *both* sets of lines
810
        # If we get the ordering wrong, these will look like new lines in D,
811
        # rather than carried over from B, C
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
812
        self.add_rev('root', 'D', ['B', 'C'],
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
813
                         'abwxyzcdef')
814
        # Supersede the lines in B and delete the lines in C, which will
815
        # conflict if they are treated as being in D
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
816
        self.add_rev('root', 'E', ['C', 'B'],
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
817
                         'abnocdef')
818
        # Same thing for the lines in C
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
819
        self.add_rev('root', 'F', ['C'], 'abpqcdef')
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
820
        plan = self.plan_merge_vf.plan_merge('D', 'E')
821
        self.assertEqual([
822
                          ('unchanged', 'a\n'),
823
                          ('unchanged', 'b\n'),
824
                          ('killed-b', 'w\n'),
825
                          ('killed-b', 'x\n'),
826
                          ('killed-b', 'y\n'),
827
                          ('killed-b', 'z\n'),
828
                          ('new-b', 'n\n'),
829
                          ('new-b', 'o\n'),
830
                          ('unchanged', 'c\n'),
831
                          ('unchanged', 'd\n'),
832
                          ('unchanged', 'e\n'),
833
                          ('unchanged', 'f\n')],
834
                         list(plan))
835
        plan = self.plan_merge_vf.plan_merge('E', 'D')
836
        # Going in the opposite direction shows the effect of the opposite plan
837
        self.assertEqual([
838
                          ('unchanged', 'a\n'),
839
                          ('unchanged', 'b\n'),
840
                          ('new-b', 'w\n'),
841
                          ('new-b', 'x\n'),
842
                          ('killed-a', 'y\n'),
843
                          ('killed-a', 'z\n'),
844
                          ('killed-both', 'w\n'),
845
                          ('killed-both', 'x\n'),
846
                          ('new-a', 'n\n'),
847
                          ('new-a', 'o\n'),
848
                          ('unchanged', 'c\n'),
849
                          ('unchanged', 'd\n'),
850
                          ('unchanged', 'e\n'),
851
                          ('unchanged', 'f\n')],
3062.1.9 by Aaron Bentley
Move PlanMerge into merge and _PlanMergeVersionedFile into versionedfile
852
                         list(plan))
3062.2.1 by Aaron Bentley
Add support for plan-merge with a base
853
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
854
    def test_plan_merge_criss_cross(self):
855
        # This is specificly trying to trigger problems when using limited
856
        # ancestry and weaves. The ancestry graph looks like:
3514.2.8 by John Arbash Meinel
The insertion ordering into the weave has an impact on conflicts.
857
        #       XX      unused ancestor, should not show up in the weave
858
        #       |
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
859
        #       A       Unique LCA
860
        #       |\
861
        #       B \     Introduces a line 'foo'
862
        #      / \ \
863
        #     C   D E   C & D both have 'foo', E has different changes
864
        #     |\ /| |
865
        #     | X | |
866
        #     |/ \|/
867
        #     F   G      All of C, D, E are merged into F and G, so they are
868
        #                all common ancestors.
869
        #
870
        # The specific issue with weaves:
871
        #   B introduced a text ('foo') that is present in both C and D.
872
        #   If we do not include B (because it isn't an ancestor of E), then
873
        #   the A=>C and A=>D look like both sides independently introduce the
874
        #   text ('foo'). If F does not modify the text, it would still appear
875
        #   to have deleted on of the versions from C or D. If G then modifies
876
        #   'foo', it should appear as superseding the value in F (since it
877
        #   came from B), rather than conflict because of the resolution during
878
        #   C & D.
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
879
        self.add_rev('root', 'XX', [], 'qrs')
880
        self.add_rev('root', 'A', ['XX'], 'abcdef')
881
        self.add_rev('root', 'B', ['A'], 'axcdef')
882
        self.add_rev('root', 'C', ['B'], 'axcdefg')
883
        self.add_rev('root', 'D', ['B'], 'haxcdef')
884
        self.add_rev('root', 'E', ['A'], 'abcdyf')
885
        # Simple combining of all texts
886
        self.add_rev('root', 'F', ['C', 'D', 'E'], 'haxcdyfg')
887
        # combine and supersede 'x'
888
        self.add_rev('root', 'G', ['C', 'D', 'E'], 'hazcdyfg')
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
889
        plan = self.plan_merge_vf.plan_merge('F', 'G')
890
        self.assertEqual([
891
                          ('unchanged', 'h\n'),
892
                          ('unchanged', 'a\n'),
3514.2.7 by John Arbash Meinel
Fix the failing test by implementing the fallback logic.
893
                          ('killed-base', 'b\n'),
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
894
                          ('killed-b', 'x\n'),
895
                          ('new-b', 'z\n'),
896
                          ('unchanged', 'c\n'),
897
                          ('unchanged', 'd\n'),
898
                          ('killed-base', 'e\n'),
899
                          ('unchanged', 'y\n'),
900
                          ('unchanged', 'f\n'),
901
                          ('unchanged', 'g\n')],
902
                         list(plan))
4634.101.8 by John Arbash Meinel
Add the criss-cross flip-flop 'bug' for weave merge.
903
        plan = self.plan_merge_vf.plan_lca_merge('F', 'G')
904
        # This is one of the main differences between plan_merge and
905
        # plan_lca_merge. plan_lca_merge generates a conflict for 'x => z',
906
        # because 'x' was not present in one of the bases. However, in this
907
        # case it is spurious because 'x' does not exist in the global base A.
908
        self.assertEqual([
909
                          ('unchanged', 'h\n'),
910
                          ('unchanged', 'a\n'),
911
                          ('conflicted-a', 'x\n'),
912
                          ('new-b', 'z\n'),
913
                          ('unchanged', 'c\n'),
914
                          ('unchanged', 'd\n'),
915
                          ('unchanged', 'y\n'),
916
                          ('unchanged', 'f\n'),
917
                          ('unchanged', 'g\n')],
918
                         list(plan))
919
920
    def test_criss_cross_flip_flop(self):
921
        # This is specificly trying to trigger problems when using limited
922
        # ancestry and weaves. The ancestry graph looks like:
923
        #       XX      unused ancestor, should not show up in the weave
924
        #       |
925
        #       A       Unique LCA
926
        #      / \  
927
        #     B   C     B & C both introduce a new line
928
        #     |\ /|  
929
        #     | X |  
930
        #     |/ \| 
931
        #     D   E     B & C are both merged, so both are common ancestors
932
        #               In the process of merging, both sides order the new
933
        #               lines differently
934
        #
935
        self.add_rev('root', 'XX', [], 'qrs')
936
        self.add_rev('root', 'A', ['XX'], 'abcdef')
937
        self.add_rev('root', 'B', ['A'], 'abcdgef')
938
        self.add_rev('root', 'C', ['A'], 'abcdhef')
939
        self.add_rev('root', 'D', ['B', 'C'], 'abcdghef')
940
        self.add_rev('root', 'E', ['C', 'B'], 'abcdhgef')
941
        plan = list(self.plan_merge_vf.plan_merge('D', 'E'))
942
        self.assertEqual([
943
                          ('unchanged', 'a\n'),
944
                          ('unchanged', 'b\n'),
945
                          ('unchanged', 'c\n'),
946
                          ('unchanged', 'd\n'),
947
                          ('new-b', 'h\n'),
948
                          ('unchanged', 'g\n'),
949
                          ('killed-b', 'h\n'),
950
                          ('unchanged', 'e\n'),
951
                          ('unchanged', 'f\n'),
952
                         ], plan)
953
        pwm = versionedfile.PlanWeaveMerge(plan)
954
        self.assertEqualDiff('\n'.join('abcdghef') + '\n',
955
                             ''.join(pwm.base_from_plan()))
956
        # Reversing the order reverses the merge plan, and final order of 'hg'
957
        # => 'gh'
958
        plan = list(self.plan_merge_vf.plan_merge('E', 'D'))
959
        self.assertEqual([
960
                          ('unchanged', 'a\n'),
961
                          ('unchanged', 'b\n'),
962
                          ('unchanged', 'c\n'),
963
                          ('unchanged', 'd\n'),
964
                          ('new-b', 'g\n'),
965
                          ('unchanged', 'h\n'),
966
                          ('killed-b', 'g\n'),
967
                          ('unchanged', 'e\n'),
968
                          ('unchanged', 'f\n'),
969
                         ], plan)
970
        pwm = versionedfile.PlanWeaveMerge(plan)
971
        self.assertEqualDiff('\n'.join('abcdhgef') + '\n',
972
                             ''.join(pwm.base_from_plan()))
973
        # This is where lca differs, in that it (fairly correctly) determines
974
        # that there is a conflict because both sides resolved the merge
975
        # differently
976
        plan = list(self.plan_merge_vf.plan_lca_merge('D', 'E'))
977
        self.assertEqual([
978
                          ('unchanged', 'a\n'),
979
                          ('unchanged', 'b\n'),
980
                          ('unchanged', 'c\n'),
981
                          ('unchanged', 'd\n'),
982
                          ('conflicted-b', 'h\n'),
983
                          ('unchanged', 'g\n'),
984
                          ('conflicted-a', 'h\n'),
985
                          ('unchanged', 'e\n'),
986
                          ('unchanged', 'f\n'),
987
                         ], plan)
988
        pwm = versionedfile.PlanWeaveMerge(plan)
4634.101.9 by John Arbash Meinel
Reverse the .BASE values for --lca and conflicted lines.
989
        self.assertEqualDiff('\n'.join('abcdgef') + '\n',
4634.101.8 by John Arbash Meinel
Add the criss-cross flip-flop 'bug' for weave merge.
990
                             ''.join(pwm.base_from_plan()))
991
        # Reversing it changes what line is doubled, but still gives a
992
        # double-conflict
993
        plan = list(self.plan_merge_vf.plan_lca_merge('E', 'D'))
994
        self.assertEqual([
995
                          ('unchanged', 'a\n'),
996
                          ('unchanged', 'b\n'),
997
                          ('unchanged', 'c\n'),
998
                          ('unchanged', 'd\n'),
999
                          ('conflicted-b', 'g\n'),
1000
                          ('unchanged', 'h\n'),
1001
                          ('conflicted-a', 'g\n'),
1002
                          ('unchanged', 'e\n'),
1003
                          ('unchanged', 'f\n'),
1004
                         ], plan)
1005
        pwm = versionedfile.PlanWeaveMerge(plan)
4634.101.9 by John Arbash Meinel
Reverse the .BASE values for --lca and conflicted lines.
1006
        self.assertEqualDiff('\n'.join('abcdhef') + '\n',
4634.101.8 by John Arbash Meinel
Add the criss-cross flip-flop 'bug' for weave merge.
1007
                             ''.join(pwm.base_from_plan()))
3514.2.6 by John Arbash Meinel
Write a (failing) test for complex ancestry.
1008
3514.2.12 by John Arbash Meinel
Start refactoring into helper functions
1009
    def assertRemoveExternalReferences(self, filtered_parent_map,
1010
                                       child_map, tails, parent_map):
1011
        """Assert results for _PlanMerge._remove_external_references."""
1012
        (act_filtered_parent_map, act_child_map,
1013
         act_tails) = _PlanMerge._remove_external_references(parent_map)
1014
1015
        # The parent map *should* preserve ordering, but the ordering of
1016
        # children is not strictly defined
1017
        # child_map = dict((k, sorted(children))
1018
        #                  for k, children in child_map.iteritems())
1019
        # act_child_map = dict(k, sorted(children)
1020
        #                      for k, children in act_child_map.iteritems())
1021
        self.assertEqual(filtered_parent_map, act_filtered_parent_map)
1022
        self.assertEqual(child_map, act_child_map)
1023
        self.assertEqual(sorted(tails), sorted(act_tails))
1024
1025
    def test__remove_external_references(self):
1026
        # First, nothing to remove
1027
        self.assertRemoveExternalReferences({3: [2], 2: [1], 1: []},
1028
            {1: [2], 2: [3], 3: []}, [1], {3: [2], 2: [1], 1: []})
1029
        # The reverse direction
1030
        self.assertRemoveExternalReferences({1: [2], 2: [3], 3: []},
1031
            {3: [2], 2: [1], 1: []}, [3], {1: [2], 2: [3], 3: []})
1032
        # Extra references
1033
        self.assertRemoveExternalReferences({3: [2], 2: [1], 1: []},
1034
            {1: [2], 2: [3], 3: []}, [1], {3: [2, 4], 2: [1, 5], 1: [6]})
1035
        # Multiple tails
1036
        self.assertRemoveExternalReferences(
1037
            {4: [2, 3], 3: [], 2: [1], 1: []},
1038
            {1: [2], 2: [4], 3: [4], 4: []},
1039
            [1, 3],
1040
            {4: [2, 3], 3: [5], 2: [1], 1: [6]})
1041
        # Multiple children
1042
        self.assertRemoveExternalReferences(
1043
            {1: [3], 2: [3, 4], 3: [], 4: []},
1044
            {1: [], 2: [], 3: [1, 2], 4: [2]},
1045
            [3, 4],
1046
            {1: [3], 2: [3, 4], 3: [5], 4: []})
1047
3514.2.13 by John Arbash Meinel
Add the ability to prune extra tails from the parent_map.
1048
    def assertPruneTails(self, pruned_map, tails, parent_map):
1049
        child_map = {}
6656.1.1 by Martin
Apply 2to3 dict fixer and clean up resulting mess using view helpers
1050
        for key, parent_keys in parent_map.items():
3514.2.13 by John Arbash Meinel
Add the ability to prune extra tails from the parent_map.
1051
            child_map.setdefault(key, [])
1052
            for pkey in parent_keys:
1053
                child_map.setdefault(pkey, []).append(key)
1054
        _PlanMerge._prune_tails(parent_map, child_map, tails)
1055
        self.assertEqual(pruned_map, parent_map)
1056
1057
    def test__prune_tails(self):
1058
        # Nothing requested to prune
1059
        self.assertPruneTails({1: [], 2: [], 3: []}, [],
1060
                              {1: [], 2: [], 3: []})
1061
        # Prune a single entry
1062
        self.assertPruneTails({1: [], 3: []}, [2],
1063
                              {1: [], 2: [], 3: []})
1064
        # Prune a chain
1065
        self.assertPruneTails({1: []}, [3],
1066
                              {1: [], 2: [3], 3: []})
1067
        # Prune a chain with a diamond
1068
        self.assertPruneTails({1: []}, [5],
1069
                              {1: [], 2: [3, 4], 3: [5], 4: [5], 5: []})
1070
        # Prune a partial chain
1071
        self.assertPruneTails({1: [6], 6:[]}, [5],
1072
                              {1: [2, 6], 2: [3, 4], 3: [5], 4: [5], 5: [],
1073
                               6: []})
1074
        # Prune a chain with multiple tips, that pulls out intermediates
1075
        self.assertPruneTails({1:[3], 3:[]}, [4, 5],
1076
                              {1: [2, 3], 2: [4, 5], 3: [], 4:[], 5:[]})
1077
        self.assertPruneTails({1:[3], 3:[]}, [5, 4],
1078
                              {1: [2, 3], 2: [4, 5], 3: [], 4:[], 5:[]})
1079
3062.2.1 by Aaron Bentley
Add support for plan-merge with a base
1080
    def test_subtract_plans(self):
1081
        old_plan = [
1082
        ('unchanged', 'a\n'),
1083
        ('new-a', 'b\n'),
1084
        ('killed-a', 'c\n'),
1085
        ('new-b', 'd\n'),
1086
        ('new-b', 'e\n'),
1087
        ('killed-b', 'f\n'),
1088
        ('killed-b', 'g\n'),
1089
        ]
1090
        new_plan = [
1091
        ('unchanged', 'a\n'),
1092
        ('new-a', 'b\n'),
1093
        ('killed-a', 'c\n'),
1094
        ('new-b', 'd\n'),
1095
        ('new-b', 'h\n'),
1096
        ('killed-b', 'f\n'),
1097
        ('killed-b', 'i\n'),
1098
        ]
1099
        subtracted_plan = [
1100
        ('unchanged', 'a\n'),
1101
        ('new-a', 'b\n'),
1102
        ('killed-a', 'c\n'),
1103
        ('new-b', 'h\n'),
1104
        ('unchanged', 'f\n'),
1105
        ('killed-b', 'i\n'),
1106
        ]
1107
        self.assertEqual(subtracted_plan,
3062.2.3 by Aaron Bentley
Sync up with bzr.dev API changes
1108
            list(_PlanMerge._subtract_plans(old_plan, new_plan)))
3062.2.1 by Aaron Bentley
Add support for plan-merge with a base
1109
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1110
    def setup_merge_with_base(self):
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
1111
        self.add_rev('root', 'COMMON', [], 'abc')
1112
        self.add_rev('root', 'THIS', ['COMMON'], 'abcd')
1113
        self.add_rev('root', 'BASE', ['COMMON'], 'eabc')
1114
        self.add_rev('root', 'OTHER', ['BASE'], 'eafb')
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1115
1116
    def test_plan_merge_with_base(self):
1117
        self.setup_merge_with_base()
3062.2.3 by Aaron Bentley
Sync up with bzr.dev API changes
1118
        plan = self.plan_merge_vf.plan_merge('THIS', 'OTHER', 'BASE')
3062.2.1 by Aaron Bentley
Add support for plan-merge with a base
1119
        self.assertEqual([('unchanged', 'a\n'),
1120
                          ('new-b', 'f\n'),
1121
                          ('unchanged', 'b\n'),
1122
                          ('killed-b', 'c\n'),
1123
                          ('new-a', 'd\n')
1124
                         ], list(plan))
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1125
1126
    def test_plan_lca_merge(self):
1127
        self.setup_plan_merge()
1128
        plan = self.plan_merge_vf.plan_lca_merge('B', 'C')
1129
        self.assertEqual([
1130
                          ('new-b', 'f\n'),
1131
                          ('unchanged', 'a\n'),
1132
                          ('killed-b', 'c\n'),
1133
                          ('new-a', 'e\n'),
1134
                          ('new-a', 'h\n'),
1135
                          ('killed-a', 'b\n'),
1136
                          ('unchanged', 'g\n')],
1137
                         list(plan))
1138
1139
    def test_plan_lca_merge_uncommitted_files(self):
1140
        self.setup_plan_merge_uncommitted()
1141
        plan = self.plan_merge_vf.plan_lca_merge('B:', 'C:')
1142
        self.assertEqual([
1143
                          ('new-b', 'f\n'),
1144
                          ('unchanged', 'a\n'),
1145
                          ('killed-b', 'c\n'),
1146
                          ('new-a', 'e\n'),
1147
                          ('new-a', 'h\n'),
1148
                          ('killed-a', 'b\n'),
1149
                          ('unchanged', 'g\n')],
1150
                         list(plan))
1151
1152
    def test_plan_lca_merge_with_base(self):
1153
        self.setup_merge_with_base()
1154
        plan = self.plan_merge_vf.plan_lca_merge('THIS', 'OTHER', 'BASE')
1155
        self.assertEqual([('unchanged', 'a\n'),
1156
                          ('new-b', 'f\n'),
1157
                          ('unchanged', 'b\n'),
1158
                          ('killed-b', 'c\n'),
1159
                          ('new-a', 'd\n')
1160
                         ], list(plan))
1161
1162
    def test_plan_lca_merge_with_criss_cross(self):
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1163
        self.add_version(('root', 'ROOT'), [], 'abc')
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1164
        # each side makes a change
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1165
        self.add_version(('root', 'REV1'), [('root', 'ROOT')], 'abcd')
1166
        self.add_version(('root', 'REV2'), [('root', 'ROOT')], 'abce')
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1167
        # both sides merge, discarding others' changes
3350.6.4 by Robert Collins
First cut at pluralised VersionedFiles. Some rather massive API incompatabilities, primarily because of the difficulty of coherence among competing stores.
1168
        self.add_version(('root', 'LCA1'),
1169
            [('root', 'REV1'), ('root', 'REV2')], 'abcd')
1170
        self.add_version(('root', 'LCA2'),
1171
            [('root', 'REV1'), ('root', 'REV2')], 'fabce')
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1172
        plan = self.plan_merge_vf.plan_lca_merge('LCA1', 'LCA2')
3144.3.10 by Aaron Bentley
Use correct index when emitting conflicted-b
1173
        self.assertEqual([('new-b', 'f\n'),
1174
                          ('unchanged', 'a\n'),
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1175
                          ('unchanged', 'b\n'),
1176
                          ('unchanged', 'c\n'),
3144.3.3 by Aaron Bentley
Update test for new conflicted types
1177
                          ('conflicted-a', 'd\n'),
1178
                          ('conflicted-b', 'e\n'),
3144.3.1 by Aaron Bentley
Implement LCA merge, with problematic conflict markers
1179
                         ], list(plan))
3144.5.3 by Aaron Bentley
Test interesting_files for LCA merge
1180
3287.17.1 by John Arbash Meinel
Fix bug #235715 by using the empty list as the text for a base of NULL_REVISION.
1181
    def test_plan_lca_merge_with_null(self):
3350.6.5 by Robert Collins
Update to bzr.dev.
1182
        self.add_version(('root', 'A'), [], 'ab')
1183
        self.add_version(('root', 'B'), [], 'bc')
3287.17.1 by John Arbash Meinel
Fix bug #235715 by using the empty list as the text for a base of NULL_REVISION.
1184
        plan = self.plan_merge_vf.plan_lca_merge('A', 'B')
1185
        self.assertEqual([('new-a', 'a\n'),
1186
                          ('unchanged', 'b\n'),
1187
                          ('new-b', 'c\n'),
1188
                         ], list(plan))
1189
3514.2.1 by Aaron Bentley
Test for correct conflicts on delete + change
1190
    def test_plan_merge_with_delete_and_change(self):
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
1191
        self.add_rev('root', 'C', [], 'a')
1192
        self.add_rev('root', 'A', ['C'], 'b')
1193
        self.add_rev('root', 'B', ['C'], '')
3514.2.1 by Aaron Bentley
Test for correct conflicts on delete + change
1194
        plan = self.plan_merge_vf.plan_merge('A', 'B')
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
1195
        self.assertEqual([('killed-both', 'a\n'),
1196
                          ('new-a', 'b\n'),
1197
                         ], list(plan))
1198
1199
    def test_plan_merge_with_move_and_change(self):
3514.2.17 by John Arbash Meinel
On Ian's suggestion, change the 'plan_merge' tests to use the clearer 'add_rev' instead of 'add_version'
1200
        self.add_rev('root', 'C', [], 'abcd')
1201
        self.add_rev('root', 'A', ['C'], 'acbd')
1202
        self.add_rev('root', 'B', ['C'], 'aBcd')
3514.2.2 by John Arbash Meinel
Restore a real weave merge to 'bzr merge --weave'.
1203
        plan = self.plan_merge_vf.plan_merge('A', 'B')
1204
        self.assertEqual([('unchanged', 'a\n'),
1205
                          ('new-a', 'c\n'),
1206
                          ('killed-b', 'b\n'),
1207
                          ('new-b', 'B\n'),
1208
                          ('killed-a', 'c\n'),
1209
                          ('unchanged', 'd\n'),
3514.2.1 by Aaron Bentley
Test for correct conflicts on delete + change
1210
                         ], list(plan))
1211
3144.5.3 by Aaron Bentley
Test interesting_files for LCA merge
1212
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1213
class LoggingMerger(object):
1214
    # These seem to be the required attributes
1215
    requires_base = False
1216
    supports_reprocess = False
1217
    supports_show_base = False
1218
    supports_cherrypick = False
1219
    # We intentionally do not define supports_lca_trees
1220
1221
    def __init__(self, *args, **kwargs):
1222
        self.args = args
1223
        self.kwargs = kwargs
1224
1225
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1226
class TestMergerBase(TestCaseWithMemoryTransport):
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1227
    """Common functionality for Merger tests that don't write to disk."""
3514.4.1 by John Arbash Meinel
Update Merger to set a flag when we encounter a criss-cross merge.
1228
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1229
    def get_builder(self):
1230
        builder = self.make_branch_builder('path')
1231
        builder.start_series()
1232
        self.addCleanup(builder.finish_series)
1233
        return builder
1234
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1235
    def setup_simple_graph(self):
1236
        """Create a simple 3-node graph.
1237
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1238
        :return: A BranchBuilder
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1239
        """
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1240
        #
1241
        #  A
1242
        #  |\
1243
        #  B C
1244
        #
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1245
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1246
        builder.build_snapshot(None,
1247
            [('add', ('', None, 'directory', None))],
1248
            revision_id='A-id' )
1249
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1250
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1251
        return builder
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1252
1253
    def setup_criss_cross_graph(self):
1254
        """Create a 5-node graph with a criss-cross.
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1255
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1256
        :return: A BranchBuilder
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1257
        """
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1258
        # A
1259
        # |\
1260
        # B C
1261
        # |X|
1262
        # D E
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1263
        builder = self.setup_simple_graph()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1264
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1265
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1266
        return builder
1267
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
1268
    def make_Merger(self, builder, other_revision_id,
1269
                    interesting_files=None, interesting_ids=None):
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1270
        """Make a Merger object from a branch builder"""
1271
        mem_tree = memorytree.MemoryTree.create_on_branch(builder.get_branch())
1272
        mem_tree.lock_write()
1273
        self.addCleanup(mem_tree.unlock)
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
1274
        merger = _mod_merge.Merger.from_revision_ids(
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1275
            mem_tree, other_revision_id)
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1276
        merger.set_interesting_files(interesting_files)
1277
        # It seems there is no matching function for set_interesting_ids
1278
        merger.interesting_ids = interesting_ids
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1279
        merger.merge_type = _mod_merge.Merge3Merger
1280
        return merger
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1281
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1282
1283
class TestMergerInMemory(TestMergerBase):
1284
4595.13.2 by Alexander Belchenko
[cherrypick revno 4650 from bzr.dev] Fix shelve on windows. (Robert Collins, #305006)
1285
    def test_cache_trees_with_revision_ids_None(self):
1286
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1287
        original_cache = dict(merger._cached_trees)
1288
        merger.cache_trees_with_revision_ids([None])
1289
        self.assertEqual(original_cache, merger._cached_trees)
1290
1291
    def test_cache_trees_with_revision_ids_no_revision_id(self):
1292
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1293
        original_cache = dict(merger._cached_trees)
1294
        tree = self.make_branch_and_memory_tree('tree')
1295
        merger.cache_trees_with_revision_ids([tree])
1296
        self.assertEqual(original_cache, merger._cached_trees)
1297
1298
    def test_cache_trees_with_revision_ids_having_revision_id(self):
1299
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
1300
        original_cache = dict(merger._cached_trees)
1301
        tree = merger.this_branch.repository.revision_tree('B-id')
1302
        original_cache['B-id'] = tree
1303
        merger.cache_trees_with_revision_ids([tree])
1304
        self.assertEqual(original_cache, merger._cached_trees)
1305
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1306
    def test_find_base(self):
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1307
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1308
        self.assertEqual('A-id', merger.base_rev_id)
1309
        self.assertFalse(merger._is_criss_cross)
1310
        self.assertIs(None, merger._lca_trees)
1311
1312
    def test_find_base_criss_cross(self):
3514.4.14 by John Arbash Meinel
Add a test which shows that the ordering switches when you pick the other parent.
1313
        builder = self.setup_criss_cross_graph()
1314
        merger = self.make_Merger(builder, 'E-id')
3514.4.1 by John Arbash Meinel
Update Merger to set a flag when we encounter a criss-cross merge.
1315
        self.assertEqual('A-id', merger.base_rev_id)
1316
        self.assertTrue(merger._is_criss_cross)
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1317
        self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1318
                                            for t in merger._lca_trees])
3514.4.14 by John Arbash Meinel
Add a test which shows that the ordering switches when you pick the other parent.
1319
        # If we swap the order, we should get a different lca order
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1320
        builder.build_snapshot(['E-id'], [], revision_id='F-id')
3514.4.14 by John Arbash Meinel
Add a test which shows that the ordering switches when you pick the other parent.
1321
        merger = self.make_Merger(builder, 'D-id')
1322
        self.assertEqual(['C-id', 'B-id'], [t.get_revision_id()
1323
                                            for t in merger._lca_trees])
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1324
3514.4.23 by John Arbash Meinel
Handle when there are more than 2 LCAs while searching for the unique lca.
1325
    def test_find_base_triple_criss_cross(self):
1326
        #       A-.
1327
        #      / \ \
1328
        #     B   C F # F is merged into both branches
1329
        #     |\ /| |
1330
        #     | X | |\
1331
        #     |/ \| | :
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1332
        #   : D   E |
1333
        #    \|   |/
3514.4.23 by John Arbash Meinel
Handle when there are more than 2 LCAs while searching for the unique lca.
1334
        #     G   H
1335
        builder = self.setup_criss_cross_graph()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1336
        builder.build_snapshot(['A-id'], [], revision_id='F-id')
1337
        builder.build_snapshot(['E-id', 'F-id'], [], revision_id='H-id')
1338
        builder.build_snapshot(['D-id', 'F-id'], [], revision_id='G-id')
3514.4.23 by John Arbash Meinel
Handle when there are more than 2 LCAs while searching for the unique lca.
1339
        merger = self.make_Merger(builder, 'H-id')
1340
        self.assertEqual(['B-id', 'C-id', 'F-id'],
1341
                         [t.get_revision_id() for t in merger._lca_trees])
1342
5540.1.2 by Gary van der Merwe
Add a test for bug #588698, for merging a new root more than once.
1343
    def test_find_base_new_root_criss_cross(self):
1344
        # A   B
1345
        # |\ /|
1346
        # | X |
1347
        # |/ \|
1348
        # C   D
1349
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1350
        builder.build_snapshot(None,
1351
            [('add', ('', None, 'directory', None))],
1352
            revision_id='A-id')
1353
        builder.build_snapshot([],
1354
            [('add', ('', None, 'directory', None))],
1355
            revision_id='B-id')
1356
        builder.build_snapshot(['A-id', 'B-id'], [], revision_id='D-id')
1357
        builder.build_snapshot(['A-id', 'B-id'], [], revision_id='C-id')
5540.1.2 by Gary van der Merwe
Add a test for bug #588698, for merging a new root more than once.
1358
        merger = self.make_Merger(builder, 'D-id')
1359
        self.assertEqual('A-id', merger.base_rev_id)
1360
        self.assertTrue(merger._is_criss_cross)
1361
        self.assertEqual(['A-id', 'B-id'], [t.get_revision_id()
1362
                                            for t in merger._lca_trees])
1363
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1364
    def test_no_criss_cross_passed_to_merge_type(self):
1365
        class LCATreesMerger(LoggingMerger):
1366
            supports_lca_trees = True
1367
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1368
        merger = self.make_Merger(self.setup_simple_graph(), 'C-id')
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1369
        merger.merge_type = LCATreesMerger
1370
        merge_obj = merger.make_merger()
1371
        self.assertIsInstance(merge_obj, LCATreesMerger)
1372
        self.assertFalse('lca_trees' in merge_obj.kwargs)
1373
1374
    def test_criss_cross_passed_to_merge_type(self):
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1375
        merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1376
        merger.merge_type = _mod_merge.Merge3Merger
1377
        merge_obj = merger.make_merger()
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1378
        self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1379
                                            for t in merger._lca_trees])
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1380
1381
    def test_criss_cross_not_supported_merge_type(self):
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1382
        merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1383
        # We explicitly do not define supports_lca_trees
1384
        merger.merge_type = LoggingMerger
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1385
        merge_obj = merger.make_merger()
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1386
        self.assertIsInstance(merge_obj, LoggingMerger)
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1387
        self.assertFalse('lca_trees' in merge_obj.kwargs)
1388
1389
    def test_criss_cross_unsupported_merge_type(self):
1390
        class UnsupportedLCATreesMerger(LoggingMerger):
1391
            supports_lca_trees = False
1392
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1393
        merger = self.make_Merger(self.setup_criss_cross_graph(), 'E-id')
3514.4.4 by John Arbash Meinel
Test that the lca_trees are passed down to the Merger object when appropriate.
1394
        merger.merge_type = UnsupportedLCATreesMerger
1395
        merge_obj = merger.make_merger()
1396
        self.assertIsInstance(merge_obj, UnsupportedLCATreesMerger)
1397
        self.assertFalse('lca_trees' in merge_obj.kwargs)
3514.4.5 by John Arbash Meinel
Initial work on _entries_lca.
1398
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1399
1400
class TestMergerEntriesLCA(TestMergerBase):
1401
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
1402
    def make_merge_obj(self, builder, other_revision_id,
1403
                       interesting_files=None, interesting_ids=None):
1404
        merger = self.make_Merger(builder, other_revision_id,
1405
            interesting_files=interesting_files,
1406
            interesting_ids=interesting_ids)
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1407
        return merger.make_merger()
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1408
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1409
    def test_simple(self):
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1410
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1411
        builder.build_snapshot(None,
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1412
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1413
             ('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1414
            revision_id='A-id')
1415
        builder.build_snapshot(['A-id'],
1416
            [('modify', ('a-id', 'a\nb\nC\nc\n'))],
1417
            revision_id='C-id')
1418
        builder.build_snapshot(['A-id'],
1419
            [('modify', ('a-id', 'a\nB\nb\nc\n'))],
1420
            revision_id='B-id')
1421
        builder.build_snapshot(['C-id', 'B-id'],
1422
            [('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))],
1423
            revision_id='E-id')
1424
        builder.build_snapshot(['B-id', 'C-id'],
1425
            [('modify', ('a-id', 'a\nB\nb\nC\nc\n'))],
1426
            revision_id='D-id', )
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1427
        merge_obj = self.make_merge_obj(builder, 'E-id')
3514.4.5 by John Arbash Meinel
Initial work on _entries_lca.
1428
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1429
        self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1430
                                            for t in merge_obj._lca_trees])
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1431
        self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
3514.4.5 by John Arbash Meinel
Initial work on _entries_lca.
1432
        entries = list(merge_obj._entries_lca())
1433
1434
        # (file_id, changed, parents, names, executable)
1435
        # BASE, lca1, lca2, OTHER, THIS
3514.4.7 by John Arbash Meinel
switch over test_merge to using the new BranchBuilder api.
1436
        root_id = 'a-root-id'
3514.4.12 by John Arbash Meinel
add more filtering for when a directory hasn't actually changed.
1437
        self.assertEqual([('a-id', True,
3514.4.5 by John Arbash Meinel
Initial work on _entries_lca.
1438
                           ((root_id, [root_id, root_id]), root_id, root_id),
1439
                           ((u'a', [u'a', u'a']), u'a', u'a'),
1440
                           ((False, [False, False]), False, False)),
1441
                         ], entries)
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1442
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1443
    def test_not_in_base(self):
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1444
        # LCAs all have the same last-modified revision for the file, as do
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1445
        # the tips, but the base has something different
1446
        #       A    base, doesn't have the file
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1447
        #       |\
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1448
        #       B C  B introduces 'foo', C introduces 'bar'
1449
        #       |X|
1450
        #       D E  D and E now both have 'foo' and 'bar'
1451
        #       |X|
1452
        #       F G  the files are now in F, G, D and E, but not in A
1453
        #            G modifies 'bar'
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1454
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1455
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1456
        builder.build_snapshot(None,
1457
            [('add', (u'', 'a-root-id', 'directory', None))],
1458
            revision_id='A-id')
1459
        builder.build_snapshot(['A-id'],
1460
            [('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))],
1461
            revision_id='B-id')
1462
        builder.build_snapshot(['A-id'],
1463
            [('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))],
1464
            revision_id='C-id')
1465
        builder.build_snapshot(['B-id', 'C-id'],
1466
            [('add', (u'bar', 'bar-id', 'file', 'd\ne\nf\n'))],
1467
            revision_id='D-id')
1468
        builder.build_snapshot(['C-id', 'B-id'],
1469
            [('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))],
1470
            revision_id='E-id')
1471
        builder.build_snapshot(['E-id', 'D-id'],
1472
            [('modify', (u'bar-id', 'd\ne\nf\nG\n'))],
1473
            revision_id='G-id')
1474
        builder.build_snapshot(['D-id', 'E-id'], [], revision_id='F-id')
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1475
        merge_obj = self.make_merge_obj(builder, 'G-id')
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1476
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1477
        self.assertEqual(['D-id', 'E-id'], [t.get_revision_id()
1478
                                            for t in merge_obj._lca_trees])
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1479
        self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
3514.4.10 by John Arbash Meinel
Test the case where BASE is missing a file that is present in THIS, OTHER and all LCAs.
1480
        entries = list(merge_obj._entries_lca())
1481
        root_id = 'a-root-id'
1482
        self.assertEqual([('bar-id', True,
1483
                           ((None, [root_id, root_id]), root_id, root_id),
1484
                           ((None, [u'bar', u'bar']), u'bar', u'bar'),
1485
                           ((None, [False, False]), False, False)),
1486
                         ], entries)
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1487
1488
    def test_not_in_this(self):
1489
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1490
        builder.build_snapshot(None,
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1491
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1492
             ('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1493
            revision_id='A-id')
1494
        builder.build_snapshot(['A-id'],
1495
            [('modify', ('a-id', 'a\nB\nb\nc\n'))],
1496
            revision_id='B-id')
1497
        builder.build_snapshot(['A-id'],
1498
            [('modify', ('a-id', 'a\nb\nC\nc\n'))],
1499
            revision_id='C-id')
1500
        builder.build_snapshot(['C-id', 'B-id'],
1501
            [('modify', ('a-id', 'a\nB\nb\nC\nc\nE\n'))],
1502
            revision_id='E-id')
1503
        builder.build_snapshot(['B-id', 'C-id'],
1504
            [('unversion', 'a-id')],
1505
            revision_id='D-id')
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1506
        merge_obj = self.make_merge_obj(builder, 'E-id')
1507
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1508
        self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1509
                                            for t in merge_obj._lca_trees])
3514.4.11 by John Arbash Meinel
Handle when an entry is missing in THIS
1510
        self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1511
1512
        entries = list(merge_obj._entries_lca())
1513
        root_id = 'a-root-id'
1514
        self.assertEqual([('a-id', True,
1515
                           ((root_id, [root_id, root_id]), root_id, None),
1516
                           ((u'a', [u'a', u'a']), u'a', None),
1517
                           ((False, [False, False]), False, None)),
1518
                         ], entries)
1519
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1520
    def test_file_not_in_one_lca(self):
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1521
        #   A   # just root
1522
        #   |\
1523
        #   B C # B no file, C introduces a file
1524
        #   |X|
1525
        #   D E # D and E both have the file, unchanged from C
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1526
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1527
        builder.build_snapshot(None,
1528
            [('add', (u'', 'a-root-id', 'directory', None))],
1529
            revision_id='A-id')
1530
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1531
        builder.build_snapshot(['A-id'],
1532
            [('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1533
            revision_id='C-id')
1534
        builder.build_snapshot(['C-id', 'B-id'],
1535
                               [], revision_id='E-id') # Inherited from C
1536
        builder.build_snapshot(['B-id', 'C-id'], # Merged from C
1537
            [('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1538
            revision_id='D-id')
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1539
        merge_obj = self.make_merge_obj(builder, 'E-id')
1540
1541
        self.assertEqual(['B-id', 'C-id'], [t.get_revision_id()
1542
                                            for t in merge_obj._lca_trees])
1543
        self.assertEqual('A-id', merge_obj.base_tree.get_revision_id())
1544
1545
        entries = list(merge_obj._entries_lca())
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1546
        self.assertEqual([], entries)
3514.4.13 by John Arbash Meinel
Switch the lca_trees to be in 'find_merge_order'.
1547
3514.4.15 by John Arbash Meinel
Handle when OTHER doesn't have the entry.
1548
    def test_not_in_other(self):
1549
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1550
        builder.build_snapshot(None,
3514.4.15 by John Arbash Meinel
Handle when OTHER doesn't have the entry.
1551
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1552
             ('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1553
            revision_id='A-id')
1554
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1555
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1556
        builder.build_snapshot(
1557
                ['C-id', 'B-id'],
1558
                [('unversion', 'a-id')], revision_id='E-id')
1559
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.15 by John Arbash Meinel
Handle when OTHER doesn't have the entry.
1560
        merge_obj = self.make_merge_obj(builder, 'E-id')
1561
1562
        entries = list(merge_obj._entries_lca())
1563
        root_id = 'a-root-id'
1564
        self.assertEqual([('a-id', True,
1565
                           ((root_id, [root_id, root_id]), None, root_id),
1566
                           ((u'a', [u'a', u'a']), None, u'a'),
1567
                           ((False, [False, False]), None, False)),
1568
                         ], entries)
1569
3514.4.30 by John Arbash Meinel
Several updates.
1570
    def test_not_in_other_or_lca(self):
1571
        #       A    base, introduces 'foo'
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1572
        #       |\
3514.4.30 by John Arbash Meinel
Several updates.
1573
        #       B C  B nothing, C deletes foo
1574
        #       |X|
1575
        #       D E  D restores foo (same as B), E leaves it deleted
3948.1.1 by John Arbash Meinel
Fix an edge case with deleted files and criss-cross merges.
1576
        # Analysis:
1577
        #   A => B, no changes
1578
        #   A => C, delete foo (C should supersede B)
1579
        #   C => D, restore foo
1580
        #   C => E, no changes
1581
        # D would then win 'cleanly' and no record would be given
3514.4.30 by John Arbash Meinel
Several updates.
1582
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1583
        builder.build_snapshot(None,
3514.4.30 by John Arbash Meinel
Several updates.
1584
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1585
             ('add', (u'foo', 'foo-id', 'file', 'content\n'))],
1586
            revision_id='A-id')
1587
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1588
        builder.build_snapshot(['A-id'],
1589
            [('unversion', 'foo-id')], revision_id='C-id')
1590
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1591
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.30 by John Arbash Meinel
Several updates.
1592
        merge_obj = self.make_merge_obj(builder, 'E-id')
1593
1594
        entries = list(merge_obj._entries_lca())
3948.1.1 by John Arbash Meinel
Fix an edge case with deleted files and criss-cross merges.
1595
        self.assertEqual([], entries)
1596
1597
    def test_not_in_other_mod_in_lca1_not_in_lca2(self):
1598
        #       A    base, introduces 'foo'
1599
        #       |\
1600
        #       B C  B changes 'foo', C deletes foo
1601
        #       |X|
1602
        #       D E  D restores foo (same as B), E leaves it deleted (as C)
1603
        # Analysis:
1604
        #   A => B, modified foo
1605
        #   A => C, delete foo, C does not supersede B
1606
        #   B => D, no changes
1607
        #   C => D, resolve in favor of B
1608
        #   B => E, resolve in favor of E
1609
        #   C => E, no changes
1610
        # In this case, we have a conflict of how the changes were resolved. E
1611
        # picked C and D picked B, so we should issue a conflict
1612
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1613
        builder.build_snapshot(None,
3948.1.1 by John Arbash Meinel
Fix an edge case with deleted files and criss-cross merges.
1614
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1615
             ('add', (u'foo', 'foo-id', 'file', 'content\n'))],
1616
            revision_id='A-id')
1617
        builder.build_snapshot(['A-id'], [
1618
            ('modify', ('foo-id', 'new-content\n'))],
1619
            revision_id='B-id')
1620
        builder.build_snapshot(['A-id'],
1621
            [('unversion', 'foo-id')],
1622
            revision_id='C-id')
1623
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1624
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3948.1.1 by John Arbash Meinel
Fix an edge case with deleted files and criss-cross merges.
1625
        merge_obj = self.make_merge_obj(builder, 'E-id')
1626
1627
        entries = list(merge_obj._entries_lca())
3948.1.4 by Vincent Ladeuil
More cleanup and fix overzealous previous one.
1628
        root_id = 'a-root-id'
3514.4.30 by John Arbash Meinel
Several updates.
1629
        self.assertEqual([('foo-id', True,
1630
                           ((root_id, [root_id, None]), None, root_id),
1631
                           ((u'foo', [u'foo', None]), None, 'foo'),
1632
                           ((False, [False, None]), None, False)),
1633
                         ], entries)
1634
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1635
    def test_only_in_one_lca(self):
3948.1.1 by John Arbash Meinel
Fix an edge case with deleted files and criss-cross merges.
1636
        #   A   add only root
1637
        #   |\
1638
        #   B C B nothing, C add file
1639
        #   |X|
1640
        #   D E D still has nothing, E removes file
1641
        # Analysis:
1642
        #   B => D, no change
1643
        #   C => D, removed the file
1644
        #   B => E, no change
1645
        #   C => E, removed the file
1646
        # Thus D & E have identical changes, and this is a no-op
1647
        # Alternatively:
1648
        #   A => B, no change
1649
        #   A => C, add file, thus C supersedes B
1650
        #   w/ C=BASE, D=THIS, E=OTHER we have 'happy convergence'
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1651
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1652
        builder.build_snapshot(None,
1653
            [('add', (u'', 'a-root-id', 'directory', None))],
1654
            revision_id='A-id')
1655
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1656
        builder.build_snapshot(['A-id'],
1657
            [('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1658
            revision_id='C-id')
1659
        builder.build_snapshot(['C-id', 'B-id'],
1660
            [('unversion', 'a-id')],
1661
            revision_id='E-id')
1662
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1663
        merge_obj = self.make_merge_obj(builder, 'E-id')
1664
1665
        entries = list(merge_obj._entries_lca())
3948.1.1 by John Arbash Meinel
Fix an edge case with deleted files and criss-cross merges.
1666
        self.assertEqual([], entries)
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1667
3514.4.16 by John Arbash Meinel
another test for only in OTHER
1668
    def test_only_in_other(self):
1669
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1670
        builder.build_snapshot(None,
1671
            [('add', (u'', 'a-root-id', 'directory', None))],
1672
            revision_id='A-id')
1673
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
1674
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1675
        builder.build_snapshot(['C-id', 'B-id'],
1676
            [('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
1677
            revision_id='E-id')
1678
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.16 by John Arbash Meinel
another test for only in OTHER
1679
        merge_obj = self.make_merge_obj(builder, 'E-id')
1680
1681
        entries = list(merge_obj._entries_lca())
1682
        root_id = 'a-root-id'
1683
        self.assertEqual([('a-id', True,
1684
                           ((None, [None, None]), root_id, None),
1685
                           ((None, [None, None]), u'a', None),
1686
                           ((None, [None, None]), False, None)),
1687
                         ], entries)
3514.4.19 by John Arbash Meinel
Add the _lca_multi_way function, and explicit tests.
1688
3514.4.30 by John Arbash Meinel
Several updates.
1689
    def test_one_lca_supersedes(self):
3514.4.41 by John Arbash Meinel
Some grammar and other clarity feedback from Aaron.
1690
        # One LCA supersedes the other LCAs last modified value, but the
3514.4.30 by John Arbash Meinel
Several updates.
1691
        # value is not the same as BASE.
1692
        #       A    base, introduces 'foo', last mod A
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1693
        #       |\
3514.4.30 by John Arbash Meinel
Several updates.
1694
        #       B C  B modifies 'foo' (mod B), C does nothing (mod A)
1695
        #       |X|
1696
        #       D E  D does nothing (mod B), E updates 'foo' (mod E)
1697
        #       |X|
1698
        #       F G  F updates 'foo' (mod F). G does nothing (mod E)
1699
        #
1700
        #   At this point, G should not be considered to modify 'foo', even
1701
        #   though its LCAs disagree. This is because the modification in E
1702
        #   completely supersedes the value in D.
1703
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1704
        builder.build_snapshot(None,
3514.4.30 by John Arbash Meinel
Several updates.
1705
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1706
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
1707
            revision_id='A-id')
1708
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1709
        builder.build_snapshot(['A-id'],
1710
            [('modify', ('foo-id', 'B content\n'))],
1711
            revision_id='B-id')
1712
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
1713
        builder.build_snapshot(['C-id', 'B-id'],
1714
            [('modify', ('foo-id', 'E content\n'))],
1715
            revision_id='E-id')
1716
        builder.build_snapshot(['E-id', 'D-id'], [], revision_id='G-id')
1717
        builder.build_snapshot(['D-id', 'E-id'],
1718
            [('modify', ('foo-id', 'F content\n'))],
1719
            revision_id='F-id')
3514.4.30 by John Arbash Meinel
Several updates.
1720
        merge_obj = self.make_merge_obj(builder, 'G-id')
1721
1722
        self.assertEqual([], list(merge_obj._entries_lca()))
1723
3514.4.31 by John Arbash Meinel
Add expected failures for cases where we should be looking at more than
1724
    def test_one_lca_supersedes_path(self):
1725
        # Double-criss-cross merge, the ultimate base value is different from
1726
        # the intermediate.
1727
        #   A    value 'foo'
1728
        #   |\
1729
        #   B C  B value 'bar', C = 'foo'
1730
        #   |X|
1731
        #   D E  D = 'bar', E supersedes to 'bing'
1732
        #   |X|
1733
        #   F G  F = 'bing', G supersedes to 'barry'
1734
        #
1735
        # In this case, we technically should not care about the value 'bar' for
1736
        # D, because it was clearly superseded by E's 'bing'. The
1737
        # per-file/attribute graph would actually look like:
1738
        #   A
1739
        #   |
1740
        #   B
1741
        #   |
1742
        #   E
1743
        #   |
1744
        #   G
1745
        #
1746
        # Because the other side of the merge never modifies the value, it just
1747
        # takes the value from the merge.
1748
        #
1749
        # ATM this fails because we will prune 'foo' from the LCAs, but we
1750
        # won't prune 'bar'. This is getting far off into edge-case land, so we
1751
        # aren't supporting it yet.
1752
        #
1753
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1754
        builder.build_snapshot(None,
3514.4.31 by John Arbash Meinel
Add expected failures for cases where we should be looking at more than
1755
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1756
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
1757
            revision_id='A-id')
1758
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1759
        builder.build_snapshot(['A-id'],
1760
            [('rename', ('foo', 'bar'))],
1761
            revision_id='B-id')
1762
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
1763
        builder.build_snapshot(['C-id', 'B-id'],
1764
            [('rename', ('foo', 'bing'))],
1765
            revision_id='E-id') # override to bing
1766
        builder.build_snapshot(['E-id', 'D-id'],
1767
            [('rename', ('bing', 'barry'))],
1768
            revision_id='G-id') # override to barry
1769
        builder.build_snapshot(['D-id', 'E-id'],
1770
            [('rename', ('bar', 'bing'))],
1771
            revision_id='F-id') # Merge in E's change
3514.4.31 by John Arbash Meinel
Add expected failures for cases where we should be looking at more than
1772
        merge_obj = self.make_merge_obj(builder, 'G-id')
1773
1774
        self.expectFailure("We don't do an actual heads() check on lca values,"
1775
            " or use the per-attribute graph",
1776
            self.assertEqual, [], list(merge_obj._entries_lca()))
1777
1778
    def test_one_lca_accidentally_pruned(self):
1779
        # Another incorrect resolution from the same basic flaw:
1780
        #   A    value 'foo'
1781
        #   |\
1782
        #   B C  B value 'bar', C = 'foo'
1783
        #   |X|
1784
        #   D E  D = 'bar', E reverts to 'foo'
1785
        #   |X|
1786
        #   F G  F = 'bing', G switches to 'bar'
1787
        #
1788
        # 'bar' will not be seen as an interesting change, because 'foo' will
1789
        # be pruned from the LCAs, even though it was newly introduced by E
1790
        # (superseding B).
1791
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1792
        builder.build_snapshot(None,
3514.4.31 by John Arbash Meinel
Add expected failures for cases where we should be looking at more than
1793
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1794
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
1795
            revision_id='A-id')
1796
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1797
        builder.build_snapshot(['A-id'],
1798
            [('rename', ('foo', 'bar'))],
1799
            revision_id='B-id')
1800
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
1801
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1802
        builder.build_snapshot(['E-id', 'D-id'],
1803
            [('rename', ('foo', 'bar'))],
1804
            revision_id='G-id')
1805
        builder.build_snapshot(['D-id', 'E-id'],
1806
            [('rename', ('bar', 'bing'))],
1807
            revision_id='F-id') # should end up conflicting
3514.4.31 by John Arbash Meinel
Add expected failures for cases where we should be looking at more than
1808
        merge_obj = self.make_merge_obj(builder, 'G-id')
1809
1810
        entries = list(merge_obj._entries_lca())
1811
        root_id = 'a-root-id'
1812
        self.expectFailure("We prune values from BASE even when relevant.",
1813
            self.assertEqual,
1814
                [('foo-id', False,
1815
                  ((root_id, [root_id, root_id]), root_id, root_id),
1816
                  ((u'foo', [u'bar', u'foo']), u'bar', u'bing'),
1817
                  ((False, [False, False]), False, False)),
1818
                ], entries)
1819
3514.4.30 by John Arbash Meinel
Several updates.
1820
    def test_both_sides_revert(self):
1821
        # Both sides of a criss-cross revert the text to the lca
1822
        #       A    base, introduces 'foo'
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1823
        #       |\
3514.4.30 by John Arbash Meinel
Several updates.
1824
        #       B C  B modifies 'foo', C modifies 'foo'
1825
        #       |X|
1826
        #       D E  D reverts to B, E reverts to C
1827
        # This should conflict
1828
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1829
        builder.build_snapshot(None,
3514.4.30 by John Arbash Meinel
Several updates.
1830
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1831
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
1832
            revision_id='A-id')
1833
        builder.build_snapshot(['A-id'],
1834
            [('modify', ('foo-id', 'B content\n'))],
1835
            revision_id='B-id')
1836
        builder.build_snapshot(['A-id'],
1837
            [('modify', ('foo-id', 'C content\n'))],
1838
            revision_id='C-id')
1839
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1840
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.30 by John Arbash Meinel
Several updates.
1841
        merge_obj = self.make_merge_obj(builder, 'E-id')
1842
1843
        entries = list(merge_obj._entries_lca())
1844
        root_id = 'a-root-id'
1845
        self.assertEqual([('foo-id', True,
1846
                           ((root_id, [root_id, root_id]), root_id, root_id),
1847
                           ((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1848
                           ((False, [False, False]), False, False)),
1849
                         ], entries)
1850
1851
    def test_different_lca_resolve_one_side_updates_content(self):
1852
        # Both sides converge, but then one side updates the text.
1853
        #       A    base, introduces 'foo'
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1854
        #       |\
3514.4.30 by John Arbash Meinel
Several updates.
1855
        #       B C  B modifies 'foo', C modifies 'foo'
1856
        #       |X|
1857
        #       D E  D reverts to B, E reverts to C
1858
        #       |
1859
        #       F    F updates to a new value
1860
        # We need to emit an entry for 'foo', because D & E differed on the
1861
        # merge resolution
1862
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1863
        builder.build_snapshot(None,
3514.4.30 by John Arbash Meinel
Several updates.
1864
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1865
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
1866
            revision_id='A-id')
1867
        builder.build_snapshot(['A-id'],
1868
            [('modify', ('foo-id', 'B content\n'))],
1869
            revision_id='B-id')
1870
        builder.build_snapshot(['A-id'],
1871
            [('modify', ('foo-id', 'C content\n'))],
1872
            revision_id='C-id', )
1873
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1874
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
1875
        builder.build_snapshot(['D-id'],
1876
            [('modify', ('foo-id', 'F content\n'))],
1877
            revision_id='F-id')
3514.4.30 by John Arbash Meinel
Several updates.
1878
        merge_obj = self.make_merge_obj(builder, 'E-id')
1879
1880
        entries = list(merge_obj._entries_lca())
1881
        root_id = 'a-root-id'
1882
        self.assertEqual([('foo-id', True,
1883
                           ((root_id, [root_id, root_id]), root_id, root_id),
1884
                           ((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
1885
                           ((False, [False, False]), False, False)),
1886
                         ], entries)
1887
1888
    def test_same_lca_resolution_one_side_updates_content(self):
1889
        # Both sides converge, but then one side updates the text.
1890
        #       A    base, introduces 'foo'
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
1891
        #       |\
3514.4.30 by John Arbash Meinel
Several updates.
1892
        #       B C  B modifies 'foo', C modifies 'foo'
1893
        #       |X|
1894
        #       D E  D and E use C's value
1895
        #       |
1896
        #       F    F updates to a new value
1897
        # I think it is a bug that this conflicts, but we don't have a way to
1898
        # detect otherwise. And because of:
1899
        #   test_different_lca_resolve_one_side_updates_content
1900
        # We need to conflict.
1901
1902
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1903
        builder.build_snapshot(None,
3514.4.30 by John Arbash Meinel
Several updates.
1904
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1905
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
1906
            revision_id='A-id')
1907
        builder.build_snapshot(['A-id'],
1908
            [('modify', ('foo-id', 'B content\n'))],
1909
            revision_id='B-id')
1910
        builder.build_snapshot(['A-id'],
1911
            [('modify', ('foo-id', 'C content\n'))],
1912
            revision_id='C-id')
1913
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1914
        builder.build_snapshot(['B-id', 'C-id'],
1915
            [('modify', ('foo-id', 'C content\n'))],
1916
            revision_id='D-id') # Same as E
1917
        builder.build_snapshot(['D-id'],
1918
            [('modify', ('foo-id', 'F content\n'))],
1919
            revision_id='F-id')
3514.4.30 by John Arbash Meinel
Several updates.
1920
        merge_obj = self.make_merge_obj(builder, 'E-id')
1921
1922
        entries = list(merge_obj._entries_lca())
1923
        self.expectFailure("We don't detect that LCA resolution was the"
1924
                           " same on both sides",
1925
            self.assertEqual, [], entries)
1926
3514.4.20 by John Arbash Meinel
Use the _lca_multi_way to work out if there is actually a kind/parent/name/content change.
1927
    def test_only_path_changed(self):
3514.4.19 by John Arbash Meinel
Add the _lca_multi_way function, and explicit tests.
1928
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1929
        builder.build_snapshot(None,
3514.4.19 by John Arbash Meinel
Add the _lca_multi_way function, and explicit tests.
1930
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1931
             ('add', (u'a', 'a-id', 'file', 'content\n'))],
1932
            revision_id='A-id')
1933
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1934
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1935
        builder.build_snapshot(['C-id', 'B-id'],
1936
            [('rename', (u'a', u'b'))],
1937
            revision_id='E-id')
1938
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.19 by John Arbash Meinel
Add the _lca_multi_way function, and explicit tests.
1939
        merge_obj = self.make_merge_obj(builder, 'E-id')
1940
        entries = list(merge_obj._entries_lca())
1941
        root_id = 'a-root-id'
1942
        # The content was not changed, only the path
1943
        self.assertEqual([('a-id', False,
1944
                           ((root_id, [root_id, root_id]), root_id, root_id),
1945
                           ((u'a', [u'a', u'a']), u'b', u'a'),
1946
                           ((False, [False, False]), False, False)),
1947
                         ], entries)
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
1948
1949
    def test_kind_changed(self):
1950
        # Identical content, except 'D' changes a-id into a directory
1951
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1952
        builder.build_snapshot(None,
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
1953
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1954
             ('add', (u'a', 'a-id', 'file', 'content\n'))],
1955
            revision_id='A-id')
1956
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1957
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1958
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
1959
            [('unversion', 'a-id'),
6008.2.5 by Andrew Bennetts
Rename 'checkpoint' to 'flush', add some unit tests and more comments.
1960
             ('flush', None),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1961
             ('add', (u'a', 'a-id', 'directory', None))],
1962
            revision_id='E-id')
1963
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
1964
        merge_obj = self.make_merge_obj(builder, 'E-id')
1965
        entries = list(merge_obj._entries_lca())
1966
        root_id = 'a-root-id'
1967
        # Only the kind was changed (content)
1968
        self.assertEqual([('a-id', True,
1969
                           ((root_id, [root_id, root_id]), root_id, root_id),
1970
                           ((u'a', [u'a', u'a']), u'a', u'a'),
1971
                           ((False, [False, False]), False, False)),
1972
                         ], entries)
1973
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
1974
    def test_this_changed_kind(self):
1975
        # Identical content, but THIS changes a file to a directory
1976
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1977
        builder.build_snapshot(None,
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
1978
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1979
             ('add', (u'a', 'a-id', 'file', 'content\n'))],
1980
            revision_id='A-id')
1981
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
1982
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
1983
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
1984
        builder.build_snapshot(['B-id', 'C-id'],
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
1985
            [('unversion', 'a-id'),
6008.2.5 by Andrew Bennetts
Rename 'checkpoint' to 'flush', add some unit tests and more comments.
1986
             ('flush', None),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1987
             ('add', (u'a', 'a-id', 'directory', None))],
1988
            revision_id='D-id')
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
1989
        merge_obj = self.make_merge_obj(builder, 'E-id')
1990
        entries = list(merge_obj._entries_lca())
1991
        # Only the kind was changed (content)
1992
        self.assertEqual([], entries)
1993
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
1994
    def test_interesting_files(self):
1995
        # Two files modified, but we should filter one of them
1996
        builder = self.get_builder()
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
1997
        builder.build_snapshot(None,
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
1998
            [('add', (u'', 'a-root-id', 'directory', None)),
1999
             ('add', (u'a', 'a-id', 'file', 'content\n')),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
2000
             ('add', (u'b', 'b-id', 'file', 'content\n'))],
2001
            revision_id='A-id')
2002
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
2003
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2004
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2005
            [('modify', ('a-id', 'new-content\n')),
6816.2.2 by Jelmer Vernooij
Migrate some build_snapshot code over to having revision_id as keyword argument.
2006
             ('modify', ('b-id', 'new-content\n'))],
2007
            revision_id='E-id')
2008
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2009
        merge_obj = self.make_merge_obj(builder, 'E-id',
2010
                                        interesting_files=['b'])
2011
        entries = list(merge_obj._entries_lca())
2012
        root_id = 'a-root-id'
2013
        self.assertEqual([('b-id', True,
2014
                           ((root_id, [root_id, root_id]), root_id, root_id),
2015
                           ((u'b', [u'b', u'b']), u'b', u'b'),
2016
                           ((False, [False, False]), False, False)),
2017
                         ], entries)
2018
2019
    def test_interesting_file_in_this(self):
2020
        # This renamed the file, but it should still match the entry in other
2021
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2022
        builder.build_snapshot(None,
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2023
            [('add', (u'', 'a-root-id', 'directory', None)),
2024
             ('add', (u'a', 'a-id', 'file', 'content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2025
             ('add', (u'b', 'b-id', 'file', 'content\n'))],
2026
            revision_id='A-id')
2027
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
2028
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2029
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2030
            [('modify', ('a-id', 'new-content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2031
             ('modify', ('b-id', 'new-content\n'))],
2032
            revision_id='E-id')
2033
        builder.build_snapshot(['B-id', 'C-id'],
2034
            [('rename', ('b', 'c'))],
2035
            revision_id='D-id')
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2036
        merge_obj = self.make_merge_obj(builder, 'E-id',
2037
                                        interesting_files=['c'])
2038
        entries = list(merge_obj._entries_lca())
2039
        root_id = 'a-root-id'
2040
        self.assertEqual([('b-id', True,
2041
                           ((root_id, [root_id, root_id]), root_id, root_id),
2042
                           ((u'b', [u'b', u'b']), u'b', u'c'),
2043
                           ((False, [False, False]), False, False)),
2044
                         ], entries)
2045
2046
    def test_interesting_file_in_base(self):
2047
        # This renamed the file, but it should still match the entry in BASE
2048
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2049
        builder.build_snapshot(None,
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2050
            [('add', (u'', 'a-root-id', 'directory', None)),
2051
             ('add', (u'a', 'a-id', 'file', 'content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2052
             ('add', (u'c', 'c-id', 'file', 'content\n'))],
2053
            revision_id='A-id')
2054
        builder.build_snapshot(['A-id'],
2055
            [('rename', ('c', 'b'))],
2056
            revision_id='B-id')
2057
        builder.build_snapshot(['A-id'],
2058
            [('rename', ('c', 'b'))],
2059
            revision_id='C-id')
2060
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2061
            [('modify', ('a-id', 'new-content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2062
             ('modify', ('c-id', 'new-content\n'))],
2063
            revision_id='E-id')
2064
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2065
        merge_obj = self.make_merge_obj(builder, 'E-id',
2066
                                        interesting_files=['c'])
2067
        entries = list(merge_obj._entries_lca())
2068
        root_id = 'a-root-id'
2069
        self.assertEqual([('c-id', True,
2070
                           ((root_id, [root_id, root_id]), root_id, root_id),
2071
                           ((u'c', [u'b', u'b']), u'b', u'b'),
2072
                           ((False, [False, False]), False, False)),
2073
                         ], entries)
2074
2075
    def test_interesting_file_in_lca(self):
2076
        # This renamed the file, but it should still match the entry in LCA
2077
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2078
        builder.build_snapshot(None,
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2079
            [('add', (u'', 'a-root-id', 'directory', None)),
2080
             ('add', (u'a', 'a-id', 'file', 'content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2081
             ('add', (u'b', 'b-id', 'file', 'content\n'))],
2082
            revision_id='A-id')
2083
        builder.build_snapshot(['A-id'],
2084
            [('rename', ('b', 'c'))], revision_id='B-id')
2085
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2086
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2087
            [('modify', ('a-id', 'new-content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2088
             ('modify', ('b-id', 'new-content\n'))],
2089
            revision_id='E-id')
2090
        builder.build_snapshot(['B-id', 'C-id'],
2091
            [('rename', ('c', 'b'))], revision_id='D-id')
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2092
        merge_obj = self.make_merge_obj(builder, 'E-id',
2093
                                        interesting_files=['c'])
2094
        entries = list(merge_obj._entries_lca())
2095
        root_id = 'a-root-id'
2096
        self.assertEqual([('b-id', True,
2097
                           ((root_id, [root_id, root_id]), root_id, root_id),
2098
                           ((u'b', [u'c', u'b']), u'b', u'b'),
2099
                           ((False, [False, False]), False, False)),
2100
                         ], entries)
2101
2102
    def test_interesting_ids(self):
2103
        # Two files modified, but we should filter one of them
2104
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2105
        builder.build_snapshot(None,
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2106
            [('add', (u'', 'a-root-id', 'directory', None)),
2107
             ('add', (u'a', 'a-id', 'file', 'content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2108
             ('add', (u'b', 'b-id', 'file', 'content\n'))],
2109
            revision_id='A-id')
2110
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
2111
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2112
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2113
            [('modify', ('a-id', 'new-content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2114
             ('modify', ('b-id', 'new-content\n'))], revision_id='E-id')
2115
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.24 by John Arbash Meinel
Implement support for 'interesting_files' and 'interesting_ids' for _entries_lca
2116
        merge_obj = self.make_merge_obj(builder, 'E-id',
2117
                                        interesting_ids=['b-id'])
2118
        entries = list(merge_obj._entries_lca())
2119
        root_id = 'a-root-id'
2120
        self.assertEqual([('b-id', True,
2121
                           ((root_id, [root_id, root_id]), root_id, root_id),
2122
                           ((u'b', [u'b', u'b']), u'b', u'b'),
2123
                           ((False, [False, False]), False, False)),
2124
                         ], entries)
2125
2126
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2127
2128
class TestMergerEntriesLCAOnDisk(tests.TestCaseWithTransport):
2129
2130
    def get_builder(self):
2131
        builder = self.make_branch_builder('path')
2132
        builder.start_series()
2133
        self.addCleanup(builder.finish_series)
2134
        return builder
2135
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2136
    def get_wt_from_builder(self, builder):
2137
        """Get a real WorkingTree from the builder."""
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2138
        the_branch = builder.get_branch()
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2139
        wt = the_branch.controldir.create_workingtree()
3514.4.31 by John Arbash Meinel
Add expected failures for cases where we should be looking at more than
2140
        # Note: This is a little bit ugly, but we are holding the branch
2141
        #       write-locked as part of the build process, and we would like to
2142
        #       maintain that. So we just force the WT to re-use the same
2143
        #       branch object.
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2144
        wt._branch = the_branch
2145
        wt.lock_write()
2146
        self.addCleanup(wt.unlock)
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2147
        return wt
2148
2149
    def do_merge(self, builder, other_revision_id):
2150
        wt = self.get_wt_from_builder(builder)
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2151
        merger = _mod_merge.Merger.from_revision_ids(
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2152
            wt, other_revision_id)
2153
        merger.merge_type = _mod_merge.Merge3Merger
2154
        return wt, merger.do_merge()
2155
2156
    def test_simple_lca(self):
2157
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2158
        builder.build_snapshot(None,
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2159
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2160
             ('add', (u'a', 'a-id', 'file', 'a\nb\nc\n'))],
2161
            revision_id='A-id')
2162
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2163
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
2164
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
2165
        builder.build_snapshot(['B-id', 'C-id'],
2166
            [('modify', ('a-id', 'a\nb\nc\nd\ne\nf\n'))],
2167
            revision_id='D-id')
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2168
        wt, conflicts = self.do_merge(builder, 'E-id')
2169
        self.assertEqual(0, conflicts)
2170
        # The merge should have simply update the contents of 'a'
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
2171
        self.assertEqual('a\nb\nc\nd\ne\nf\n', wt.get_file_text('a'))
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2172
2173
    def test_conflict_without_lca(self):
2174
        # This test would cause a merge conflict, unless we use the lca trees
2175
        # to determine the real ancestry
2176
        #   A       Path at 'foo'
2177
        #  / \
2178
        # B   C     Path renamed to 'bar' in B
2179
        # |\ /|
2180
        # | X |
2181
        # |/ \|
2182
        # D   E     Path at 'bar' in D and E
2183
        #     |
2184
        #     F     Path at 'baz' in F, which supersedes 'bar' and 'foo'
2185
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2186
        builder.build_snapshot(None,
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2187
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2188
             ('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))],
2189
            revision_id='A-id')
2190
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2191
        builder.build_snapshot(['A-id'],
2192
            [('rename', ('foo', 'bar'))], revision_id='B-id', )
2193
        builder.build_snapshot(['C-id', 'B-id'], # merge the rename
2194
            [('rename', ('foo', 'bar'))], revision_id='E-id')
2195
        builder.build_snapshot(['E-id'],
2196
            [('rename', ('bar', 'baz'))], revision_id='F-id')
2197
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2198
        wt, conflicts = self.do_merge(builder, 'F-id')
2199
        self.assertEqual(0, conflicts)
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2200
        # The merge should simply recognize that the final rename takes
2201
        # precedence
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2202
        self.assertEqual('baz', wt.id2path('foo-id'))
2203
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2204
    def test_other_deletes_lca_renames(self):
2205
        # This test would cause a merge conflict, unless we use the lca trees
2206
        # to determine the real ancestry
2207
        #   A       Path at 'foo'
2208
        #  / \
2209
        # B   C     Path renamed to 'bar' in B
2210
        # |\ /|
2211
        # | X |
2212
        # |/ \|
2213
        # D   E     Path at 'bar' in D and E
2214
        #     |
2215
        #     F     F deletes 'bar'
2216
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2217
        builder.build_snapshot(None,
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2218
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2219
             ('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))],
2220
            revision_id='A-id')
2221
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2222
        builder.build_snapshot(['A-id'],
2223
            [('rename', ('foo', 'bar'))], revision_id='B-id')
2224
        builder.build_snapshot(['C-id', 'B-id'], # merge the rename
2225
            [('rename', ('foo', 'bar'))], revision_id='E-id')
2226
        builder.build_snapshot(['E-id'],
2227
            [('unversion', 'foo-id')], revision_id='F-id')
2228
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2229
        wt, conflicts = self.do_merge(builder, 'F-id')
2230
        self.assertEqual(0, conflicts)
2231
        self.assertRaises(errors.NoSuchId, wt.id2path, 'foo-id')
2232
2233
    def test_executable_changes(self):
2234
        #   A       Path at 'foo'
2235
        #  / \
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2236
        # B   C
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2237
        # |\ /|
2238
        # | X |
2239
        # |/ \|
2240
        # D   E
2241
        #     |
2242
        #     F     Executable bit changed
2243
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2244
        builder.build_snapshot(None,
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2245
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2246
             ('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))],
2247
            revision_id='A-id')
2248
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2249
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
2250
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
2251
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2252
        # Have to use a real WT, because BranchBuilder doesn't support exec bit
2253
        wt = self.get_wt_from_builder(builder)
2254
        tt = transform.TreeTransform(wt)
2255
        try:
2256
            tt.set_executability(True, tt.trans_id_tree_file_id('foo-id'))
2257
            tt.apply()
2258
        except:
2259
            tt.finalize()
2260
            raise
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
2261
        self.assertTrue(wt.is_executable('foo'))
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2262
        wt.commit('F-id', rev_id='F-id')
2263
        # Reset to D, so that we can merge F
2264
        wt.set_parent_ids(['D-id'])
2265
        wt.branch.set_last_revision_info(3, 'D-id')
2266
        wt.revert()
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
2267
        self.assertFalse(wt.is_executable('foo'))
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2268
        conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2269
        self.assertEqual(0, conflicts)
6809.4.4 by Jelmer Vernooij
Swap arguments for Tree.is_executable.
2270
        self.assertTrue(wt.is_executable('foo'))
3514.4.22 by John Arbash Meinel
Handle executable bit changes as well.
2271
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2272
    def test_create_symlink(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2273
        self.requireFeature(features.SymlinkFeature)
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2274
        #   A
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2275
        #  / \
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2276
        # B   C
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2277
        # |\ /|
2278
        # | X |
2279
        # |/ \|
2280
        # D   E
2281
        #     |
2282
        #     F     Add a symlink 'foo' => 'bar'
2283
        # Have to use a real WT, because BranchBuilder and MemoryTree don't
2284
        # have symlink support
2285
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2286
        builder.build_snapshot(None,
2287
            [('add', (u'', 'a-root-id', 'directory', None))],
2288
            revision_id='A-id')
2289
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2290
        builder.build_snapshot(['A-id'], [], revision_id='B-id')
2291
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
2292
        builder.build_snapshot(['C-id', 'B-id'], [], revision_id='E-id')
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2293
        # Have to use a real WT, because BranchBuilder doesn't support exec bit
2294
        wt = self.get_wt_from_builder(builder)
2295
        os.symlink('bar', 'path/foo')
2296
        wt.add(['foo'], ['foo-id'])
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2297
        self.assertEqual('bar', wt.get_symlink_target('foo'))
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2298
        wt.commit('add symlink', rev_id='F-id')
2299
        # Reset to D, so that we can merge F
2300
        wt.set_parent_ids(['D-id'])
2301
        wt.branch.set_last_revision_info(3, 'D-id')
2302
        wt.revert()
2303
        self.assertIs(None, wt.path2id('foo'))
2304
        conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2305
        self.assertEqual(0, conflicts)
2306
        self.assertEqual('foo-id', wt.path2id('foo'))
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2307
        self.assertEqual('bar', wt.get_symlink_target('foo'))
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2308
3514.4.30 by John Arbash Meinel
Several updates.
2309
    def test_both_sides_revert(self):
2310
        # Both sides of a criss-cross revert the text to the lca
2311
        #       A    base, introduces 'foo'
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2312
        #       |\
3514.4.30 by John Arbash Meinel
Several updates.
2313
        #       B C  B modifies 'foo', C modifies 'foo'
2314
        #       |X|
2315
        #       D E  D reverts to B, E reverts to C
2316
        # This should conflict
2317
        # This must be done with a real WorkingTree, because normally their
2318
        # inventory contains "None" rather than a real sha1
2319
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2320
        builder.build_snapshot(None,
3514.4.30 by John Arbash Meinel
Several updates.
2321
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2322
             ('add', (u'foo', 'foo-id', 'file', 'A content\n'))],
2323
            revision_id='A-id')
2324
        builder.build_snapshot(['A-id'],
2325
            [('modify', ('foo-id', 'B content\n'))],
2326
            revision_id='B-id')
2327
        builder.build_snapshot(['A-id'],
2328
            [('modify', ('foo-id', 'C content\n'))],
2329
            revision_id='C-id')
2330
        builder.build_snapshot(['C-id', 'B-id'], [],
2331
                revision_id='E-id')
2332
        builder.build_snapshot(['B-id', 'C-id'], [],
2333
                revision_id='D-id')
3514.4.30 by John Arbash Meinel
Several updates.
2334
        wt, conflicts = self.do_merge(builder, 'E-id')
2335
        self.assertEqual(1, conflicts)
2336
        self.assertEqualDiff('<<<<<<< TREE\n'
2337
                             'B content\n'
2338
                             '=======\n'
2339
                             'C content\n'
2340
                             '>>>>>>> MERGE-SOURCE\n',
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
2341
                             wt.get_file_text('foo'))
3514.4.30 by John Arbash Meinel
Several updates.
2342
3514.4.28 by John Arbash Meinel
More symlink tests.
2343
    def test_modified_symlink(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2344
        self.requireFeature(features.SymlinkFeature)
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2345
        #   A       Create symlink foo => bar
2346
        #  / \
2347
        # B   C     B relinks foo => baz
2348
        # |\ /|
2349
        # | X |
2350
        # |/ \|
2351
        # D   E     D & E have foo => baz
2352
        #     |
2353
        #     F     F changes it to bing
2354
        #
2355
        # Merging D & F should result in F cleanly overriding D, because D's
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2356
        # value actually comes from B
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2357
2358
        # Have to use a real WT, because BranchBuilder and MemoryTree don't
2359
        # have symlink support
2360
        wt = self.make_branch_and_tree('path')
2361
        wt.lock_write()
2362
        self.addCleanup(wt.unlock)
2363
        os.symlink('bar', 'path/foo')
2364
        wt.add(['foo'], ['foo-id'])
2365
        wt.commit('add symlink', rev_id='A-id')
2366
        os.remove('path/foo')
2367
        os.symlink('baz', 'path/foo')
2368
        wt.commit('foo => baz', rev_id='B-id')
2369
        wt.set_last_revision('A-id')
2370
        wt.branch.set_last_revision_info(1, 'A-id')
2371
        wt.revert()
2372
        wt.commit('C', rev_id='C-id')
2373
        wt.merge_from_branch(wt.branch, 'B-id')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2374
        self.assertEqual('baz', wt.get_symlink_target('foo'))
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2375
        wt.commit('E merges C & B', rev_id='E-id')
2376
        os.remove('path/foo')
2377
        os.symlink('bing', 'path/foo')
2378
        wt.commit('F foo => bing', rev_id='F-id')
2379
        wt.set_last_revision('B-id')
2380
        wt.branch.set_last_revision_info(2, 'B-id')
2381
        wt.revert()
2382
        wt.merge_from_branch(wt.branch, 'C-id')
2383
        wt.commit('D merges B & C', rev_id='D-id')
2384
        conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
3948.1.7 by Vincent Ladeuil
Slight refactoring and test fixing.
2385
        self.assertEqual(0, conflicts)
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2386
        self.assertEqual('bing', wt.get_symlink_target('foo'))
3514.4.27 by John Arbash Meinel
A couple of symlink tests, we need to do more.
2387
3514.4.28 by John Arbash Meinel
More symlink tests.
2388
    def test_renamed_symlink(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2389
        self.requireFeature(features.SymlinkFeature)
3514.4.28 by John Arbash Meinel
More symlink tests.
2390
        #   A       Create symlink foo => bar
2391
        #  / \
2392
        # B   C     B renames foo => barry
2393
        # |\ /|
2394
        # | X |
2395
        # |/ \|
2396
        # D   E     D & E have barry
2397
        #     |
2398
        #     F     F renames barry to blah
2399
        #
2400
        # Merging D & F should result in F cleanly overriding D, because D's
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2401
        # value actually comes from B
3514.4.28 by John Arbash Meinel
More symlink tests.
2402
2403
        wt = self.make_branch_and_tree('path')
2404
        wt.lock_write()
2405
        self.addCleanup(wt.unlock)
2406
        os.symlink('bar', 'path/foo')
2407
        wt.add(['foo'], ['foo-id'])
2408
        wt.commit('A add symlink', rev_id='A-id')
2409
        wt.rename_one('foo', 'barry')
2410
        wt.commit('B foo => barry', rev_id='B-id')
2411
        wt.set_last_revision('A-id')
2412
        wt.branch.set_last_revision_info(1, 'A-id')
2413
        wt.revert()
2414
        wt.commit('C', rev_id='C-id')
2415
        wt.merge_from_branch(wt.branch, 'B-id')
2416
        self.assertEqual('barry', wt.id2path('foo-id'))
6809.4.9 by Jelmer Vernooij
Fix some more tests.
2417
        self.assertEqual('bar', wt.get_symlink_target('barry'))
3514.4.28 by John Arbash Meinel
More symlink tests.
2418
        wt.commit('E merges C & B', rev_id='E-id')
2419
        wt.rename_one('barry', 'blah')
2420
        wt.commit('F barry => blah', rev_id='F-id')
2421
        wt.set_last_revision('B-id')
2422
        wt.branch.set_last_revision_info(2, 'B-id')
2423
        wt.revert()
2424
        wt.merge_from_branch(wt.branch, 'C-id')
2425
        wt.commit('D merges B & C', rev_id='D-id')
2426
        self.assertEqual('barry', wt.id2path('foo-id'))
2427
        # Check the output of the Merger object directly
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2428
        merger = _mod_merge.Merger.from_revision_ids(wt, 'F-id')
3514.4.28 by John Arbash Meinel
More symlink tests.
2429
        merger.merge_type = _mod_merge.Merge3Merger
2430
        merge_obj = merger.make_merger()
2431
        root_id = wt.path2id('')
2432
        entries = list(merge_obj._entries_lca())
2433
        # No content change, just a path change
2434
        self.assertEqual([('foo-id', False,
2435
                           ((root_id, [root_id, root_id]), root_id, root_id),
2436
                           ((u'foo', [u'barry', u'foo']), u'blah', u'barry'),
2437
                           ((False, [False, False]), False, False)),
2438
                         ], entries)
2439
        conflicts = wt.merge_from_branch(wt.branch, to_revision='F-id')
2440
        self.assertEqual(0, conflicts)
2441
        self.assertEqual('blah', wt.id2path('foo-id'))
2442
2443
    def test_symlink_no_content_change(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2444
        self.requireFeature(features.SymlinkFeature)
3514.4.28 by John Arbash Meinel
More symlink tests.
2445
        #   A       Create symlink foo => bar
2446
        #  / \
2447
        # B   C     B relinks foo => baz
2448
        # |\ /|
2449
        # | X |
2450
        # |/ \|
2451
        # D   E     D & E have foo => baz
2452
        # |
2453
        # F         F has foo => bing
2454
        #
2455
        # Merging E into F should not cause a conflict, because E doesn't have
2456
        # a content change relative to the LCAs (it does relative to A)
2457
        wt = self.make_branch_and_tree('path')
2458
        wt.lock_write()
2459
        self.addCleanup(wt.unlock)
2460
        os.symlink('bar', 'path/foo')
2461
        wt.add(['foo'], ['foo-id'])
2462
        wt.commit('add symlink', rev_id='A-id')
2463
        os.remove('path/foo')
2464
        os.symlink('baz', 'path/foo')
2465
        wt.commit('foo => baz', rev_id='B-id')
2466
        wt.set_last_revision('A-id')
2467
        wt.branch.set_last_revision_info(1, 'A-id')
2468
        wt.revert()
2469
        wt.commit('C', rev_id='C-id')
2470
        wt.merge_from_branch(wt.branch, 'B-id')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2471
        self.assertEqual('baz', wt.get_symlink_target('foo'))
3514.4.28 by John Arbash Meinel
More symlink tests.
2472
        wt.commit('E merges C & B', rev_id='E-id')
2473
        wt.set_last_revision('B-id')
2474
        wt.branch.set_last_revision_info(2, 'B-id')
2475
        wt.revert()
2476
        wt.merge_from_branch(wt.branch, 'C-id')
2477
        wt.commit('D merges B & C', rev_id='D-id')
2478
        os.remove('path/foo')
2479
        os.symlink('bing', 'path/foo')
2480
        wt.commit('F foo => bing', rev_id='F-id')
2481
2482
        # Check the output of the Merger object directly
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2483
        merger = _mod_merge.Merger.from_revision_ids(wt, 'E-id')
3514.4.28 by John Arbash Meinel
More symlink tests.
2484
        merger.merge_type = _mod_merge.Merge3Merger
2485
        merge_obj = merger.make_merger()
2486
        # Nothing interesting happened in OTHER relative to BASE
2487
        self.assertEqual([], list(merge_obj._entries_lca()))
2488
        # Now do a real merge, just to test the rest of the stack
2489
        conflicts = wt.merge_from_branch(wt.branch, to_revision='E-id')
2490
        self.assertEqual(0, conflicts)
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2491
        self.assertEqual('bing', wt.get_symlink_target('foo'))
3514.4.28 by John Arbash Meinel
More symlink tests.
2492
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
2493
    def test_symlink_this_changed_kind(self):
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2494
        self.requireFeature(features.SymlinkFeature)
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
2495
        #   A       Nothing
2496
        #  / \
2497
        # B   C     B creates symlink foo => bar
2498
        # |\ /|
2499
        # | X |
2500
        # |/ \|
2501
        # D   E     D changes foo into a file, E has foo => bing
2502
        #
2503
        # Mostly, this is trying to test that we don't try to os.readlink() on
2504
        # a file, or when there is nothing there
2505
        wt = self.make_branch_and_tree('path')
2506
        wt.lock_write()
2507
        self.addCleanup(wt.unlock)
2508
        wt.commit('base', rev_id='A-id')
2509
        os.symlink('bar', 'path/foo')
2510
        wt.add(['foo'], ['foo-id'])
2511
        wt.commit('add symlink foo => bar', rev_id='B-id')
2512
        wt.set_last_revision('A-id')
2513
        wt.branch.set_last_revision_info(1, 'A-id')
2514
        wt.revert()
2515
        wt.commit('C', rev_id='C-id')
2516
        wt.merge_from_branch(wt.branch, 'B-id')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2517
        self.assertEqual('bar', wt.get_symlink_target('foo'))
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
2518
        os.remove('path/foo')
2519
        # We have to change the link in E, or it won't try to do a comparison
2520
        os.symlink('bing', 'path/foo')
2521
        wt.commit('E merges C & B, overrides to bing', rev_id='E-id')
2522
        wt.set_last_revision('B-id')
2523
        wt.branch.set_last_revision_info(2, 'B-id')
2524
        wt.revert()
2525
        wt.merge_from_branch(wt.branch, 'C-id')
2526
        os.remove('path/foo')
2527
        self.build_tree_contents([('path/foo', 'file content\n')])
2528
        # XXX: workaround, WT doesn't detect kind changes unless you do
2529
        # iter_changes()
2530
        list(wt.iter_changes(wt.basis_tree()))
2531
        wt.commit('D merges B & C, makes it a file', rev_id='D-id')
2532
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2533
        merger = _mod_merge.Merger.from_revision_ids(wt, 'E-id')
3514.4.35 by John Arbash Meinel
Add a test that we only call get_symlink_target if the object should be a symlink.
2534
        merger.merge_type = _mod_merge.Merge3Merger
2535
        merge_obj = merger.make_merger()
2536
        entries = list(merge_obj._entries_lca())
2537
        root_id = wt.path2id('')
2538
        self.assertEqual([('foo-id', True,
2539
                           ((None, [root_id, None]), root_id, root_id),
2540
                           ((None, [u'foo', None]), u'foo', u'foo'),
2541
                           ((None, [False, None]), False, False)),
2542
                         ], entries)
2543
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2544
    def test_symlink_all_wt(self):
2545
        """Check behavior if all trees are Working Trees."""
5967.12.1 by Martin Pool
Move all test features into bzrlib.tests.features
2546
        self.requireFeature(features.SymlinkFeature)
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2547
        # The big issue is that entry.symlink_target is None for WorkingTrees.
2548
        # So we need to make sure we handle that case correctly.
2549
        #   A   foo => bar
2550
        #   |\
2551
        #   B C B relinks foo => baz
2552
        #   |X|
2553
        #   D E D & E have foo => baz
2554
        #     |
2555
        #     F F changes it to bing
2556
        # Merging D & F should result in F cleanly overriding D, because D's
2557
        # value actually comes from B
2558
2559
        wt = self.make_branch_and_tree('path')
2560
        wt.lock_write()
2561
        self.addCleanup(wt.unlock)
2562
        os.symlink('bar', 'path/foo')
2563
        wt.add(['foo'], ['foo-id'])
2564
        wt.commit('add symlink', rev_id='A-id')
2565
        os.remove('path/foo')
2566
        os.symlink('baz', 'path/foo')
2567
        wt.commit('foo => baz', rev_id='B-id')
2568
        wt.set_last_revision('A-id')
2569
        wt.branch.set_last_revision_info(1, 'A-id')
2570
        wt.revert()
2571
        wt.commit('C', rev_id='C-id')
2572
        wt.merge_from_branch(wt.branch, 'B-id')
6809.4.7 by Jelmer Vernooij
Swap arguments for get_symlink_target and kind/stored_kind.
2573
        self.assertEqual('baz', wt.get_symlink_target('foo'))
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2574
        wt.commit('E merges C & B', rev_id='E-id')
2575
        os.remove('path/foo')
2576
        os.symlink('bing', 'path/foo')
2577
        wt.commit('F foo => bing', rev_id='F-id')
2578
        wt.set_last_revision('B-id')
2579
        wt.branch.set_last_revision_info(2, 'B-id')
2580
        wt.revert()
2581
        wt.merge_from_branch(wt.branch, 'C-id')
2582
        wt.commit('D merges B & C', rev_id='D-id')
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2583
        wt_base = wt.controldir.sprout('base', 'A-id').open_workingtree()
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2584
        wt_base.lock_read()
2585
        self.addCleanup(wt_base.unlock)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2586
        wt_lca1 = wt.controldir.sprout('b-tree', 'B-id').open_workingtree()
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2587
        wt_lca1.lock_read()
2588
        self.addCleanup(wt_lca1.unlock)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2589
        wt_lca2 = wt.controldir.sprout('c-tree', 'C-id').open_workingtree()
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2590
        wt_lca2.lock_read()
2591
        self.addCleanup(wt_lca2.unlock)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2592
        wt_other = wt.controldir.sprout('other', 'F-id').open_workingtree()
3514.4.34 by John Arbash Meinel
Handle symlinks properly when objects are not RevisionTrees
2593
        wt_other.lock_read()
2594
        self.addCleanup(wt_other.unlock)
2595
        merge_obj = _mod_merge.Merge3Merger(wt, wt, wt_base,
2596
            wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2597
        entries = list(merge_obj._entries_lca())
2598
        root_id = wt.path2id('')
2599
        self.assertEqual([('foo-id', True,
2600
                           ((root_id, [root_id, root_id]), root_id, root_id),
2601
                           ((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2602
                           ((False, [False, False]), False, False)),
2603
                         ], entries)
2604
3514.4.25 by John Arbash Meinel
A few more merge-level behavior tests.
2605
    def test_other_reverted_path_to_base(self):
2606
        #   A       Path at 'foo'
2607
        #  / \
2608
        # B   C     Path at 'bar' in B
2609
        # |\ /|
2610
        # | X |
2611
        # |/ \|
2612
        # D   E     Path at 'bar'
2613
        #     |
2614
        #     F     Path at 'foo'
2615
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2616
        builder.build_snapshot(None,
3514.4.25 by John Arbash Meinel
A few more merge-level behavior tests.
2617
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2618
             ('add', (u'foo', 'foo-id', 'file', 'a\nb\nc\n'))],
2619
            revision_id='A-id')
2620
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2621
        builder.build_snapshot(['A-id'],
2622
            [('rename', ('foo', 'bar'))], revision_id='B-id')
2623
        builder.build_snapshot(['C-id', 'B-id'],
2624
            [('rename', ('foo', 'bar'))], revision_id='E-id') # merge the rename
2625
        builder.build_snapshot(['E-id'],
2626
            [('rename', ('bar', 'foo'))], revision_id='F-id') # Rename back to BASE
2627
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.25 by John Arbash Meinel
A few more merge-level behavior tests.
2628
        wt, conflicts = self.do_merge(builder, 'F-id')
2629
        self.assertEqual(0, conflicts)
2630
        self.assertEqual('foo', wt.id2path('foo-id'))
2631
2632
    def test_other_reverted_content_to_base(self):
2633
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2634
        builder.build_snapshot(None,
3514.4.25 by John Arbash Meinel
A few more merge-level behavior tests.
2635
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2636
             ('add', (u'foo', 'foo-id', 'file', 'base content\n'))],
2637
            revision_id='A-id')
2638
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2639
        builder.build_snapshot(['A-id'],
2640
            [('modify', ('foo-id', 'B content\n'))],
2641
            revision_id='B-id')
2642
        builder.build_snapshot(['C-id', 'B-id'],
2643
            [('modify', ('foo-id', 'B content\n'))],
2644
            revision_id='E-id') # merge the content
2645
        builder.build_snapshot(['E-id'],
2646
            [('modify', ('foo-id', 'base content\n'))],
2647
            revision_id='F-id') # Revert back to BASE
2648
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.25 by John Arbash Meinel
A few more merge-level behavior tests.
2649
        wt, conflicts = self.do_merge(builder, 'F-id')
2650
        self.assertEqual(0, conflicts)
2651
        # TODO: We need to use the per-file graph to properly select a BASE
3514.4.26 by John Arbash Meinel
Clean up comments, only symlink support left.
2652
        #       before this will work. Or at least use the LCA trees to find
2653
        #       the appropriate content base. (which is B, not A).
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
2654
        self.assertEqual('base content\n', wt.get_file_text('foo'))
3514.4.25 by John Arbash Meinel
A few more merge-level behavior tests.
2655
3514.4.28 by John Arbash Meinel
More symlink tests.
2656
    def test_other_modified_content(self):
2657
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2658
        builder.build_snapshot(None,
3514.4.28 by John Arbash Meinel
More symlink tests.
2659
            [('add', (u'', 'a-root-id', 'directory', None)),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2660
             ('add', (u'foo', 'foo-id', 'file', 'base content\n'))],
2661
            revision_id='A-id')
2662
        builder.build_snapshot(['A-id'], [], revision_id='C-id')
2663
        builder.build_snapshot(['A-id'],
2664
            [('modify', ('foo-id', 'B content\n'))],
2665
            revision_id='B-id')
2666
        builder.build_snapshot(['C-id', 'B-id'],
2667
            [('modify', ('foo-id', 'B content\n'))],
2668
            revision_id='E-id') # merge the content
2669
        builder.build_snapshot(['E-id'],
2670
            [('modify', ('foo-id', 'F content\n'))],
2671
            revision_id='F-id') # Override B content
2672
        builder.build_snapshot(['B-id', 'C-id'], [], revision_id='D-id')
3514.4.28 by John Arbash Meinel
More symlink tests.
2673
        wt, conflicts = self.do_merge(builder, 'F-id')
2674
        self.assertEqual(0, conflicts)
6809.4.5 by Jelmer Vernooij
Swap arguments for get_file_*.
2675
        self.assertEqual('F content\n', wt.get_file_text('foo'))
3514.4.28 by John Arbash Meinel
More symlink tests.
2676
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2677
    def test_all_wt(self):
2678
        """Check behavior if all trees are Working Trees."""
2679
        # The big issue is that entry.revision is None for WorkingTrees. (as is
2680
        # entry.text_sha1, etc. So we need to make sure we handle that case
2681
        # correctly.
2682
        #   A   Content of 'foo', path of 'a'
2683
        #   |\
2684
        #   B C B modifies content, C renames 'a' => 'b'
2685
        #   |X|
2686
        #   D E E updates content, renames 'b' => 'c'
2687
        builder = self.get_builder()
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2688
        builder.build_snapshot(None,
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2689
            [('add', (u'', 'a-root-id', 'directory', None)),
2690
             ('add', (u'a', 'a-id', 'file', 'base content\n')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2691
             ('add', (u'foo', 'foo-id', 'file', 'base content\n'))],
2692
            revision_id='A-id')
2693
        builder.build_snapshot(['A-id'],
2694
            [('modify', ('foo-id', 'B content\n'))],
2695
            revision_id='B-id')
2696
        builder.build_snapshot(['A-id'],
2697
            [('rename', ('a', 'b'))],
2698
            revision_id='C-id')
2699
        builder.build_snapshot(['C-id', 'B-id'],
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2700
            [('rename', ('b', 'c')),
6816.2.3 by Jelmer Vernooij
Port over last uses of build_snapshot.
2701
             ('modify', ('foo-id', 'E content\n'))],
2702
            revision_id='E-id')
2703
        builder.build_snapshot(['B-id', 'C-id'],
2704
            [('rename', ('a', 'b'))], revision_id='D-id') # merged change
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2705
        wt_this = self.get_wt_from_builder(builder)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2706
        wt_base = wt_this.controldir.sprout('base', 'A-id').open_workingtree()
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2707
        wt_base.lock_read()
2708
        self.addCleanup(wt_base.unlock)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2709
        wt_lca1 = wt_this.controldir.sprout('b-tree', 'B-id').open_workingtree()
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2710
        wt_lca1.lock_read()
2711
        self.addCleanup(wt_lca1.unlock)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2712
        wt_lca2 = wt_this.controldir.sprout('c-tree', 'C-id').open_workingtree()
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2713
        wt_lca2.lock_read()
2714
        self.addCleanup(wt_lca2.unlock)
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
2715
        wt_other = wt_this.controldir.sprout('other', 'E-id').open_workingtree()
3514.4.32 by John Arbash Meinel
Add a test for proper behavior when *everything* is a WT.
2716
        wt_other.lock_read()
2717
        self.addCleanup(wt_other.unlock)
2718
        merge_obj = _mod_merge.Merge3Merger(wt_this, wt_this, wt_base,
2719
            wt_other, lca_trees=[wt_lca1, wt_lca2], do_merge=False)
2720
        entries = list(merge_obj._entries_lca())
2721
        root_id = 'a-root-id'
2722
        self.assertEqual([('a-id', False,
2723
                           ((root_id, [root_id, root_id]), root_id, root_id),
2724
                           ((u'a', [u'a', u'b']), u'c', u'b'),
2725
                           ((False, [False, False]), False, False)),
2726
                          ('foo-id', True,
2727
                           ((root_id, [root_id, root_id]), root_id, root_id),
2728
                           ((u'foo', [u'foo', u'foo']), u'foo', u'foo'),
2729
                           ((False, [False, False]), False, False)),
2730
                         ], entries)
2731
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2732
    def test_nested_tree_unmodified(self):
2733
        # Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2734
        # 'tree-reference'
2735
        wt = self.make_branch_and_tree('tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2736
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2737
        wt.lock_write()
2738
        self.addCleanup(wt.unlock)
2739
        sub_tree = self.make_branch_and_tree('tree/sub-tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2740
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2741
        wt.set_root_id('a-root-id')
2742
        sub_tree.set_root_id('sub-tree-root')
2743
        self.build_tree_contents([('tree/sub-tree/file', 'text1')])
2744
        sub_tree.add('file')
2745
        sub_tree.commit('foo', rev_id='sub-A-id')
2746
        wt.add_reference(sub_tree)
2747
        wt.commit('set text to 1', rev_id='A-id', recursive=None)
2748
        # Now create a criss-cross merge in the parent, without modifying the
2749
        # subtree
2750
        wt.commit('B', rev_id='B-id', recursive=None)
2751
        wt.set_last_revision('A-id')
2752
        wt.branch.set_last_revision_info(1, 'A-id')
2753
        wt.commit('C', rev_id='C-id', recursive=None)
2754
        wt.merge_from_branch(wt.branch, to_revision='B-id')
2755
        wt.commit('E', rev_id='E-id', recursive=None)
2756
        wt.set_parent_ids(['B-id', 'C-id'])
2757
        wt.branch.set_last_revision_info(2, 'B-id')
2758
        wt.commit('D', rev_id='D-id', recursive=None)
2759
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2760
        merger = _mod_merge.Merger.from_revision_ids(wt, 'E-id')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2761
        merger.merge_type = _mod_merge.Merge3Merger
2762
        merge_obj = merger.make_merger()
2763
        entries = list(merge_obj._entries_lca())
2764
        self.assertEqual([], entries)
2765
2766
    def test_nested_tree_subtree_modified(self):
2767
        # Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2768
        # 'tree-reference'
2769
        wt = self.make_branch_and_tree('tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2770
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2771
        wt.lock_write()
2772
        self.addCleanup(wt.unlock)
2773
        sub_tree = self.make_branch_and_tree('tree/sub',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2774
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2775
        wt.set_root_id('a-root-id')
2776
        sub_tree.set_root_id('sub-tree-root')
2777
        self.build_tree_contents([('tree/sub/file', 'text1')])
2778
        sub_tree.add('file')
2779
        sub_tree.commit('foo', rev_id='sub-A-id')
2780
        wt.add_reference(sub_tree)
2781
        wt.commit('set text to 1', rev_id='A-id', recursive=None)
2782
        # Now create a criss-cross merge in the parent, without modifying the
2783
        # subtree
2784
        wt.commit('B', rev_id='B-id', recursive=None)
2785
        wt.set_last_revision('A-id')
2786
        wt.branch.set_last_revision_info(1, 'A-id')
2787
        wt.commit('C', rev_id='C-id', recursive=None)
2788
        wt.merge_from_branch(wt.branch, to_revision='B-id')
2789
        self.build_tree_contents([('tree/sub/file', 'text2')])
2790
        sub_tree.commit('modify contents', rev_id='sub-B-id')
2791
        wt.commit('E', rev_id='E-id', recursive=None)
2792
        wt.set_parent_ids(['B-id', 'C-id'])
2793
        wt.branch.set_last_revision_info(2, 'B-id')
2794
        wt.commit('D', rev_id='D-id', recursive=None)
2795
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2796
        merger = _mod_merge.Merger.from_revision_ids(wt, 'E-id')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2797
        merger.merge_type = _mod_merge.Merge3Merger
2798
        merge_obj = merger.make_merger()
2799
        entries = list(merge_obj._entries_lca())
2800
        # Nothing interesting about this sub-tree, because content changes are
2801
        # computed at a higher level
2802
        self.assertEqual([], entries)
2803
2804
    def test_nested_tree_subtree_renamed(self):
2805
        # Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2806
        # 'tree-reference'
2807
        wt = self.make_branch_and_tree('tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2808
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2809
        wt.lock_write()
2810
        self.addCleanup(wt.unlock)
2811
        sub_tree = self.make_branch_and_tree('tree/sub',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2812
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2813
        wt.set_root_id('a-root-id')
2814
        sub_tree.set_root_id('sub-tree-root')
2815
        self.build_tree_contents([('tree/sub/file', 'text1')])
2816
        sub_tree.add('file')
2817
        sub_tree.commit('foo', rev_id='sub-A-id')
2818
        wt.add_reference(sub_tree)
2819
        wt.commit('set text to 1', rev_id='A-id', recursive=None)
2820
        # Now create a criss-cross merge in the parent, without modifying the
2821
        # subtree
2822
        wt.commit('B', rev_id='B-id', recursive=None)
2823
        wt.set_last_revision('A-id')
2824
        wt.branch.set_last_revision_info(1, 'A-id')
2825
        wt.commit('C', rev_id='C-id', recursive=None)
2826
        wt.merge_from_branch(wt.branch, to_revision='B-id')
2827
        wt.rename_one('sub', 'alt_sub')
2828
        wt.commit('E', rev_id='E-id', recursive=None)
2829
        wt.set_last_revision('B-id')
2830
        wt.revert()
2831
        wt.set_parent_ids(['B-id', 'C-id'])
2832
        wt.branch.set_last_revision_info(2, 'B-id')
2833
        wt.commit('D', rev_id='D-id', recursive=None)
2834
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2835
        merger = _mod_merge.Merger.from_revision_ids(wt, 'E-id')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2836
        merger.merge_type = _mod_merge.Merge3Merger
2837
        merge_obj = merger.make_merger()
2838
        entries = list(merge_obj._entries_lca())
2839
        root_id = 'a-root-id'
2840
        self.assertEqual([('sub-tree-root', False,
2841
                           ((root_id, [root_id, root_id]), root_id, root_id),
2842
                           ((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2843
                           ((False, [False, False]), False, False)),
2844
                         ], entries)
2845
2846
    def test_nested_tree_subtree_renamed_and_modified(self):
2847
        # Tested with a real WT, because BranchBuilder/MemoryTree don't handle
2848
        # 'tree-reference'
2849
        wt = self.make_branch_and_tree('tree',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2850
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2851
        wt.lock_write()
2852
        self.addCleanup(wt.unlock)
2853
        sub_tree = self.make_branch_and_tree('tree/sub',
6437.14.2 by Jelmer Vernooij
Run subtree tests with development-subtree rather than deprecated dirstate-with-subtree.
2854
            format='development-subtree')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2855
        wt.set_root_id('a-root-id')
2856
        sub_tree.set_root_id('sub-tree-root')
2857
        self.build_tree_contents([('tree/sub/file', 'text1')])
2858
        sub_tree.add('file')
2859
        sub_tree.commit('foo', rev_id='sub-A-id')
2860
        wt.add_reference(sub_tree)
2861
        wt.commit('set text to 1', rev_id='A-id', recursive=None)
2862
        # Now create a criss-cross merge in the parent, without modifying the
2863
        # subtree
2864
        wt.commit('B', rev_id='B-id', recursive=None)
2865
        wt.set_last_revision('A-id')
2866
        wt.branch.set_last_revision_info(1, 'A-id')
2867
        wt.commit('C', rev_id='C-id', recursive=None)
2868
        wt.merge_from_branch(wt.branch, to_revision='B-id')
2869
        self.build_tree_contents([('tree/sub/file', 'text2')])
2870
        sub_tree.commit('modify contents', rev_id='sub-B-id')
2871
        wt.rename_one('sub', 'alt_sub')
2872
        wt.commit('E', rev_id='E-id', recursive=None)
2873
        wt.set_last_revision('B-id')
2874
        wt.revert()
2875
        wt.set_parent_ids(['B-id', 'C-id'])
2876
        wt.branch.set_last_revision_info(2, 'B-id')
2877
        wt.commit('D', rev_id='D-id', recursive=None)
2878
6719.1.4 by Jelmer Vernooij
Fix remaining tests.
2879
        merger = _mod_merge.Merger.from_revision_ids(wt, 'E-id')
3514.4.33 by John Arbash Meinel
Implement support for 'tree-reference'.
2880
        merger.merge_type = _mod_merge.Merge3Merger
2881
        merge_obj = merger.make_merger()
2882
        entries = list(merge_obj._entries_lca())
2883
        root_id = 'a-root-id'
2884
        self.assertEqual([('sub-tree-root', False,
2885
                           ((root_id, [root_id, root_id]), root_id, root_id),
2886
                           ((u'sub', [u'sub', u'sub']), u'alt_sub', u'sub'),
2887
                           ((False, [False, False]), False, False)),
2888
                         ], entries)
2889
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2890
2891
class TestLCAMultiWay(tests.TestCase):
2892
3514.4.30 by John Arbash Meinel
Several updates.
2893
    def assertLCAMultiWay(self, expected, base, lcas, other, this,
2894
                          allow_overriding_lca=True):
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2895
        self.assertEqual(expected, _mod_merge.Merge3Merger._lca_multi_way(
3514.4.30 by John Arbash Meinel
Several updates.
2896
                                (base, lcas), other, this,
2897
                                allow_overriding_lca=allow_overriding_lca))
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2898
2899
    def test_other_equal_equal_lcas(self):
2900
        """Test when OTHER=LCA and all LCAs are identical."""
2901
        self.assertLCAMultiWay('this',
2902
            'bval', ['bval', 'bval'], 'bval', 'bval')
2903
        self.assertLCAMultiWay('this',
2904
            'bval', ['lcaval', 'lcaval'], 'lcaval', 'bval')
2905
        self.assertLCAMultiWay('this',
2906
            'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'bval')
2907
        self.assertLCAMultiWay('this',
2908
            'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', 'tval')
2909
        self.assertLCAMultiWay('this',
2910
            'bval', ['lcaval', 'lcaval', 'lcaval'], 'lcaval', None)
2911
2912
    def test_other_equal_this(self):
2913
        """Test when other and this are identical."""
2914
        self.assertLCAMultiWay('this',
2915
            'bval', ['bval', 'bval'], 'oval', 'oval')
2916
        self.assertLCAMultiWay('this',
2917
            'bval', ['lcaval', 'lcaval'], 'oval', 'oval')
2918
        self.assertLCAMultiWay('this',
2919
            'bval', ['cval', 'dval'], 'oval', 'oval')
2920
        self.assertLCAMultiWay('this',
2921
            'bval', [None, 'lcaval'], 'oval', 'oval')
2922
        self.assertLCAMultiWay('this',
2923
            None, [None, 'lcaval'], 'oval', 'oval')
2924
        self.assertLCAMultiWay('this',
2925
            None, ['lcaval', 'lcaval'], 'oval', 'oval')
2926
        self.assertLCAMultiWay('this',
2927
            None, ['cval', 'dval'], 'oval', 'oval')
2928
        self.assertLCAMultiWay('this',
2929
            None, ['cval', 'dval'], None, None)
2930
        self.assertLCAMultiWay('this',
2931
            None, ['cval', 'dval', 'eval', 'fval'], 'oval', 'oval')
2932
2933
    def test_no_lcas(self):
2934
        self.assertLCAMultiWay('this',
2935
            'bval', [], 'bval', 'tval')
2936
        self.assertLCAMultiWay('other',
2937
            'bval', [], 'oval', 'bval')
2938
        self.assertLCAMultiWay('conflict',
2939
            'bval', [], 'oval', 'tval')
2940
        self.assertLCAMultiWay('this',
2941
            'bval', [], 'oval', 'oval')
2942
2943
    def test_lca_supersedes_other_lca(self):
2944
        """If one lca == base, the other lca takes precedence"""
2945
        self.assertLCAMultiWay('this',
2946
            'bval', ['bval', 'lcaval'], 'lcaval', 'tval')
2947
        self.assertLCAMultiWay('this',
2948
            'bval', ['bval', 'lcaval'], 'lcaval', 'bval')
2949
        # This is actually considered a 'revert' because the 'lcaval' in LCAS
2950
        # supersedes the BASE val (in the other LCA) but then OTHER reverts it
2951
        # back to bval.
2952
        self.assertLCAMultiWay('other',
2953
            'bval', ['bval', 'lcaval'], 'bval', 'lcaval')
2954
        self.assertLCAMultiWay('conflict',
2955
            'bval', ['bval', 'lcaval'], 'bval', 'tval')
2956
2957
    def test_other_and_this_pick_different_lca(self):
2958
        # OTHER and THIS resolve the lca conflict in different ways
2959
        self.assertLCAMultiWay('conflict',
2960
            'bval', ['lca1val', 'lca2val'], 'lca1val', 'lca2val')
2961
        self.assertLCAMultiWay('conflict',
2962
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'lca2val')
2963
        self.assertLCAMultiWay('conflict',
2964
            'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'lca2val')
2965
2966
    def test_other_in_lca(self):
2967
        # OTHER takes a value of one of the LCAs, THIS takes a new value, which
2968
        # theoretically supersedes both LCA values and 'wins'
2969
        self.assertLCAMultiWay('this',
2970
            'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval')
2971
        self.assertLCAMultiWay('this',
2972
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval')
3514.4.30 by John Arbash Meinel
Several updates.
2973
        self.assertLCAMultiWay('conflict',
2974
            'bval', ['lca1val', 'lca2val'], 'lca1val', 'newval',
2975
            allow_overriding_lca=False)
2976
        self.assertLCAMultiWay('conflict',
2977
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'newval',
2978
            allow_overriding_lca=False)
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2979
        # THIS reverted back to BASE, but that is an explicit supersede of all
2980
        # LCAs
2981
        self.assertLCAMultiWay('this',
2982
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval')
2983
        self.assertLCAMultiWay('this',
2984
            'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval')
3514.4.30 by John Arbash Meinel
Several updates.
2985
        self.assertLCAMultiWay('conflict',
2986
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'lca1val', 'bval',
2987
            allow_overriding_lca=False)
2988
        self.assertLCAMultiWay('conflict',
2989
            'bval', ['lca1val', 'lca2val', 'bval'], 'lca1val', 'bval',
2990
            allow_overriding_lca=False)
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
2991
2992
    def test_this_in_lca(self):
2993
        # THIS takes a value of one of the LCAs, OTHER takes a new value, which
2994
        # theoretically supersedes both LCA values and 'wins'
2995
        self.assertLCAMultiWay('other',
2996
            'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val')
2997
        self.assertLCAMultiWay('other',
2998
            'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val')
3514.4.30 by John Arbash Meinel
Several updates.
2999
        self.assertLCAMultiWay('conflict',
3000
            'bval', ['lca1val', 'lca2val'], 'oval', 'lca1val',
3001
            allow_overriding_lca=False)
3002
        self.assertLCAMultiWay('conflict',
3003
            'bval', ['lca1val', 'lca2val'], 'oval', 'lca2val',
3004
            allow_overriding_lca=False)
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
3005
        # OTHER reverted back to BASE, but that is an explicit supersede of all
3006
        # LCAs
3007
        self.assertLCAMultiWay('other',
3008
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val')
3514.4.30 by John Arbash Meinel
Several updates.
3009
        self.assertLCAMultiWay('conflict',
3010
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'bval', 'lca3val',
3011
            allow_overriding_lca=False)
3514.4.21 by John Arbash Meinel
Hook up the lca-way logic into the path handlers.
3012
3013
    def test_all_differ(self):
3014
        self.assertLCAMultiWay('conflict',
3015
            'bval', ['lca1val', 'lca2val'], 'oval', 'tval')
3016
        self.assertLCAMultiWay('conflict',
3017
            'bval', ['lca1val', 'lca2val', 'lca2val'], 'oval', 'tval')
3018
        self.assertLCAMultiWay('conflict',
3019
            'bval', ['lca1val', 'lca2val', 'lca3val'], 'oval', 'tval')
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3020
3021
3022
class TestConfigurableFileMerger(tests.TestCaseWithTransport):
3023
4797.9.2 by Vincent Ladeuil
More tests.
3024
    def setUp(self):
3025
        super(TestConfigurableFileMerger, self).setUp()
3026
        self.calls = []
3027
3028
    def get_merger_factory(self):
3029
        # Allows  the inner methods to access the test attributes
5340.15.1 by John Arbash Meinel
supersede exc-info branch
3030
        calls = self.calls
4797.9.2 by Vincent Ladeuil
More tests.
3031
3032
        class FooMerger(_mod_merge.ConfigurableFileMerger):
4797.5.3 by Robert Collins
Tweak ConfigurableFileMerger to use class variables rather than requiring __init__ wrapping as future proofing for helper functions.
3033
            name_prefix = "foo"
4797.9.1 by Vincent Ladeuil
No test was exercising the faulty code path.
3034
            default_files = ['bar']
4797.9.2 by Vincent Ladeuil
More tests.
3035
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3036
            def merge_text(self, params):
5340.15.1 by John Arbash Meinel
supersede exc-info branch
3037
                calls.append('merge_text')
4797.9.1 by Vincent Ladeuil
No test was exercising the faulty code path.
3038
                return ('not_applicable', None)
4797.9.2 by Vincent Ladeuil
More tests.
3039
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3040
        def factory(merger):
4797.9.2 by Vincent Ladeuil
More tests.
3041
            result = FooMerger(merger)
3042
            # Make sure we start with a clean slate
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3043
            self.assertEqual(None, result.affected_files)
4797.9.2 by Vincent Ladeuil
More tests.
3044
            # Track the original merger
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3045
            self.merger = result
3046
            return result
4797.9.2 by Vincent Ladeuil
More tests.
3047
3048
        return factory
3049
3050
    def _install_hook(self, factory):
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3051
        _mod_merge.Merger.hooks.install_named_hook('merge_file_content',
4797.9.1 by Vincent Ladeuil
No test was exercising the faulty code path.
3052
                                                   factory, 'test factory')
4797.9.2 by Vincent Ladeuil
More tests.
3053
3054
    def make_builder(self):
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3055
        builder = test_merge_core.MergeBuilder(self.test_base_dir)
3056
        self.addCleanup(builder.cleanup)
4797.9.2 by Vincent Ladeuil
More tests.
3057
        return builder
3058
3059
    def make_text_conflict(self, file_name='bar'):
3060
        factory = self.get_merger_factory()
3061
        self._install_hook(factory)
3062
        builder = self.make_builder()
3063
        builder.add_file('bar-id', builder.tree_root, file_name, 'text1', True)
4797.9.1 by Vincent Ladeuil
No test was exercising the faulty code path.
3064
        builder.change_contents('bar-id', other='text4', this='text3')
4797.9.2 by Vincent Ladeuil
More tests.
3065
        return builder
3066
3067
    def make_kind_change(self):
3068
        factory = self.get_merger_factory()
3069
        self._install_hook(factory)
3070
        builder = self.make_builder()
3071
        builder.add_file('bar-id', builder.tree_root, 'bar', 'text1', True,
3072
                         this=False)
3073
        builder.add_dir('bar-dir', builder.tree_root, 'bar-id',
3074
                        base=False, other=False)
3075
        return builder
3076
4797.21.1 by Aaron Bentley
Fix merge when this_tree is not a WorkingTree.
3077
    def test_uses_this_branch(self):
3078
        builder = self.make_text_conflict()
3079
        tt = builder.make_preview_transform()
3080
        self.addCleanup(tt.finalize)
3081
4797.9.2 by Vincent Ladeuil
More tests.
3082
    def test_affected_files_cached(self):
3083
        """Ensures that the config variable is cached"""
3084
        builder = self.make_text_conflict()
4797.5.2 by Robert Collins
Refactor NewsMerger into a reusable base class merge.ConfigurableFileMerger.
3085
        conflicts = builder.merge()
3086
        # The hook should set the variable
4797.9.1 by Vincent Ladeuil
No test was exercising the faulty code path.
3087
        self.assertEqual(['bar'], self.merger.affected_files)
4797.9.2 by Vincent Ladeuil
More tests.
3088
        self.assertEqual(1, len(conflicts))
3089
3090
    def test_hook_called_for_text_conflicts(self):
3091
        builder = self.make_text_conflict()
3092
        conflicts = builder.merge()
3093
        # The hook should call the merge_text() method
3094
        self.assertEqual(['merge_text'], self.calls)
3095
3096
    def test_hook_not_called_for_kind_change(self):
3097
        builder = self.make_kind_change()
3098
        conflicts = builder.merge()
3099
        # The hook should not call the merge_text() method
3100
        self.assertEqual([], self.calls)
3101
3102
    def test_hook_not_called_for_other_files(self):
3103
        builder = self.make_text_conflict('foobar')
3104
        conflicts = builder.merge()
3105
        # The hook should not call the merge_text() method
3106
        self.assertEqual([], self.calls)
5246.2.34 by Andrew Bennetts
Delete test_merge_into, and put those tests directly in test_merge.
3107
3108
3109
class TestMergeIntoBase(tests.TestCaseWithTransport):
3110
3111
    def setup_simple_branch(self, relpath, shape=None, root_id=None):
3112
        """One commit, containing tree specified by optional shape.
3113
        
3114
        Default is empty tree (just root entry).
3115
        """
3116
        if root_id is None:
3117
            root_id = '%s-root-id' % (relpath,)
3118
        wt = self.make_branch_and_tree(relpath)
3119
        wt.set_root_id(root_id)
3120
        if shape is not None:
3121
            adjusted_shape = [relpath + '/' + elem for elem in shape]
3122
            self.build_tree(adjusted_shape)
3123
            ids = ['%s-%s-id' % (relpath, basename(elem.rstrip('/')))
3124
                   for elem in shape]
3125
            wt.add(shape, ids=ids)
3126
        rev_id = 'r1-%s' % (relpath,)
3127
        wt.commit("Initial commit of %s" % (relpath,), rev_id=rev_id)
3128
        self.assertEqual(root_id, wt.path2id(''))
3129
        return wt
3130
3131
    def setup_two_branches(self, custom_root_ids=True):
3132
        """Setup 2 branches, one will be a library, the other a project."""
3133
        if custom_root_ids:
3134
            root_id = None
3135
        else:
3136
            root_id = inventory.ROOT_ID
3137
        project_wt = self.setup_simple_branch(
3138
            'project', ['README', 'dir/', 'dir/file.c'],
3139
            root_id)
3140
        lib_wt = self.setup_simple_branch(
3141
            'lib1', ['README', 'Makefile', 'foo.c'], root_id)
3142
3143
        return project_wt, lib_wt
3144
3145
    def do_merge_into(self, location, merge_as):
3146
        """Helper for using MergeIntoMerger.
3147
        
3148
        :param location: location of directory to merge from, either the
3149
            location of a branch or of a path inside a branch.
3150
        :param merge_as: the path in a tree to add the new directory as.
3151
        :returns: the conflicts from 'do_merge'.
3152
        """
3153
        operation = cleanup.OperationWithCleanups(self._merge_into)
3154
        return operation.run(location, merge_as)
3155
3156
    def _merge_into(self, op, location, merge_as):
3157
        # Open and lock the various tree and branch objects
3158
        wt, subdir_relpath = WorkingTree.open_containing(merge_as)
3159
        op.add_cleanup(wt.lock_write().unlock)
3160
        branch_to_merge, subdir_to_merge = _mod_branch.Branch.open_containing(
3161
            location)
3162
        op.add_cleanup(branch_to_merge.lock_read().unlock)
3163
        other_tree = branch_to_merge.basis_tree()
3164
        op.add_cleanup(other_tree.lock_read().unlock)
3165
        # Perform the merge
3166
        merger = _mod_merge.MergeIntoMerger(this_tree=wt, other_tree=other_tree,
3167
            other_branch=branch_to_merge, target_subdir=subdir_relpath,
3168
            source_subpath=subdir_to_merge)
3169
        merger.set_base_revision(_mod_revision.NULL_REVISION, branch_to_merge)
3170
        conflicts = merger.do_merge()
3171
        merger.set_pending()
3172
        return conflicts
3173
3174
    def assertTreeEntriesEqual(self, expected_entries, tree):
3175
        """Assert that 'tree' contains the expected inventory entries.
3176
3177
        :param expected_entries: sequence of (path, file-id) pairs.
3178
        """
3179
        files = [(path, ie.file_id) for path, ie in tree.iter_entries_by_dir()]
3180
        self.assertEqual(expected_entries, files)
3181
3182
3183
class TestMergeInto(TestMergeIntoBase):
3184
3185
    def test_newdir_with_unique_roots(self):
3186
        """Merge a branch with a unique root into a new directory."""
3187
        project_wt, lib_wt = self.setup_two_branches()
3188
        self.do_merge_into('lib1', 'project/lib1')
3189
        project_wt.lock_read()
3190
        self.addCleanup(project_wt.unlock)
3191
        # The r1-lib1 revision should be merged into this one
3192
        self.assertEqual(['r1-project', 'r1-lib1'], project_wt.get_parent_ids())
3193
        self.assertTreeEntriesEqual(
3194
            [('', 'project-root-id'),
3195
             ('README', 'project-README-id'),
3196
             ('dir', 'project-dir-id'),
3197
             ('lib1', 'lib1-root-id'),
3198
             ('dir/file.c', 'project-file.c-id'),
3199
             ('lib1/Makefile', 'lib1-Makefile-id'),
3200
             ('lib1/README', 'lib1-README-id'),
3201
             ('lib1/foo.c', 'lib1-foo.c-id'),
3202
            ], project_wt)
3203
3204
    def test_subdir(self):
3205
        """Merge a branch into a subdirectory of an existing directory."""
3206
        project_wt, lib_wt = self.setup_two_branches()
3207
        self.do_merge_into('lib1', 'project/dir/lib1')
3208
        project_wt.lock_read()
3209
        self.addCleanup(project_wt.unlock)
3210
        # The r1-lib1 revision should be merged into this one
3211
        self.assertEqual(['r1-project', 'r1-lib1'], project_wt.get_parent_ids())
3212
        self.assertTreeEntriesEqual(
3213
            [('', 'project-root-id'),
3214
             ('README', 'project-README-id'),
3215
             ('dir', 'project-dir-id'),
3216
             ('dir/file.c', 'project-file.c-id'),
3217
             ('dir/lib1', 'lib1-root-id'),
3218
             ('dir/lib1/Makefile', 'lib1-Makefile-id'),
3219
             ('dir/lib1/README', 'lib1-README-id'),
3220
             ('dir/lib1/foo.c', 'lib1-foo.c-id'),
3221
            ], project_wt)
3222
3223
    def test_newdir_with_repeat_roots(self):
3224
        """If the file-id of the dir to be merged already exists a new ID will
3225
        be allocated to let the merge happen.
3226
        """
3227
        project_wt, lib_wt = self.setup_two_branches(custom_root_ids=False)
3228
        root_id = project_wt.path2id('')
3229
        self.do_merge_into('lib1', 'project/lib1')
3230
        project_wt.lock_read()
3231
        self.addCleanup(project_wt.unlock)
3232
        # The r1-lib1 revision should be merged into this one
3233
        self.assertEqual(['r1-project', 'r1-lib1'], project_wt.get_parent_ids())
3234
        new_lib1_id = project_wt.path2id('lib1')
3235
        self.assertNotEqual(None, new_lib1_id)
3236
        self.assertTreeEntriesEqual(
3237
            [('', root_id),
3238
             ('README', 'project-README-id'),
3239
             ('dir', 'project-dir-id'),
3240
             ('lib1', new_lib1_id),
3241
             ('dir/file.c', 'project-file.c-id'),
3242
             ('lib1/Makefile', 'lib1-Makefile-id'),
3243
             ('lib1/README', 'lib1-README-id'),
3244
             ('lib1/foo.c', 'lib1-foo.c-id'),
3245
            ], project_wt)
3246
3247
    def test_name_conflict(self):
3248
        """When the target directory name already exists a conflict is
3249
        generated and the original directory is renamed to foo.moved.
3250
        """
3251
        dest_wt = self.setup_simple_branch('dest', ['dir/', 'dir/file.txt'])
3252
        src_wt = self.setup_simple_branch('src', ['README'])
3253
        conflicts = self.do_merge_into('src', 'dest/dir')
3254
        self.assertEqual(1, conflicts)
3255
        dest_wt.lock_read()
3256
        self.addCleanup(dest_wt.unlock)
3257
        # The r1-lib1 revision should be merged into this one
3258
        self.assertEqual(['r1-dest', 'r1-src'], dest_wt.get_parent_ids())
3259
        self.assertTreeEntriesEqual(
3260
            [('', 'dest-root-id'),
3261
             ('dir', 'src-root-id'),
3262
             ('dir.moved', 'dest-dir-id'),
3263
             ('dir/README', 'src-README-id'),
3264
             ('dir.moved/file.txt', 'dest-file.txt-id'),
3265
            ], dest_wt)
3266
3267
    def test_file_id_conflict(self):
3268
        """A conflict is generated if the merge-into adds a file (or other
3269
        inventory entry) with a file-id that already exists in the target tree.
3270
        """
3271
        dest_wt = self.setup_simple_branch('dest', ['file.txt'])
3272
        # Make a second tree with a file-id that will clash with file.txt in
3273
        # dest.
3274
        src_wt = self.make_branch_and_tree('src')
3275
        self.build_tree(['src/README'])
3276
        src_wt.add(['README'], ids=['dest-file.txt-id'])
3277
        src_wt.commit("Rev 1 of src.", rev_id='r1-src')
3278
        conflicts = self.do_merge_into('src', 'dest/dir')
3279
        # This is an edge case that shouldn't happen to users very often.  So
3280
        # we don't care really about the exact presentation of the conflict,
3281
        # just that there is one.
3282
        self.assertEqual(1, conflicts)
3283
3284
    def test_only_subdir(self):
3285
        """When the location points to just part of a tree, merge just that
3286
        subtree.
3287
        """
3288
        dest_wt = self.setup_simple_branch('dest')
3289
        src_wt = self.setup_simple_branch(
3290
            'src', ['hello.txt', 'dir/', 'dir/foo.c'])
3291
        conflicts = self.do_merge_into('src/dir', 'dest/dir')
3292
        dest_wt.lock_read()
3293
        self.addCleanup(dest_wt.unlock)
3294
        # The r1-lib1 revision should NOT be merged into this one (this is a
3295
        # partial merge).
3296
        self.assertEqual(['r1-dest'], dest_wt.get_parent_ids())
3297
        self.assertTreeEntriesEqual(
3298
            [('', 'dest-root-id'),
3299
             ('dir', 'src-dir-id'),
3300
             ('dir/foo.c', 'src-foo.c-id'),
3301
            ], dest_wt)
3302
3303
    def test_only_file(self):
3304
        """An edge case: merge just one file, not a whole dir."""
3305
        dest_wt = self.setup_simple_branch('dest')
3306
        two_file_wt = self.setup_simple_branch(
3307
            'two-file', ['file1.txt', 'file2.txt'])
3308
        conflicts = self.do_merge_into('two-file/file1.txt', 'dest/file1.txt')
3309
        dest_wt.lock_read()
3310
        self.addCleanup(dest_wt.unlock)
3311
        # The r1-lib1 revision should NOT be merged into this one
3312
        self.assertEqual(['r1-dest'], dest_wt.get_parent_ids())
3313
        self.assertTreeEntriesEqual(
3314
            [('', 'dest-root-id'), ('file1.txt', 'two-file-file1.txt-id')],
3315
            dest_wt)
3316
3317
    def test_no_such_source_path(self):
3318
        """PathNotInTree is raised if the specified path in the source tree
3319
        does not exist.
3320
        """
3321
        dest_wt = self.setup_simple_branch('dest')
3322
        two_file_wt = self.setup_simple_branch('src', ['dir/'])
3323
        self.assertRaises(_mod_merge.PathNotInTree, self.do_merge_into,
3324
            'src/no-such-dir', 'dest/foo')
3325
        dest_wt.lock_read()
3326
        self.addCleanup(dest_wt.unlock)
3327
        # The dest tree is unmodified.
3328
        self.assertEqual(['r1-dest'], dest_wt.get_parent_ids())
3329
        self.assertTreeEntriesEqual([('', 'dest-root-id')], dest_wt)
3330
3331
    def test_no_such_target_path(self):
3332
        """PathNotInTree is also raised if the specified path in the target
3333
        tree does not exist.
3334
        """
3335
        dest_wt = self.setup_simple_branch('dest')
3336
        two_file_wt = self.setup_simple_branch('src', ['file.txt'])
3337
        self.assertRaises(_mod_merge.PathNotInTree, self.do_merge_into,
3338
            'src', 'dest/no-such-dir/foo')
3339
        dest_wt.lock_read()
3340
        self.addCleanup(dest_wt.unlock)
3341
        # The dest tree is unmodified.
3342
        self.assertEqual(['r1-dest'], dest_wt.get_parent_ids())
3343
        self.assertTreeEntriesEqual([('', 'dest-root-id')], dest_wt)
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3344
3345
3346
class TestMergeHooks(TestCaseWithTransport):
3347
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3348
    def setUp(self):
3349
        super(TestMergeHooks, self).setUp()
3350
        self.tree_a = self.make_branch_and_tree('tree_a')
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3351
        self.build_tree_contents([('tree_a/file', 'content_1')])
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3352
        self.tree_a.add('file', 'file-id')
3353
        self.tree_a.commit('added file')
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3354
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
3355
        self.tree_b = self.tree_a.controldir.sprout('tree_b').open_workingtree()
6388.1.4 by Jelmer Vernooij
Fix tests.
3356
        self.build_tree_contents([('tree_b/file', 'content_2')])
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3357
        self.tree_b.commit('modify file')
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3358
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3359
    def test_pre_merge_hook_inject_different_tree(self):
6653.6.1 by Jelmer Vernooij
Rename a number of attributes from bzrdir to controldir.
3360
        tree_c = self.tree_b.controldir.sprout('tree_c').open_workingtree()
6388.1.4 by Jelmer Vernooij
Fix tests.
3361
        self.build_tree_contents([('tree_c/file', 'content_3')])
3362
        tree_c.commit("more content")
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3363
        calls = []
6388.1.4 by Jelmer Vernooij
Fix tests.
3364
        def factory(merger):
3365
            self.assertIsInstance(merger, _mod_merge.Merge3Merger)
3366
            merger.other_tree = tree_c
3367
            calls.append(merger)
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3368
        _mod_merge.Merger.hooks.install_named_hook('pre_merge',
3369
                                                   factory, 'test factory')
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3370
        self.tree_a.merge_from_branch(self.tree_b.branch)
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3371
6388.1.4 by Jelmer Vernooij
Fix tests.
3372
        self.assertFileEqual("content_3", 'tree_a/file')
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3373
        self.assertLength(1, calls)
3374
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3375
    def test_post_merge_hook_called(self):
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3376
        calls = []
6388.1.4 by Jelmer Vernooij
Fix tests.
3377
        def factory(merger):
3378
            self.assertIsInstance(merger, _mod_merge.Merge3Merger)
3379
            calls.append(merger)
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3380
        _mod_merge.Merger.hooks.install_named_hook('post_merge',
3381
                                                   factory, 'test factory')
3382
6388.1.7 by Jelmer Vernooij
Review feedback from Vila.
3383
        self.tree_a.merge_from_branch(self.tree_b.branch)
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3384
6388.1.4 by Jelmer Vernooij
Fix tests.
3385
        self.assertFileEqual("content_2", 'tree_a/file')
6388.1.3 by Jelmer Vernooij
Add pre and post merge hooks.
3386
        self.assertLength(1, calls)