/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 apply_inv_change(self, inventory_change, orig_inventory):
128
        orig_inventory_by_path = {}
129
        for file_id, path in orig_inventory.iteritems():
130
            orig_inventory_by_path[path] = file_id
131
132
        def parent_id(file_id):
133
            try:
134
                parent_dir = os.path.dirname(orig_inventory[file_id])
135
            except:
136
                print file_id
137
                raise
138
            if parent_dir == "":
139
                return None
140
            return orig_inventory_by_path[parent_dir]
141
        
142
        def new_path(file_id):
143
            if inventory_change.has_key(file_id):
144
                return inventory_change[file_id]
145
            else:
146
                parent = parent_id(file_id)
147
                if parent is None:
148
                    return orig_inventory[file_id]
149
                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.
150
                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
151
152
        new_inventory = {}
153
        for file_id in orig_inventory.iterkeys():
154
            path = new_path(file_id)
155
            if path is None:
156
                continue
157
            new_inventory[file_id] = path
158
159
        for file_id, path in inventory_change.iteritems():
160
            if orig_inventory.has_key(file_id):
161
                continue
162
            new_inventory[file_id] = path
163
        return new_inventory
164
165
    def cleanup(self):
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
166
        rmtree(self.dir)
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
167
1448 by Robert Collins
revert symlinks correctly
168
1185.31.40 by John Arbash Meinel
Added osutils.mkdtemp()
169
class MergeTest(TestCase):
1666.1.4 by Robert Collins
* 'Metadir' is now the default disk format. This improves behaviour in
170
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
171
    def test_change_name(self):
172
        """Test renames"""
173
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
174
        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
175
        builder.change_name("1", other="name2")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
176
        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
177
        builder.change_name("2", base="name4")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
178
        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
179
        builder.change_name("3", this="name6")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
180
        builder.merge()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
181
        builder.cleanup()
182
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
183
        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
