/brz/remove-bazaar

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