/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
import bzrlib.inventory as inventory
1534.7.140 by Aaron Bentley
Moved the merge stuff into merge.py
12
from bzrlib.merge import Merge3Merger, Diff3Merger, WeaveMerger
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
13
from bzrlib.osutils import (file_kind, getcwd, mkdtemp, pathjoin, rename, rmtree,
1692.7.6 by Martin Pool
[patch] force deletion of trees containing readonly files (alexander)
14
                            sha_file, 
15
                            )
1534.7.140 by Aaron Bentley
Moved the merge stuff into merge.py
16
from bzrlib.transform import TreeTransform
1534.7.130 by Aaron Bentley
More conflict handling, test porting
17
from bzrlib.tests import TestCaseWithTransport, TestCase, TestSkipped
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
18
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
19
1185.1.41 by Robert Collins
massive patch from Alexander Belchenko - many PEP8 fixes, removes unused function uuid
20
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
21
class MergeBuilder(object):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
22
    def __init__(self, dir=None):
23
        self.dir = mkdtemp(prefix="merge-test", dir=dir)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
24
        def wt(name):
25
           path = pathjoin(self.dir, name)
26
           os.mkdir(path)
1559.1.1 by Robert Collins
Merge in InterRepository API support.
27
           wt = bzrlib.bzrdir.BzrDir.create_standalone_workingtree(path)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
28
           tt = TreeTransform(wt)
29
           return wt, tt
30
        self.base, self.base_tt = wt('base') 
31
        self.this, self.this_tt = wt('this')
32
        self.other, self.other_tt = wt('other')
1185.50.33 by John Arbash Meinel
Whitespace cleanups.
33
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
34
    def get_cset_path(self, parent, name):
35
        if name is None:
36
            assert (parent is None)
37
            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 \
38
        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
39
1558.7.12 by Aaron Bentley
Additional spurious conflict test
40
    def add_file(self, id, parent, name, contents, executable, this=True, 
41
                 base=True, other=True):
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
42
        def new_file(tt):
1534.7.181 by Aaron Bentley
Renamed a bunch of functions
43
            parent_id = tt.trans_id_file_id(parent)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
44
            tt.new_file(name, parent_id, contents, id, executable)
1558.7.12 by Aaron Bentley
Additional spurious conflict test
45
        for option, tt in self.selected_transforms(this, base, other):
46
            if option is True:
47
                new_file(tt)
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
48
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
49
    def merge(self, merge_type=Merge3Merger, interesting_ids=None, **kwargs):
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
50
        self.base_tt.apply()
51
        self.base.commit('base commit')
52
        for tt, wt in ((self.this_tt, self.this), (self.other_tt, self.other)):
1908.6.1 by Robert Collins
Change all callers of set_last_revision to use set_parent_trees.
53
            # why does this not do wt.pull() ?
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
54
            wt.branch.pull(self.base.branch)
1908.6.3 by Robert Collins
Tidy up the last_revision_id and add_pending_merge conversion to use cleaner apis.
55
            wt.set_parent_ids([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):
1963.2.1 by Robey Pointer
remove usage of has_key()
143
            if fild_id in inventory_change:
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
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():
1963.2.1 by Robey Pointer
remove usage of has_key()
160
            if file_id in orig_inventory:
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
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
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
169
class MergeTest(TestCaseWithTransport):
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"""
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
173
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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()
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
182
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
190
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
191
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", True)
1558.2.2 by Aaron Bentley
Make remerge honour interesting-ids
192
        builder.change_contents("1", other="text4")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
193
        builder.add_file("2", "TREE_ROOT", "name2", "hello1", True)
1558.2.2 by Aaron Bentley
Make remerge honour interesting-ids
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"""
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
201
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
202
        builder.add_dir("1", "TREE_ROOT", "dir1")
203
        builder.add_dir("2", "TREE_ROOT", "dir2")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
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
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
213
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
214
        builder.add_dir("1", "TREE_ROOT", "dir1")
215
        builder.add_dir("2", "TREE_ROOT", "dir2")
216
        builder.add_dir("3", "TREE_ROOT", "dir3")
1534.7.130 by Aaron Bentley
More conflict handling, test porting
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
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
242
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
243
        builder.add_file('a', 'TREE_ROOT', 'blah', 'a', False)
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
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):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
270
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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)
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
278
        builder.add_file("5", "TREE_ROOT", "name7", "a\nb\nc\nd\ne\nf\n", True)