184
        builder.change_name("1", other="name2", this="name3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
185
        conflicts = builder.merge()
1534.10.20 by Aaron Bentley
Got all tests passing
186
        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
187
        builder.cleanup()
1558.2.2 by Aaron Bentley
Make remerge honour interesting-ids
188
189
    def test_merge_one(self):
190
        builder = MergeBuilder()
191
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", True)
192
        builder.change_contents("1", other="text4")
193
        builder.add_file("2", "TREE_ROOT", "name2", "hello1", True)
194
        builder.change_contents("2", other="text4")
195
        builder.merge(interesting_ids=["1"])
196
        self.assertEqual(builder.this.get_file("1").read(), "text4" )
197
        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
198
        
199
    def test_file_moves(self):
200
        """Test moves"""
201
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
202
        builder.add_dir("1", "TREE_ROOT", "dir1")
203
        builder.add_dir("2", "TREE_ROOT", "dir2")
204
        builder.add_file("3", "1", "file1", "hello1", True)
205
        builder.add_file("4", "1", "file2", "hello2", True)
206
        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
207
        builder.change_parent("3", other="2")
208
        builder.change_parent("4", this="2")
209
        builder.change_parent("5", base="2")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
210
        builder.merge()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
211
        builder.cleanup()
212
213
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
214
        builder.add_dir("1", "TREE_ROOT", "dir1")
215
        builder.add_dir("2", "TREE_ROOT", "dir2")
216
        builder.add_dir("3", "TREE_ROOT", "dir3")
217
        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
218
        builder.change_parent("4", other="2", this="3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
219
        conflicts = builder.merge()
1534.7.176 by abentley
Fixed up tests for Windows
220
        path2 = pathjoin('dir2', 'file1')
221
        path3 = pathjoin('dir3', 'file1')
1534.10.20 by Aaron Bentley
Got all tests passing
222
        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
223
        builder.cleanup()
224
225
    def test_contents_merge(self):
226
        """Test merge3 merging"""
1534.7.130 by Aaron Bentley
More conflict handling, test porting
227
        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
228
229
    def test_contents_merge2(self):
230
        """Test diff3 merging"""
1534.7.130 by Aaron Bentley
More conflict handling, test porting
231
        try:
232
            self.do_contents_test(Diff3Merger)
233
        except NoDiff3:
234
            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
235
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
236
    def test_contents_merge3(self):
237
        """Test diff3 merging"""
238
        self.do_contents_test(WeaveMerger)
239
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
240
    def test_reprocess_weave(self):
241
        # Reprocess works on weaves, and behaves as expected
242
        builder = MergeBuilder()
243
        builder.add_file('a', 'TREE_ROOT', 'blah', 'a', False)
244
        builder.change_contents('a', this='b\nc\nd\ne\n', other='z\nc\nd\ny\n')
245
        builder.merge(WeaveMerger, reprocess=True)
246
        expected = """<<<<<<< TREE
247
b
248
=======
249
z
250
>>>>>>> MERGE-SOURCE
251
c
252
d
253
<<<<<<< TREE
254
e
255
=======
256
y
257
>>>>>>> MERGE-SOURCE
258
"""
259
        self.assertEqualDiff(builder.this.get_file("a").read(), expected)
260
261
 
262
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
263
    def do_contents_test(self, merge_factory):
264
        """Test merging with specified ContentsChange factory"""
265
        builder = self.contents_test_success(merge_factory)
266
        builder.cleanup()
267
        self.contents_test_conflicts(merge_factory)
268
269
    def contents_test_success(self, merge_factory):
270
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
271
        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
272
        builder.change_contents("1", other="text4")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
273
        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
274
        builder.change_contents("2", base="text5")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
275
        builder.add_file("3", "TREE_ROOT", "name5", "text3", True)
276
        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
277
        builder.remove_file("4", base=True)
1558.6.4 by Aaron Bentley
Fixed merge-type weave
278
        builder.add_file("5", "TREE_ROOT", "name7", "a\nb\nc\nd\ne\nf\n", True)
279
        builder.change_contents("5", other="a\nz\nc\nd\ne\nf\n", 
280
                                     this="a\nb\nc\nd\ne\nz\n")
281
        builder.merge(merge_factory)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
282
        self.assertEqual(builder.this.get_file("1").read(), "text4" )
283
        self.assertEqual(builder.this.get_file("2").read(), "text2" )
1558.6.4 by Aaron Bentley
Fixed merge-type weave
284
        self.assertEqual(builder.this.get_file("5").read(), 
285
                         "a\nz\nc\nd\ne\nz\n")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
286
        self.assertIs(builder.this.is_executable("1"), True)
287
        self.assertIs(builder.this.is_executable("2"), False)
288
        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
289
        return builder
290
291
    def contents_test_conflicts(self, merge_factory):
292
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
293
        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
294
        builder.change_contents("1", other="text4", this="text3")
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
295
        builder.add_file("2", "TREE_ROOT", "name2", "text1", True)
296
        builder.change_contents("2", other="\x00", this="text3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
297
        conflicts = builder.merge(merge_factory)
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
298
        self.assertEqual(conflicts, [TextConflict('name1', file_id='1'),
299
                                     ContentsConflict('name2', file_id='2')])
300
        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
301
        builder.cleanup()
302
1185.12.34 by Aaron Bentley
Added symlink three-way tests
303
    def test_symlink_conflicts(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
304
        if sys.platform != "win32":
305
            builder = MergeBuilder()
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
306
            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
307
            builder.change_target("2", other="target4", base="text3")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
308
            conflicts = builder.merge()
1534.10.20 by Aaron Bentley
Got all tests passing
309
            self.assertEqual(conflicts, [ContentsConflict('name2', 
310
                                                          file_id='2')])
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
311
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
312
1185.12.34 by Aaron Bentley
Added symlink three-way tests
313
    def test_symlink_merge(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
314
        if sys.platform != "win32":
315
            builder = MergeBuilder()
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
316
            builder.add_symlink("1", "TREE_ROOT", "name1", "target1")
317
            builder.add_symlink("2", "TREE_ROOT", "name2", "target1")
318
            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
319
            builder.change_target("1", this="target2")
320
            builder.change_target("2", base="target2")
321
            builder.change_target("3", other="target2")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
322
            builder.merge()
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
323
            self.assertEqual(builder.this.get_symlink_target("1"), "target2")
324
            self.assertEqual(builder.this.get_symlink_target("2"), "target1")
325
            self.assertEqual(builder.this.get_symlink_target("3"), "target2")
326
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
327
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
328
    def test_no_passive_add(self):
329
        builder = MergeBuilder()
330
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
331
        builder.remove_file("1", this=True)
332
        builder.merge()
1534.7.146 by Aaron Bentley
Fixed merge so tree root is auto-preserved, not by conflict resolution
333
        builder.cleanup()
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
334
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
335
    def test_perms_merge(self):
336
        builder = MergeBuilder()
1534.7.130 by Aaron Bentley
More conflict handling, test porting
337
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
338
        builder.change_perms("1", other=False)
339
        builder.add_file("2", "TREE_ROOT", "name2", "text2", True)
340
        builder.change_perms("2", base=False)
341
        builder.add_file("3", "TREE_ROOT", "name3", "text3", True)
342
        builder.change_perms("3", this=False)
1534.7.142 by Aaron Bentley
Fixed executability conflicts
343
        builder.add_file('4', 'TREE_ROOT', 'name4', 'text4', False)
344
        builder.change_perms('4', this=True)
345
        builder.remove_file('4', base=True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
346
        builder.merge()
347
        self.assertIs(builder.this.is_executable("1"), False)
348
        self.assertIs(builder.this.is_executable("2"), True)
349
        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
350
        builder.cleanup();
1092.1.25 by Robert Collins
prepare to write merge tests
351
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
352
    def test_new_suffix(self):
1534.7.130 by Aaron Bentley
More conflict handling, test porting
353
        builder = MergeBuilder()
354
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
355
        builder.change_contents("1", other="text3")
356
        builder.add_file("2", "TREE_ROOT", "name1.new", "text2", True)
357
        builder.merge()
358
        os.lstat(builder.this.id2abspath("2"))
359
        builder.cleanup()
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
360
1558.7.12 by Aaron Bentley
Additional spurious conflict test
361
    def test_spurious_conflict(self):
362
        builder = MergeBuilder()
363
        builder.add_file("1", "TREE_ROOT", "name1", "text1", False)
364
        builder.remove_file("1", other=True)
365
        builder.add_file("2", "TREE_ROOT", "name1", "text1", False, this=False, 
366
                         base=False)
367
        conflicts = builder.merge()
368
        self.assertEqual(conflicts, []) 
369
1448 by Robert Collins
revert symlinks correctly
370
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
371
class FunctionalMergeTest(TestCaseWithTransport):
1092.1.25 by Robert Collins
prepare to write merge tests
372
373
    def test_trivial_star_merge(self):
374
        """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
375
        # John starts a branch
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
376
        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.
377
        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.
378
        branch = tree.branch
1185.53.2 by Michael Ellerman
Add tests for bzr add --dry-run
379
        smart_add_tree(tree, ["original"])
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
380
        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
381
        # Mary branches it.
1092.1.34 by Robert Collins
unbreak cmd_branch now that something tests the core of it..
382
        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.
383
        branch.bzrdir.clone("mary")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
384
        # Now John commits a change
385
        file = open("original/file1", "wt")
386
        file.write("John\n")
387
        file.close()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
388
        tree.commit("change file1")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
389
        # Mary does too
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
390
        mary_tree = WorkingTree.open('mary')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
391
        mary_branch = mary_tree.branch
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
392
        file = open("mary/file2", "wt")
393
        file.write("Mary\n")
394
        file.close()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
395
        mary_tree.commit("change file2")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
396
        # john should be able to merge with no conflicts.
1534.7.84 by Aaron Bentley
Added reprocess support, support for varying merge types
397
        merge_type = Merge3Merger
1092.1.41 by Robert Collins
merge from abently, take his fixes for merge in preference
398
        base = [None, None]
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
399
        other = ("mary", -1)
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
400
        self.assertRaises(BzrCommandError, merge, other, base, check_clean=True,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
401
                          merge_type=WeaveMerger, this_dir="original",
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
402
                          show_base=True)
403
        merge(other, base, check_clean=True, merge_type=merge_type,
404
              this_dir="original")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
405
        self.assertEqual("John\n", open("original/file1", "rt").read())
406
        self.assertEqual("Mary\n", open("original/file2", "rt").read())
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
407
 
408
    def test_conflicts(self):
409
        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.
410
        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.
411
        a = wta.branch
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
412
        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.
413
        wta.add('file')
414
        wta.commit('base revision', allow_pointless=False)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
415
        d_b = a.bzrdir.clone('b')
416
        b = d_b.open_branch()
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
417
        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.
418
        wta.commit('other revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
419
        file('b/file', 'wb').write('this contents contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
420
        wtb = d_b.open_workingtree()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
421
        wtb.commit('this revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
422
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b'), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
423
        self.assert_(os.path.lexists('b/file.THIS'))
424
        self.assert_(os.path.lexists('b/file.BASE'))
425
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
426
        self.assertRaises(WorkingTreeNotRevision, merge, ['a', -1], 
427
                          [None, None], this_dir='b', check_clean=False,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
428
                          merge_type=WeaveMerger)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
429
        wtb.revert([])
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
430
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b', 
1534.7.124 by Aaron Bentley
Fixed merge_core bug
431
                               check_clean=False, merge_type=WeaveMerger), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
432
        self.assert_(os.path.lexists('b/file'))
433
        self.assert_(os.path.lexists('b/file.THIS'))
434
        self.assert_(not os.path.lexists('b/file.BASE'))
435
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
436
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
437
    def test_merge_unrelated(self):
438
        """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.
439
        wta = self.make_branch_and_tree('a')
440
        a = wta.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
441
        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.
442
        wta.add('a_file')
443
        wta.commit('a_revision', allow_pointless=False)
444
        wtb = self.make_branch_and_tree('b')
445
        b = wtb.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
446
        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.
447
        wtb.add('b_file')
448
        wtb.commit('b_revision', allow_pointless=False)
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
449
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
450
        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.
451
        self.assertEqual(wta.pending_merges(),
1457.1.14 by Robert Collins
Move pending_merges() to WorkingTree.
452
                         [b.last_revision()]) 
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
453
454
    def test_merge_unrelated_conflicting(self):
455
        """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.
456
        wta = self.make_branch_and_tree('a')
457
        a = wta.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
458
        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.
459
        wta.add('file')
460
        wta.commit('a_revision', allow_pointless=False)
461
        wtb = self.make_branch_and_tree('b')
462
        b = wtb.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
463
        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.
464
        wtb.add('file')
465
        wtb.commit('b_revision', allow_pointless=False)
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
466
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
467
        self.assert_(os.path.lexists('a/file'))
468
        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.
469
        self.assertEqual(wta.pending_merges(), [b.last_revision()])
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
470
471
    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.
472
        wta = self.make_branch_and_tree('a')
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
473
        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.
474
        wta.add('file')
475
        wta.commit('a_revision', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
476
        self.run_bzr('branch', 'a', 'b')
477
        os.remove('a/file')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
478
        wta.commit('removed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
479
        file('b/file', 'wb').write('changed contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
480
        wtb = WorkingTree.open('b')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
481
        wtb.commit('changed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
482
        merge(['a', -1], ['a', 1], this_dir='b')
483
        self.failIf(os.path.lexists('b/file'))
484
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
485
    def test_merge_metadata_vs_deletion(self):
486
        """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.
487
        a_wt = self.make_branch_and_tree('a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
488
        file('a/file', 'wb').write('contents\n')
1508.1.15 by Robert Collins
Merge from mpool.
489
        a_wt.add('file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
490
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
491
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
492
        b_wt = WorkingTree.open('b')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
493
        os.chmod('b/file', 0755)
494
        os.remove('a/file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
495
        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.
496
        self.assertEqual(a_wt.branch.revno(), 2)
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
497
        self.assertFalse(os.path.exists('a/file'))
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
498
        b_wt.commit('exec a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
499
        merge(['b', -1], ['b', 0], this_dir='a')
500
        self.assert_(os.path.exists('a/file'))
1185.31.14 by John Arbash Meinel
[merge] bzr.dev
501
1185.33.102 by Denys Duchier
two new tests suggested by abentley
502
    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.
503
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
504
        file('a/un','wb').write('UN')
505
        file('a/deux','wb').write('DEUX')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
506
        a_wt.add('un', 'un')
507
        a_wt.add('deux', 'deux')
508
        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.
509
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
510
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
511
        b_wt.rename_one('un','tmp')
512
        b_wt.rename_one('deux','un')
513
        b_wt.rename_one('tmp','deux')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
514
        b_wt.commit('r1', rev_id='r1')
515
        self.assertEqual(0, merge(['b', -1], ['b', 1], this_dir='a'))
516
        self.failUnlessExists('a/un')
517
        self.failUnless('a/deux')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
518
        self.assertFalse(os.path.exists('a/tmp'))
519
        self.assertEqual(file('a/un').read(),'DEUX')
520
        self.assertEqual(file('a/deux').read(),'UN')
521
522
    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.
523
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
524
        file('a/file', 'wb').write('THIS')
525
        a_wt.add('file')
526
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
527
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
528
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
529
        os.remove('b/file')
530
        b_wt.commit('r1')
531
        file('b/file', 'wb').write('THAT')
532
        b_wt.add('file')
533
        b_wt.commit('r2')
534
        merge(['b', -1],['b', 1],this_dir='a')
535
        self.assert_(os.path.exists('a/file'))
536
        self.assertEqual(file('a/file').read(),'THAT')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
537
538
    def test_merge_rename_before_create(self):
539
        """rename before create
540
        
541
        This case requires that you must not do creates
542
        before move-into-place:
543
544
        $ touch foo
545
        $ bzr add foo
546
        $ bzr commit
547
        $ bzr mv foo bar
548
        $ touch foo
549
        $ bzr add foo
550
        $ bzr commit
551
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
552
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
553
        file('a/foo', 'wb').write('A/FOO')
554
        a_wt.add('foo')
555
        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.
556
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
557
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
558
        b_wt.rename_one('foo', 'bar')
559
        file('b/foo', 'wb').write('B/FOO')
560
        b_wt.add('foo')
561
        b_wt.commit('moved foo to bar, added new foo')
562
        merge(['b', -1],['b', 1],this_dir='a')
563
564
    def test_merge_create_before_rename(self):
565
        """create before rename, target parents before children
566
567
        This case requires that you must not do move-into-place
568
        before creates, and that you must not do children after
569
        parents:
570
571
        $ touch foo
572
        $ bzr add foo
573
        $ bzr commit
574
        $ bzr mkdir bar
575
        $ bzr add bar
576
        $ bzr mv foo bar/foo
577
        $ bzr commit
578
        """
579
        os.mkdir('a')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
580
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
581
        file('a/foo', 'wb').write('A/FOO')
582
        a_wt.add('foo')
583
        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.
584
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
585
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
586
        os.mkdir('b/bar')
587
        b_wt.add('bar')
588
        b_wt.rename_one('foo', 'bar/foo')
589
        b_wt.commit('created bar dir, moved foo into bar')
590
        merge(['b', -1],['b', 1],this_dir='a')
591
592
    def test_merge_rename_to_temp_before_delete(self):
593
        """rename to temp before delete, source children before parents
594
595
        This case requires that you must not do deletes before
596
        move-out-of-the-way, and that you must not do children
597
        after parents:
598
        
599
        $ mkdir foo
600
        $ touch foo/bar
601
        $ bzr add foo/bar
602
        $ bzr commit
603
        $ bzr mv foo/bar bar
604
        $ rmdir foo
605
        $ bzr commit
606
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
607
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
608
        os.mkdir('a/foo')
609
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
610
        a_wt.add('foo')
611
        a_wt.add('foo/bar')
612
        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.
613
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
614
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
615
        b_wt.rename_one('foo/bar', 'bar')
616
        os.rmdir('b/foo')
617
        b_wt.remove('foo')
618
        b_wt.commit('moved foo/bar to bar, deleted foo')
619
        merge(['b', -1],['b', 1],this_dir='a')
620
621
    def test_merge_delete_before_rename_to_temp(self):
622
        """delete before rename to temp
623
624
        This case requires that you must not do
625
        move-out-of-the-way before deletes:
626
        
627
        $ touch foo
628
        $ touch bar
629
        $ bzr add foo bar
630
        $ bzr commit
631
        $ rm foo
632
        $ bzr rm foo
633
        $ bzr mv bar foo
634
        $ bzr commit
635
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
636
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
637
        file('a/foo', 'wb').write('A/FOO')
638
        file('a/bar', 'wb').write('A/BAR')
639
        a_wt.add('foo')
640
        a_wt.add('bar')
641
        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.
642
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
643
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
644
        os.unlink('b/foo')
645
        b_wt.remove('foo')
646
        b_wt.rename_one('bar', 'foo')
647
        b_wt.commit('deleted foo, renamed bar to foo')
648
        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.
649