/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
1
import os
1185.12.36 by abentley
Removed all remaining use of readonly_path
2
import stat
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
3
import sys
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
4
1559.1.1 by Robert Collins
Merge in InterRepository API support.
5
import bzrlib
1534.1.16 by Robert Collins
Merge from jam-integration.
6
from bzrlib.add import smart_add_tree
7
from bzrlib.builtins import merge
1534.10.20 by Aaron Bentley
Got all tests passing
8
from bzrlib.conflicts import ContentsConflict, TextConflict, PathConflict
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
9
from bzrlib.errors import (NotBranchError, NotVersionedError,
1534.7.130 by Aaron Bentley
More conflict handling, test porting
10
                           WorkingTreeNotRevision, BzrCommandError, NoDiff3)
1399.1.10 by Robert Collins
remove kind from the InventoryEntry constructor - only child classes should be created now
11
from bzrlib.inventory import RootEntry
12
import bzrlib.inventory as inventory
1534.7.140 by Aaron Bentley
Moved the merge stuff into merge.py
13
from bzrlib.merge import Merge3Merger, Diff3Merger, WeaveMerger
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
14
from bzrlib.osutils import (file_kind, mkdtemp, pathjoin, rename, rmtree,
15
                            sha_file, 
16
                            )
1534.7.140 by Aaron Bentley
Moved the merge stuff into merge.py
17
from bzrlib.transform import TreeTransform
1534.7.130 by Aaron Bentley
More conflict handling, test porting
18
from bzrlib.tests import TestCaseWithTransport, TestCase, TestSkipped
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
19
from bzrlib.workingtree import WorkingTree
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
20
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
21
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
22
class MergeBuilder(object):
23
    def __init__(self):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
24
        self.dir = mkdtemp(prefix="merge-test")
25
        def wt(name):
26
           path = pathjoin(self.dir, name)
27
           os.mkdir(path)
1559.1.1 by Robert Collins
Merge in InterRepository API support.
28
           wt = bzrlib.bzrdir.BzrDir.create_standalone_workingtree(path)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
29
           tt = TreeTransform(wt)
30
           return wt, tt
31
        self.base, self.base_tt = wt('base') 
32
        self.this, self.this_tt = wt('this')
33
        self.other, self.other_tt = wt('other')
1185.50.33 by John Arbash Meinel
Whitespace cleanups.
34
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
35
    def get_cset_path(self, parent, name):
36
        if name is None:
37
            assert (parent is None)
38
            return None
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 \
39
        return pathjoin(self.cset.entries[parent].path, name)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
40
1558.7.12 by Aaron Bentley
Additional spurious conflict test
41
    def add_file(self, id, parent, name, contents, executable, this=True, 
42
                 base=True, other=True):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
43
        def new_file(tt):
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
44
            parent_id = tt.trans_id_file_id(parent)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
45
            tt.new_file(name, parent_id, contents, id, executable)
1558.7.12 by Aaron Bentley
Additional spurious conflict test
46
        for option, tt in self.selected_transforms(this, base, other):
47
            if option is True:
48
                new_file(tt)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
49
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
50
    def merge(self, merge_type=Merge3Merger, interesting_ids=None, **kwargs):
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
51
        self.base_tt.apply()
52
        self.base.commit('base commit')
53
        for tt, wt in ((self.this_tt, self.this), (self.other_tt, self.other)):
54
            wt.branch.pull(self.base.branch)
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
55
            wt.set_last_revision(wt.branch.last_revision())
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
56
            tt.apply()
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
57
            wt.commit('branch commit')
58
            assert len(wt.branch.revision_history()) == 2
1559.1.1 by Robert Collins
Merge in InterRepository API support.
59
        self.this.branch.fetch(self.other.branch)
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
60
        other_basis = self.other.branch.basis_tree()
1558.2.2 by Aaron Bentley
Make remerge honour interesting-ids
61
        merger = merge_type(self.this, self.this, self.base, other_basis, 
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
62
                            interesting_ids=interesting_ids, **kwargs)
1534.7.131 by Aaron Bentley
Work on cooked conflicts
63
        return merger.cooked_conflicts
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
64
65
    def list_transforms(self):
