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