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