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