66
        return [self.this_tt, self.base_tt, self.other_tt]
67
68
    def selected_transforms(self, this, base, other):
69
        pairs = [(this, self.this_tt), (base, self.base_tt), 
70
                 (other, self.other_tt)]
71
        return [(v, tt) for (v, tt) in pairs if v is not None]
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
72
1185.12.34 by Aaron Bentley
Added symlink three-way tests
73
    def add_symlink(self, id, parent, name, contents):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
74
        for tt in self.list_transforms():
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
75
            parent_id = tt.trans_id_file_id(parent)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
76
            tt.new_symlink(name, parent_id, contents, id)
1185.12.34 by Aaron Bentley
Added symlink three-way tests
77
1534.7.130 by Aaron Bentley
More conflict handling, test porting
78
    def remove_file(self, file_id, base=False, this=False, other=False):
79
        for option, tt in self.selected_transforms(this, base, other):
80
            if option is True:
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
81
                trans_id = tt.trans_id_file_id(file_id)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
82
                tt.cancel_creation(trans_id)
83
                tt.cancel_versioning(trans_id)
84
                tt.set_executability(None, trans_id)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
85
1534.7.130 by Aaron Bentley
More conflict handling, test porting
86
    def add_dir(self, file_id, parent, name):
87
        for tt in self.list_transforms():
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
88
            parent_id = tt.trans_id_file_id(parent)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
89
            tt.new_directory(name, parent_id, file_id)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
90
91
    def change_name(self, id, base=None, this=None, other=None):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
92
        for val, tt in ((base, self.base_tt), (this, self.this_tt), 
93
                        (other, self.other_tt)):
94
            if val is None:
95
                continue
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
96
            trans_id = tt.trans_id_file_id(id)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
97
            parent_id = tt.final_parent(trans_id)
98
            tt.adjust_path(val, parent_id, trans_id)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
99
1534.7.130 by Aaron Bentley
More conflict handling, test porting
100
    def change_parent(self, file_id, base=None, this=None, other=None):
101
        for parent, tt in self.selected_transforms(this, base, other):
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
102
            trans_id  = tt.trans_id_file_id(file_id)
103
            parent_id = tt.trans_id_file_id(parent)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
104
            tt.adjust_path(tt.final_name(trans_id), parent_id, trans_id)
105
106
    def change_contents(self, file_id, base=None, this=None, other=None):
107
        for contents, tt in self.selected_transforms(this, base, other):
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
108
            trans_id = tt.trans_id_file_id(file_id)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
109
            tt.cancel_creation(trans_id)
110
            tt.create_file(contents, trans_id)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
111
1185.12.34 by Aaron Bentley
Added symlink three-way tests
112
    def change_target(self, id, base=None, this=None, other=None):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
113
        for target, tt in self.selected_transforms(this, base, other):
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
114
            trans_id = tt.trans_id_file_id(id)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
115
            tt.cancel_creation(trans_id)
116
            tt.create_symlink(target, trans_id)
1185.12.34 by Aaron Bentley
Added symlink three-way tests
117
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
118
    def change_perms(self, id, base=None, this=None, other=None):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
119
        for executability, tt in self.selected_transforms(this, base, other):
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
120
            trans_id = tt.trans_id_file_id(id)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
121
            tt.set_executability(None, trans_id)
122
            tt.set_executability(executability, trans_id)
1185.12.34 by Aaron Bentley
Added symlink three-way tests
123
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
124
    def change_perms_tree(self, id, tree, mode):
125
        os.chmod(tree.full_path(id), mode)
126
127
    def merge_changeset(self, merge_factory):
974.1.83 by Aaron Bentley
Removed unused dir parameter from ExceptionConflictHandler
128
        conflict_handler = changeset.ExceptionConflictHandler()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
129
        return make_merge_changeset(self.cset, self.this, self.base,
130
                                    self.other, conflict_handler,
131
                                    merge_factory)
132
133
    def apply_inv_change(self, inventory_change, orig_inventory):
134
        orig_inventory_by_path = {}