1558.6.4 by Aaron Bentley
Fixed merge-type weave
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):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
292
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
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")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
295
        builder.add_file("2", "TREE_ROOT", "name2", "text1", True)
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
296
        builder.change_contents("2", other="\x00", this="text3")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
297
        builder.add_file("3", "TREE_ROOT", "name3", "text5", False)
1534.10.35 by Aaron Bentley
Merge handles contents + executable + deletion conflict
298
        builder.change_perms("3", this=True)
299
        builder.change_contents('3', this='moretext')
300
        builder.remove_file('3', other=True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
301
        conflicts = builder.merge(merge_factory)
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
302
        self.assertEqual(conflicts, [TextConflict('name1', file_id='1'),
1534.10.35 by Aaron Bentley
Merge handles contents + executable + deletion conflict
303
                                     ContentsConflict('name2', file_id='2'),
304
                                     ContentsConflict('name3', file_id='3')])
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
305
        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
306
        builder.cleanup()
307
1185.12.34 by Aaron Bentley
Added symlink three-way tests
308
    def test_symlink_conflicts(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
309
        if sys.platform != "win32":
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
310
            builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
311
            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
312
            builder.change_target("2", other="target4", base="text3")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
313
            conflicts = builder.merge()
1534.10.20 by Aaron Bentley
Got all tests passing
314
            self.assertEqual(conflicts, [ContentsConflict('name2', 
315
                                                          file_id='2')])
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
316
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
317
1185.12.34 by Aaron Bentley
Added symlink three-way tests
318
    def test_symlink_merge(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
319
        if sys.platform != "win32":
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
320
            builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
321
            builder.add_symlink("1", "TREE_ROOT", "name1", "target1")
322
            builder.add_symlink("2", "TREE_ROOT", "name2", "target1")
323
            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
324
            builder.change_target("1", this="target2")
325
            builder.change_target("2", base="target2")
326
            builder.change_target("3", other="target2")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
327
            builder.merge()
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
328
            self.assertEqual(builder.this.get_symlink_target("1"), "target2")
329
            self.assertEqual(builder.this.get_symlink_target("2"), "target1")
330
            self.assertEqual(builder.this.get_symlink_target("3"), "target2")
331
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
332
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
333
    def test_no_passive_add(self):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
334
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
335
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
336
        builder.remove_file("1", this=True)
337
        builder.merge()
1534.7.146 by Aaron Bentley
Fixed merge so tree root is auto-preserved, not by conflict resolution
338
        builder.cleanup()
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
339
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
340
    def test_perms_merge(self):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
341
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
342
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
343
        builder.change_perms("1", other=False)
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
344
        builder.add_file("2", "TREE_ROOT", "name2", "text2", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
345
        builder.change_perms("2", base=False)
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
346
        builder.add_file("3", "TREE_ROOT", "name3", "text3", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
347
        builder.change_perms("3", this=False)
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
348
        builder.add_file('4', 'TREE_ROOT', 'name4', 'text4', False)
1534.7.142 by Aaron Bentley
Fixed executability conflicts
349
        builder.change_perms('4', this=True)
350
        builder.remove_file('4', base=True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
351
        builder.merge()
352
        self.assertIs(builder.this.is_executable("1"), False)
353
        self.assertIs(builder.this.is_executable("2"), True)
354
        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
355
        builder.cleanup();
1092.1.25 by Robert Collins
prepare to write merge tests
356
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
357
    def test_new_suffix(self):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
358
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
359
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
360
        builder.change_contents("1", other="text3")
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
361
        builder.add_file("2", "TREE_ROOT", "name1.new", "text2", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
362
        builder.merge()
363
        os.lstat(builder.this.id2abspath("2"))
364
        builder.cleanup()
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
365
1558.7.12 by Aaron Bentley
Additional spurious conflict test
366
    def test_spurious_conflict(self):
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
367
        builder = MergeBuilder(getcwd())
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
368
        builder.add_file("1", "TREE_ROOT", "name1", "text1", False)
1558.7.12 by Aaron Bentley
Additional spurious conflict test
369
        builder.remove_file("1", other=True)
1907.1.1 by Aaron Bentley
Unshelved all changes except those related to removing RootEntry
370
        builder.add_file("2", "TREE_ROOT", "name1", "text1", False, this=False, 
371
                         base=False)
1558.7.12 by Aaron Bentley
Additional spurious conflict test
372
        conflicts = builder.merge()
373
        self.assertEqual(conflicts, []) 
374
1448 by Robert Collins
revert symlinks correctly
375
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
376
class FunctionalMergeTest(TestCaseWithTransport):
1092.1.25 by Robert Collins
prepare to write merge tests
377
378
    def test_trivial_star_merge(self):
379
        """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
380
        # John starts a branch
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
381
        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.
382
        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.
383
        branch = tree.branch
1185.53.2 by Michael Ellerman
Add tests for bzr add --dry-run
384
        smart_add_tree(tree, ["original"])
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
385
        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
386
        # Mary branches it.
1092.1.34 by Robert Collins
unbreak cmd_branch now that something tests the core of it..
387
        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.
388
        branch.bzrdir.clone("mary")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
389
        # Now John commits a change
390
        file = open("original/file1", "wt")
391
        file.write("John\n")
392
        file.close()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
393
        tree.commit("change file1")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
394
        # Mary does too
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
395
        mary_tree = WorkingTree.open('mary')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
396
        mary_branch = mary_tree.branch
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
397
        file = open("mary/file2", "wt")
398
        file.write("Mary\n")
399
        file.close()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
400
        mary_tree.commit("change file2")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
401
        # john should be able to merge with no conflicts.
1534.7.84 by Aaron Bentley
Added reprocess support, support for varying merge types
402
        merge_type = Merge3Merger
1092.1.41 by Robert Collins
merge from abently, take his fixes for merge in preference
403
        base = [None, None]
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
404
        other = ("mary", -1)
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
405
        self.assertRaises(BzrCommandError, merge, other, base, check_clean=True,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
406
                          merge_type=WeaveMerger, this_dir="original",
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
407
                          show_base=True)
408
        merge(other, base, check_clean=True, merge_type=merge_type,
409
              this_dir="original")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
410
        self.assertEqual("John\n", open("original/file1", "rt").read())
411
        self.assertEqual("Mary\n", open("original/file2", "rt").read())
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
412
 
413
    def test_conflicts(self):
414
        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.
415
        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.
416
        a = wta.branch
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
417
        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.
418
        wta.add('file')
419
        wta.commit('base revision', allow_pointless=False)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
420
        d_b = a.bzrdir.clone('b')
421
        b = d_b.open_branch()
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
422
        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.
423
        wta.commit('other revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
424
        file('b/file', 'wb').write('this contents contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
425
        wtb = d_b.open_workingtree()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
426
        wtb.commit('this revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
427
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b'), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
428
        self.assert_(os.path.lexists('b/file.THIS'))
429
        self.assert_(os.path.lexists('b/file.BASE'))
430
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
431
        self.assertRaises(WorkingTreeNotRevision, merge, ['a', -1], 
432
                          [None, None], this_dir='b', check_clean=False,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
433
                          merge_type=WeaveMerger)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
434
        wtb.revert([])
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
435
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b', 
1534.7.124 by Aaron Bentley
Fixed merge_core bug
436
                               check_clean=False, merge_type=WeaveMerger), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
437
        self.assert_(os.path.lexists('b/file'))
438
        self.assert_(os.path.lexists('b/file.THIS'))
439
        self.assert_(not os.path.lexists('b/file.BASE'))
440
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
441
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
442
    def test_merge_unrelated(self):
443
        """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.
444
        wta = self.make_branch_and_tree('a')
445
        a = wta.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
446
        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.
447
        wta.add('a_file')
448
        wta.commit('a_revision', allow_pointless=False)
449
        wtb = self.make_branch_and_tree('b')
450
        b = wtb.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
451
        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.
452
        wtb.add('b_file')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
453
        b_rev = wtb.commit('b_revision', allow_pointless=False)
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
454
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
455
        self.assert_(os.path.lexists('a/b_file'))
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
456
        self.assertEqual([b_rev], wta.get_parent_ids()[1:])
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
457
458
    def test_merge_unrelated_conflicting(self):
459
        """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.
460
        wta = self.make_branch_and_tree('a')
461
        a = wta.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
462
        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.
463
        wta.add('file')
464
        wta.commit('a_revision', allow_pointless=False)
465
        wtb = self.make_branch_and_tree('b')
466
        b = wtb.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
467
        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.
468
        wtb.add('file')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
469
        b_rev = wtb.commit('b_revision', allow_pointless=False)
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
470
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
471
        self.assert_(os.path.lexists('a/file'))
472
        self.assert_(os.path.lexists('a/file.moved'))
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
473
        self.assertEqual([b_rev], wta.get_parent_ids()[1:])
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
474
475
    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.
476
        wta = self.make_branch_and_tree('a')
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
477
        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.
478
        wta.add('file')
479
        wta.commit('a_revision', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
480
        self.run_bzr('branch', 'a', 'b')
481
        os.remove('a/file')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
482
        wta.commit('removed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
483
        file('b/file', 'wb').write('changed contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
484
        wtb = WorkingTree.open('b')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
485
        wtb.commit('changed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
486
        merge(['a', -1], ['a', 1], this_dir='b')
487
        self.failIf(os.path.lexists('b/file'))
488
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
489
    def test_merge_metadata_vs_deletion(self):
490
        """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.
491
        a_wt = self.make_branch_and_tree('a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
492
        file('a/file', 'wb').write('contents\n')
1508.1.15 by Robert Collins
Merge from mpool.
493
        a_wt.add('file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
494
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
495
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
496
        b_wt = WorkingTree.open('b')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
497
        os.chmod('b/file', 0755)
498
        os.remove('a/file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
499
        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.
500
        self.assertEqual(a_wt.branch.revno(), 2)
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
501
        self.assertFalse(os.path.exists('a/file'))
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
502
        b_wt.commit('exec a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
503
        merge(['b', -1], ['b', 0], this_dir='a')
504
        self.assert_(os.path.exists('a/file'))
1185.31.14 by John Arbash Meinel
[merge] bzr.dev
505
1185.33.102 by Denys Duchier
two new tests suggested by abentley
506
    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.
507
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
508
        file('a/un','wb').write('UN')
509
        file('a/deux','wb').write('DEUX')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
510
        a_wt.add('un', 'un')
511
        a_wt.add('deux', 'deux')
512
        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.
513
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
514
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
515
        b_wt.rename_one('un','tmp')
516
        b_wt.rename_one('deux','un')
517
        b_wt.rename_one('tmp','deux')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
518
        b_wt.commit('r1', rev_id='r1')
519
        self.assertEqual(0, merge(['b', -1], ['b', 1], this_dir='a'))
520
        self.failUnlessExists('a/un')
521
        self.failUnless('a/deux')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
522
        self.assertFalse(os.path.exists('a/tmp'))
523
        self.assertEqual(file('a/un').read(),'DEUX')
524
        self.assertEqual(file('a/deux').read(),'UN')
525
526
    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.
527
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
528
        file('a/file', 'wb').write('THIS')
529
        a_wt.add('file')
530
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
531
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
532
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
533
        os.remove('b/file')
534
        b_wt.commit('r1')
535
        file('b/file', 'wb').write('THAT')
536
        b_wt.add('file')
537
        b_wt.commit('r2')
538
        merge(['b', -1],['b', 1],this_dir='a')
539
        self.assert_(os.path.exists('a/file'))
540
        self.assertEqual(file('a/file').read(),'THAT')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
541
542
    def test_merge_rename_before_create(self):
543
        """rename before create
544
        
545
        This case requires that you must not do creates
546
        before move-into-place:
547
548
        $ touch foo
549
        $ bzr add foo
550
        $ bzr commit
551
        $ bzr mv foo bar
552
        $ touch foo
553
        $ bzr add foo
554
        $ bzr commit
555
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
556
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
557
        file('a/foo', 'wb').write('A/FOO')
558
        a_wt.add('foo')
559
        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.
560
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
561
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
562
        b_wt.rename_one('foo', 'bar')
563
        file('b/foo', 'wb').write('B/FOO')
564
        b_wt.add('foo')
565
        b_wt.commit('moved foo to bar, added new foo')
566
        merge(['b', -1],['b', 1],this_dir='a')
567
568
    def test_merge_create_before_rename(self):
569
        """create before rename, target parents before children
570
571
        This case requires that you must not do move-into-place
572
        before creates, and that you must not do children after
573
        parents:
574
575
        $ touch foo
576
        $ bzr add foo
577
        $ bzr commit
578
        $ bzr mkdir bar
579
        $ bzr add bar
580
        $ bzr mv foo bar/foo
581
        $ bzr commit
582
        """
583
        os.mkdir('a')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
584
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
585
        file('a/foo', 'wb').write('A/FOO')
586
        a_wt.add('foo')
587
        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.
588
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
589
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
590
        os.mkdir('b/bar')
591
        b_wt.add('bar')
592
        b_wt.rename_one('foo', 'bar/foo')
593
        b_wt.commit('created bar dir, moved foo into bar')
594
        merge(['b', -1],['b', 1],this_dir='a')
595
596
    def test_merge_rename_to_temp_before_delete(self):
597
        """rename to temp before delete, source children before parents
598
599
        This case requires that you must not do deletes before
600
        move-out-of-the-way, and that you must not do children
601
        after parents:
602
        
603
        $ mkdir foo
604
        $ touch foo/bar
605
        $ bzr add foo/bar
606
        $ bzr commit
607
        $ bzr mv foo/bar bar
608
        $ rmdir foo
609
        $ bzr commit
610
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
611
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
612
        os.mkdir('a/foo')
613
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
614
        a_wt.add('foo')
615
        a_wt.add('foo/bar')
616
        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.
617
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
618
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
619
        b_wt.rename_one('foo/bar', 'bar')
620
        os.rmdir('b/foo')
621
        b_wt.remove('foo')
622
        b_wt.commit('moved foo/bar to bar, deleted foo')
623
        merge(['b', -1],['b', 1],this_dir='a')
624
625
    def test_merge_delete_before_rename_to_temp(self):
626
        """delete before rename to temp
627
628
        This case requires that you must not do
629
        move-out-of-the-way before deletes:
630
        
631
        $ touch foo
632
        $ touch bar
633
        $ bzr add foo bar
634
        $ bzr commit
635
        $ rm foo
636
        $ bzr rm foo
637
        $ bzr mv bar foo
638
        $ bzr commit
639
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
640
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
641
        file('a/foo', 'wb').write('A/FOO')
642
        file('a/bar', 'wb').write('A/BAR')
643
        a_wt.add('foo')
644
        a_wt.add('bar')
645
        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.
646
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
647
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
648
        os.unlink('b/foo')
649
        b_wt.remove('foo')
650
        b_wt.rename_one('bar', 'foo')
651
        b_wt.commit('deleted foo, renamed bar to foo')
652
        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.
653