135
        for file_id, path in orig_inventory.iteritems():
136
            orig_inventory_by_path[path] = file_id
137
138
        def parent_id(file_id):
139
            try:
140
                parent_dir = os.path.dirname(orig_inventory[file_id])
141
            except:
142
                print file_id
143
                raise
144
            if parent_dir == "":
145
                return None
146
            return orig_inventory_by_path[parent_dir]
147
        
148
        def new_path(file_id):
149
            if inventory_change.has_key(file_id):
150
                return inventory_change[file_id]
151
            else:
152
                parent = parent_id(file_id)
153
                if parent is None:
154
                    return orig_inventory[file_id]
155
                dirname = new_path(parent)
1185.50.31 by John Arbash Meinel
[merge] Denys Duchier, more tests for test_merge_core, and fixup of one test.
156
                return pathjoin(dirname, os.path.basename(orig_inventory[file_id]))
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
157
158
        new_inventory = {}
159
        for file_id in orig_inventory.iterkeys():
160
            path = new_path(file_id)
161
            if path is None:
162
                continue
163
            new_inventory[file_id] = path
164
165
        for file_id, path in inventory_change.iteritems():
166
            if orig_inventory.has_key(file_id):
167
                continue
168
            new_inventory[file_id] = path
169
        return new_inventory
170
1185.59.1 by Denys Duchier
removed support for applying changesets in reverse
171
    def apply_changeset(self, cset, conflict_handler=None):
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
172
        inventory_change = changeset.apply_changeset(cset,
1185.12.40 by abentley
Got even closer to standard Tree interface
173
                                                     self.this.inventory_dict,
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
174
                                                     self.this.dir,
1185.59.1 by Denys Duchier
removed support for applying changesets in reverse
175
                                                     conflict_handler)
1185.12.40 by abentley
Got even closer to standard Tree interface
176
        self.this.inventory_dict =  self.apply_inv_change(inventory_change, 
177
                                                     self.this.inventory_dict)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
178
179
    def cleanup(self):
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
180
        rmtree(self.dir)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
181
1448 by Robert Collins
revert symlinks correctly
182
1185.31.40 by John Arbash Meinel
Added osutils.mkdtemp()
183
class MergeTest(TestCase):
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
184
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
185
    def test_change_name(self):
186
        """Test renames"""
187
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
188
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
189
        builder.change_name("1", other="name2")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
190
        builder.add_file("2", "TREE_ROOT", "name3", "hello2", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
191
        builder.change_name("2", base="name4")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
192
        builder.add_file("3", "TREE_ROOT", "name5", "hello3", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
193
        builder.change_name("3", this="name6")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
194
        builder.merge()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
195
        builder.cleanup()
196
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
197
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", False)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
198
        builder.change_name("1", other="name2", this="name3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
199
        conflicts = builder.merge()
1534.10.20 by Aaron Bentley
Got all tests passing
200
        self.assertEqual(conflicts, [PathConflict('name3', 'name2', '1')])
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
201
        builder.cleanup()
1558.2.2 by Aaron Bentley
Make remerge honour interesting-ids
202
203
    def test_merge_one(self):
204
        builder = MergeBuilder()
205
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", True)
206
        builder.change_contents("1", other="text4")
207
        builder.add_file("2", "TREE_ROOT", "name2", "hello1", True)
208
        builder.change_contents("2", other="text4")
209
        builder.merge(interesting_ids=["1"])
210
        self.assertEqual(builder.this.get_file("1").read(), "text4" )
211
        self.assertEqual(builder.this.get_file("2").read(), "hello1" )
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
212
        
213
    def test_file_moves(self):
214
        """Test moves"""
215
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
216
        builder.add_dir("1", "TREE_ROOT", "dir1")
217
        builder.add_dir("2", "TREE_ROOT", "dir2")
218
        builder.add_file("3", "1", "file1", "hello1", True)
219
        builder.add_file("4", "1", "file2", "hello2", True)
220
        builder.add_file("5", "1", "file3", "hello3", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
221
        builder.change_parent("3", other="2")
222
        builder.change_parent("4", this="2")
223
        builder.change_parent("5", base="2")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
224
        builder.merge()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
225
        builder.cleanup()
226
227
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
228
        builder.add_dir("1", "TREE_ROOT", "dir1")
229
        builder.add_dir("2", "TREE_ROOT", "dir2")
230
        builder.add_dir("3", "TREE_ROOT", "dir3")
231
        builder.add_file("4", "1", "file1", "hello1", False)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
232
        builder.change_parent("4", other="2", this="3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
233
        conflicts = builder.merge()
1534.7.176 by abentley
Fixed up tests for Windows
234
        path2 = pathjoin('dir2', 'file1')
235
        path3 = pathjoin('dir3', 'file1')
1534.10.20 by Aaron Bentley
Got all tests passing
236
        self.assertEqual(conflicts, [PathConflict(path3, path2, '4')])
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
237
        builder.cleanup()
238
239
    def test_contents_merge(self):
240
        """Test merge3 merging"""
1534.7.130 by Aaron Bentley
More conflict handling, test porting
241
        self.do_contents_test(Merge3Merger)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
242
243
    def test_contents_merge2(self):
244
        """Test diff3 merging"""
1534.7.130 by Aaron Bentley
More conflict handling, test porting
245
        try:
246
            self.do_contents_test(Diff3Merger)
247
        except NoDiff3:
248
            raise TestSkipped("diff3 not available")
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
249
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
250
    def test_contents_merge3(self):
251
        """Test diff3 merging"""
252
        self.do_contents_test(WeaveMerger)
253
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
254
    def test_reprocess_weave(self):
255
        # Reprocess works on weaves, and behaves as expected
256
        builder = MergeBuilder()
257
        builder.add_file('a', 'TREE_ROOT', 'blah', 'a', False)
258
        builder.change_contents('a', this='b\nc\nd\ne\n', other='z\nc\nd\ny\n')
259
        builder.merge(WeaveMerger, reprocess=True)
260
        expected = """<<<<<<< TREE
261
b
262
=======
263
z
264
>>>>>>> MERGE-SOURCE
265
c
266
d
267
<<<<<<< TREE
268
e
269
=======
270
y
271
>>>>>>> MERGE-SOURCE
272
"""
273
        self.assertEqualDiff(builder.this.get_file("a").read(), expected)
274
275
 
276
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
277
    def do_contents_test(self, merge_factory):
278
        """Test merging with specified ContentsChange factory"""
279
        builder = self.contents_test_success(merge_factory)
280
        builder.cleanup()
281
        self.contents_test_conflicts(merge_factory)
282
283
    def contents_test_success(self, merge_factory):
284
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
285
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
286
        builder.change_contents("1", other="text4")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
287
        builder.add_file("2", "TREE_ROOT", "name3", "text2", False)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
288
        builder.change_contents("2", base="text5")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
289
        builder.add_file("3", "TREE_ROOT", "name5", "text3", True)
290
        builder.add_file("4", "TREE_ROOT", "name6", "text4", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
291
        builder.remove_file("4", base=True)
1558.6.4 by Aaron Bentley
Fixed merge-type weave
292
        builder.add_file("5", "TREE_ROOT", "name7", "a\nb\nc\nd\ne\nf\n", True)
293
        builder.change_contents("5", other="a\nz\nc\nd\ne\nf\n", 
294
                                     this="a\nb\nc\nd\ne\nz\n")
295
        builder.merge(merge_factory)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
296
        self.assertEqual(builder.this.get_file("1").read(), "text4" )
297
        self.assertEqual(builder.this.get_file("2").read(), "text2" )
1558.6.4 by Aaron Bentley
Fixed merge-type weave
298
        self.assertEqual(builder.this.get_file("5").read(), 
299
                         "a\nz\nc\nd\ne\nz\n")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
300
        self.assertIs(builder.this.is_executable("1"), True)
301
        self.assertIs(builder.this.is_executable("2"), False)
302
        self.assertIs(builder.this.is_executable("3"), True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
303
        return builder
304
305
    def contents_test_conflicts(self, merge_factory):
306
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
307
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
308
        builder.change_contents("1", other="text4", this="text3")
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
309
        builder.add_file("2", "TREE_ROOT", "name2", "text1", True)
310
        builder.change_contents("2", other="\x00", this="text3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
311
        conflicts = builder.merge(merge_factory)
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
312
        self.assertEqual(conflicts, [TextConflict('name1', file_id='1'),
313
                                     ContentsConflict('name2', file_id='2')])
314
        self.assertEqual(builder.this.get_file('2').read(), '\x00')
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
315
        builder.cleanup()
316
1185.12.34 by Aaron Bentley
Added symlink three-way tests
317
    def test_symlink_conflicts(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
318
        if sys.platform != "win32":
319
            builder = MergeBuilder()
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
320
            builder.add_symlink("2", "TREE_ROOT", "name2", "target1")
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
321
            builder.change_target("2", other="target4", base="text3")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
322
            conflicts = builder.merge()
1534.10.20 by Aaron Bentley
Got all tests passing
323
            self.assertEqual(conflicts, [ContentsConflict('name2', 
324
                                                          file_id='2')])
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
325
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
326
1185.12.34 by Aaron Bentley
Added symlink three-way tests
327
    def test_symlink_merge(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
328
        if sys.platform != "win32":
329
            builder = MergeBuilder()
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
330
            builder.add_symlink("1", "TREE_ROOT", "name1", "target1")
331
            builder.add_symlink("2", "TREE_ROOT", "name2", "target1")
332
            builder.add_symlink("3", "TREE_ROOT", "name3", "target1")
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
333
            builder.change_target("1", this="target2")
334
            builder.change_target("2", base="target2")
335
            builder.change_target("3", other="target2")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
336
            builder.merge()
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
337
            self.assertEqual(builder.this.get_symlink_target("1"), "target2")
338
            self.assertEqual(builder.this.get_symlink_target("2"), "target1")
339
            self.assertEqual(builder.this.get_symlink_target("3"), "target2")
340
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
341
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
342
    def test_no_passive_add(self):
343
        builder = MergeBuilder()
344
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
345
        builder.remove_file("1", this=True)
346
        builder.merge()
1534.7.146 by Aaron Bentley
Fixed merge so tree root is auto-preserved, not by conflict resolution
347
        builder.cleanup()
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
348
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
349
    def test_perms_merge(self):
350
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
351
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
352
        builder.change_perms("1", other=False)
353
        builder.add_file("2", "TREE_ROOT", "name2", "text2", True)
354
        builder.change_perms("2", base=False)
355
        builder.add_file("3", "TREE_ROOT", "name3", "text3", True)
356
        builder.change_perms("3", this=False)
1534.7.142 by Aaron Bentley
Fixed executability conflicts
357
        builder.add_file('4', 'TREE_ROOT', 'name4', 'text4', False)
358
        builder.change_perms('4', this=True)
359
        builder.remove_file('4', base=True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
360
        builder.merge()
361
        self.assertIs(builder.this.is_executable("1"), False)
362
        self.assertIs(builder.this.is_executable("2"), True)
363
        self.assertIs(builder.this.is_executable("3"), False)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
364
        builder.cleanup();
1092.1.25 by Robert Collins
prepare to write merge tests
365
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
366
    def test_new_suffix(self):
1534.7.130 by Aaron Bentley
More conflict handling, test porting
367
        builder = MergeBuilder()
368
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
369
        builder.change_contents("1", other="text3")
370
        builder.add_file("2", "TREE_ROOT", "name1.new", "text2", True)
371
        builder.merge()
372
        os.lstat(builder.this.id2abspath("2"))
373
        builder.cleanup()
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
374
1558.7.12 by Aaron Bentley
Additional spurious conflict test
375
    def test_spurious_conflict(self):
376
        builder = MergeBuilder()
377
        builder.add_file("1", "TREE_ROOT", "name1", "text1", False)
378
        builder.remove_file("1", other=True)
379
        builder.add_file("2", "TREE_ROOT", "name1", "text1", False, this=False, 
380
                         base=False)
381
        conflicts = builder.merge()
382
        self.assertEqual(conflicts, []) 
383
1448 by Robert Collins
revert symlinks correctly
384
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
385
class FunctionalMergeTest(TestCaseWithTransport):
1092.1.25 by Robert Collins
prepare to write merge tests
386
387
    def test_trivial_star_merge(self):
388
        """Test that merges in a star shape Just Work.""" 
1092.1.33 by Robert Collins
pull the important stuff out of cmd_branch.run to branch.copy_branch
389
        # John starts a branch
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
390
        self.build_tree(("original/", "original/file1", "original/file2"))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
391
        tree = self.make_branch_and_tree('original')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
392
        branch = tree.branch
1185.53.2 by Michael Ellerman
Add tests for bzr add --dry-run
393
        smart_add_tree(tree, ["original"])
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
394
        tree.commit("start branch.", verbose=False)
1092.1.33 by Robert Collins
pull the important stuff out of cmd_branch.run to branch.copy_branch
395
        # Mary branches it.
1092.1.34 by Robert Collins
unbreak cmd_branch now that something tests the core of it..
396
        self.build_tree(("mary/",))
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
397
        branch.bzrdir.clone("mary")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
398
        # Now John commits a change
399
        file = open("original/file1", "wt")
400
        file.write("John\n")
401
        file.close()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
402
        tree.commit("change file1")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
403
        # Mary does too
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
404
        mary_tree = WorkingTree.open('mary')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
405
        mary_branch = mary_tree.branch
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
406
        file = open("mary/file2", "wt")
407
        file.write("Mary\n")
408
        file.close()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
409
        mary_tree.commit("change file2")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
410
        # john should be able to merge with no conflicts.
1534.7.84 by Aaron Bentley
Added reprocess support, support for varying merge types
411
        merge_type = Merge3Merger
1092.1.41 by Robert Collins
merge from abently, take his fixes for merge in preference
412
        base = [None, None]
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
413
        other = ("mary", -1)
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
414
        self.assertRaises(BzrCommandError, merge, other, base, check_clean=True,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
415
                          merge_type=WeaveMerger, this_dir="original",
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
416
                          show_base=True)
417
        merge(other, base, check_clean=True, merge_type=merge_type,
418
              this_dir="original")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
419
        self.assertEqual("John\n", open("original/file1", "rt").read())
420
        self.assertEqual("Mary\n", open("original/file2", "rt").read())
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
421
 
422
    def test_conflicts(self):
423
        os.mkdir('a')
1534.4.50 by Robert Collins
Got the bzrdir api straightened out, plenty of refactoring to use it pending, but the api is up and running.
424
        wta = self.make_branch_and_tree('a')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
425
        a = wta.branch
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
426
        file('a/file', 'wb').write('contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
427
        wta.add('file')
428
        wta.commit('base revision', allow_pointless=False)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
429
        d_b = a.bzrdir.clone('b')
430
        b = d_b.open_branch()
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
431
        file('a/file', 'wb').write('other contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
432
        wta.commit('other revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
433
        file('b/file', 'wb').write('this contents contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
434
        wtb = d_b.open_workingtree()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
435
        wtb.commit('this revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
436
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b'), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
437
        self.assert_(os.path.lexists('b/file.THIS'))
438
        self.assert_(os.path.lexists('b/file.BASE'))
439
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
440
        self.assertRaises(WorkingTreeNotRevision, merge, ['a', -1], 
441
                          [None, None], this_dir='b', check_clean=False,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
442
                          merge_type=WeaveMerger)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
443
        wtb.revert([])
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
444
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b', 
1534.7.124 by Aaron Bentley
Fixed merge_core bug
445
                               check_clean=False, merge_type=WeaveMerger), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
446
        self.assert_(os.path.lexists('b/file'))
447
        self.assert_(os.path.lexists('b/file.THIS'))
448
        self.assert_(not os.path.lexists('b/file.BASE'))
449
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
450
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
451
    def test_merge_unrelated(self):
452
        """Sucessfully merges unrelated branches with no common names"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
453
        wta = self.make_branch_and_tree('a')
454
        a = wta.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
455
        file('a/a_file', 'wb').write('contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
456
        wta.add('a_file')
457
        wta.commit('a_revision', allow_pointless=False)
458
        wtb = self.make_branch_and_tree('b')
459
        b = wtb.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
460
        file('b/b_file', 'wb').write('contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
461
        wtb.add('b_file')
462
        wtb.commit('b_revision', allow_pointless=False)
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
463
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
464
        self.assert_(os.path.lexists('a/b_file'))
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
465
        self.assertEqual(wta.pending_merges(),
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
466
                         [b.last_revision()]) 
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
467
468
    def test_merge_unrelated_conflicting(self):
469
        """Sucessfully merges unrelated branches with common names"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
470
        wta = self.make_branch_and_tree('a')
471
        a = wta.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
472
        file('a/file', 'wb').write('contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
473
        wta.add('file')
474
        wta.commit('a_revision', allow_pointless=False)
475
        wtb = self.make_branch_and_tree('b')
476
        b = wtb.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
477
        file('b/file', 'wb').write('contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
478
        wtb.add('file')
479
        wtb.commit('b_revision', allow_pointless=False)
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
480
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
481
        self.assert_(os.path.lexists('a/file'))
482
        self.assert_(os.path.lexists('a/file.moved'))
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
483
        self.assertEqual(wta.pending_merges(), [b.last_revision()])
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
484
485
    def test_merge_deleted_conflicts(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
486
        wta = self.make_branch_and_tree('a')
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
487
        file('a/file', 'wb').write('contents\n')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
488
        wta.add('file')
489
        wta.commit('a_revision', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
490
        self.run_bzr('branch', 'a', 'b')
491
        os.remove('a/file')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
492
        wta.commit('removed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
493
        file('b/file', 'wb').write('changed contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
494
        wtb = WorkingTree.open('b')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
495
        wtb.commit('changed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
496
        merge(['a', -1], ['a', 1], this_dir='b')
497
        self.failIf(os.path.lexists('b/file'))
498
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
499
    def test_merge_metadata_vs_deletion(self):
500
        """Conflict deletion vs metadata change"""
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
501
        a_wt = self.make_branch_and_tree('a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
502
        file('a/file', 'wb').write('contents\n')
1508.1.15 by Robert Collins
Merge from mpool.
503
        a_wt.add('file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
504
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
505
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
506
        b_wt = WorkingTree.open('b')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
507
        os.chmod('b/file', 0755)
508
        os.remove('a/file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
509
        a_wt.commit('removed a')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
510
        self.assertEqual(a_wt.branch.revno(), 2)
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
511
        self.assertFalse(os.path.exists('a/file'))
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
512
        b_wt.commit('exec a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
513
        merge(['b', -1], ['b', 0], this_dir='a')
514
        self.assert_(os.path.exists('a/file'))
1185.31.14 by John Arbash Meinel
[merge] bzr.dev
515
1185.33.102 by Denys Duchier
two new tests suggested by abentley
516
    def test_merge_swapping_renames(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
517
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
518
        file('a/un','wb').write('UN')
519
        file('a/deux','wb').write('DEUX')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
520
        a_wt.add('un', 'un')
521
        a_wt.add('deux', 'deux')
522
        a_wt.commit('r0', rev_id='r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
523
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
524
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
525
        b_wt.rename_one('un','tmp')
526
        b_wt.rename_one('deux','un')
527
        b_wt.rename_one('tmp','deux')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
528
        b_wt.commit('r1', rev_id='r1')
529
        self.assertEqual(0, merge(['b', -1], ['b', 1], this_dir='a'))
530
        self.failUnlessExists('a/un')
531
        self.failUnless('a/deux')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
532
        self.assertFalse(os.path.exists('a/tmp'))
533
        self.assertEqual(file('a/un').read(),'DEUX')
534
        self.assertEqual(file('a/deux').read(),'UN')
535
536
    def test_merge_delete_and_add_same(self):
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
537
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
538
        file('a/file', 'wb').write('THIS')
539
        a_wt.add('file')
540
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
541
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
542
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
543
        os.remove('b/file')
544
        b_wt.commit('r1')
545
        file('b/file', 'wb').write('THAT')
546
        b_wt.add('file')
547
        b_wt.commit('r2')
548
        merge(['b', -1],['b', 1],this_dir='a')
549
        self.assert_(os.path.exists('a/file'))
550
        self.assertEqual(file('a/file').read(),'THAT')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
551
552
    def test_merge_rename_before_create(self):
553
        """rename before create
554
        
555
        This case requires that you must not do creates
556
        before move-into-place:
557
558
        $ touch foo
559
        $ bzr add foo
560
        $ bzr commit
561
        $ bzr mv foo bar
562
        $ touch foo
563
        $ bzr add foo
564
        $ bzr commit
565
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
566
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
567
        file('a/foo', 'wb').write('A/FOO')
568
        a_wt.add('foo')
569
        a_wt.commit('added foo')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
570
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
571
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
572
        b_wt.rename_one('foo', 'bar')
573
        file('b/foo', 'wb').write('B/FOO')
574
        b_wt.add('foo')
575
        b_wt.commit('moved foo to bar, added new foo')
576
        merge(['b', -1],['b', 1],this_dir='a')
577
578
    def test_merge_create_before_rename(self):
579
        """create before rename, target parents before children
580
581
        This case requires that you must not do move-into-place
582
        before creates, and that you must not do children after
583
        parents:
584
585
        $ touch foo
586
        $ bzr add foo
587
        $ bzr commit
588
        $ bzr mkdir bar
589
        $ bzr add bar
590
        $ bzr mv foo bar/foo
591
        $ bzr commit
592
        """
593
        os.mkdir('a')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
594
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
595
        file('a/foo', 'wb').write('A/FOO')
596
        a_wt.add('foo')
597
        a_wt.commit('added foo')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
598
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
599
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
600
        os.mkdir('b/bar')
601
        b_wt.add('bar')
602
        b_wt.rename_one('foo', 'bar/foo')
603
        b_wt.commit('created bar dir, moved foo into bar')
604
        merge(['b', -1],['b', 1],this_dir='a')
605
606
    def test_merge_rename_to_temp_before_delete(self):
607
        """rename to temp before delete, source children before parents
608
609
        This case requires that you must not do deletes before
610
        move-out-of-the-way, and that you must not do children
611
        after parents:
612
        
613
        $ mkdir foo
614
        $ touch foo/bar
615
        $ bzr add foo/bar
616
        $ bzr commit
617
        $ bzr mv foo/bar bar
618
        $ rmdir foo
619
        $ bzr commit
620
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
621
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
622
        os.mkdir('a/foo')
623
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
624
        a_wt.add('foo')
625
        a_wt.add('foo/bar')
626
        a_wt.commit('added foo/bar')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
627
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
628
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
629
        b_wt.rename_one('foo/bar', 'bar')
630
        os.rmdir('b/foo')
631
        b_wt.remove('foo')
632
        b_wt.commit('moved foo/bar to bar, deleted foo')
633
        merge(['b', -1],['b', 1],this_dir='a')
634
635
    def test_merge_delete_before_rename_to_temp(self):
636
        """delete before rename to temp
637
638
        This case requires that you must not do
639
        move-out-of-the-way before deletes:
640
        
641
        $ touch foo
642
        $ touch bar
643
        $ bzr add foo bar
644
        $ bzr commit
645
        $ rm foo
646
        $ bzr rm foo
647
        $ bzr mv bar foo
648
        $ bzr commit
649
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
650
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
651
        file('a/foo', 'wb').write('A/FOO')
652
        file('a/bar', 'wb').write('A/BAR')
653
        a_wt.add('foo')
654
        a_wt.add('bar')
655
        a_wt.commit('added foo and bar')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
656
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
657
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
658
        os.unlink('b/foo')
659
        b_wt.remove('foo')
660
        b_wt.rename_one('bar', 'foo')
661
        b_wt.commit('deleted foo, renamed bar to foo')
662
        merge(['b', -1],['b', 1],this_dir='a')
1185.50.30 by John Arbash Meinel
[patch] from duchier, include more tests of the merge core.
663