/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"""
1534.7.130 by Aaron Bentley
More conflict handling, test porting
262
        try:
263
            self.do_contents_test(Diff3Merger)
264
        except NoDiff3:
265
            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
266
1534.7.136 by Aaron Bentley
Got WeaveMerger under test
267
    def test_contents_merge3(self):
268
        """Test diff3 merging"""
269
        self.do_contents_test(WeaveMerger)
270
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
271
    def test_reprocess_weave(self):
272
        # 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
273
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
274
        builder.add_file('a', builder.tree_root, 'blah', 'a', False)
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
275
        builder.change_contents('a', this='b\nc\nd\ne\n', other='z\nc\nd\ny\n')
276
        builder.merge(WeaveMerger, reprocess=True)
277
        expected = """<<<<<<< TREE
278
b
279
=======
280
z
281
>>>>>>> MERGE-SOURCE
282
c
283
d
284
<<<<<<< TREE
285
e
286
=======
287
y
288
>>>>>>> MERGE-SOURCE
289
"""
290
        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
291
        builder.cleanup()
1551.6.8 by Aaron Bentley
Implemented reprocess for weave
292
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
293
    def do_contents_test(self, merge_factory):
294
        """Test merging with specified ContentsChange factory"""
295
        builder = self.contents_test_success(merge_factory)
296
        builder.cleanup()
297
        self.contents_test_conflicts(merge_factory)
298
299
    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
300
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
301
        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
302
        builder.change_contents("1", other="text4")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
303
        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
304
        builder.change_contents("2", base="text5")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
305
        builder.add_file("3", builder.tree_root, "name5", "text3", True)
306
        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
307
        builder.remove_file("4", base=True)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
308
        builder.add_file("5", builder.tree_root, "name7", "a\nb\nc\nd\ne\nf\n",
309
                         True)
1558.6.4 by Aaron Bentley
Fixed merge-type weave
310
        builder.change_contents("5", other="a\nz\nc\nd\ne\nf\n", 
311
                                     this="a\nb\nc\nd\ne\nz\n")
1551.8.39 by Aaron Bentley
Fix diff3 conflict-reporting bug
312
        conflicts = builder.merge(merge_factory)
313
        try:
314
            self.assertEqual([], conflicts)
1551.8.40 by Aaron Bentley
Update test case style
315
            self.assertEqual("text4", builder.this.get_file("1").read())
316
            self.assertEqual("text2", builder.this.get_file("2").read())
317
            self.assertEqual("a\nz\nc\nd\ne\nz\n", 
318
                             builder.this.get_file("5").read())
319
            self.assertTrue(builder.this.is_executable("1"))
320
            self.assertFalse(builder.this.is_executable("2"))
321
            self.assertTrue(builder.this.is_executable("3"))
1551.8.39 by Aaron Bentley
Fix diff3 conflict-reporting bug
322
        except:
323
            builder.unlock()
324
            raise
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
325
        return builder
326
327
    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
328
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
329
        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
330
        builder.change_contents("1", other="text4", this="text3")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
331
        builder.add_file("2", builder.tree_root, "name2", "text1", True)
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
332
        builder.change_contents("2", other="\x00", this="text3")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
333
        builder.add_file("3", builder.tree_root, "name3", "text5", False)
1534.10.35 by Aaron Bentley
Merge handles contents + executable + deletion conflict
334
        builder.change_perms("3", this=True)
335
        builder.change_contents('3', this='moretext')
336
        builder.remove_file('3', other=True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
337
        conflicts = builder.merge(merge_factory)
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
338
        self.assertEqual(conflicts, [TextConflict('name1', file_id='1'),
1534.10.35 by Aaron Bentley
Merge handles contents + executable + deletion conflict
339
                                     ContentsConflict('name2', file_id='2'),
340
                                     ContentsConflict('name3', file_id='3')])
1558.15.3 by Aaron Bentley
Handle binary files for diff3 merges
341
        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
342
        builder.cleanup()
343
1185.12.34 by Aaron Bentley
Added symlink three-way tests
344
    def test_symlink_conflicts(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
345
        if sys.platform != "win32":
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
346
            builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
347
            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
348
            builder.change_target("2", other="target4", base="text3")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
349
            conflicts = builder.merge()
1534.10.20 by Aaron Bentley
Got all tests passing
350
            self.assertEqual(conflicts, [ContentsConflict('name2', 
351
                                                          file_id='2')])
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
352
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
353
1185.12.34 by Aaron Bentley
Added symlink three-way tests
354
    def test_symlink_merge(self):
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
355
        if sys.platform != "win32":
1711.7.21 by John Arbash Meinel
Run the merge_core tests underneath the current test directory, rather than TEMP
356
            builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
357
            builder.add_symlink("1", builder.tree_root, "name1", "target1")
358
            builder.add_symlink("2", builder.tree_root, "name2", "target1")
359
            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
360
            builder.change_target("1", this="target2")
361
            builder.change_target("2", base="target2")
362
            builder.change_target("3", other="target2")
1534.7.129 by Aaron Bentley
Converted test cases to Tree Transform
363
            builder.merge()
1185.38.9 by John Arbash Meinel
[patch] Alexander Belchenko patch #9, skip stat tests for win32
364
            self.assertEqual(builder.this.get_symlink_target("1"), "target2")
365
            self.assertEqual(builder.this.get_symlink_target("2"), "target1")
366
            self.assertEqual(builder.this.get_symlink_target("3"), "target2")
367
            builder.cleanup()
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
368
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
369
    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
370
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
371
        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
372
        builder.remove_file("1", this=True)
373
        builder.merge()
1534.7.146 by Aaron Bentley
Fixed merge so tree root is auto-preserved, not by conflict resolution
374
        builder.cleanup()
1534.7.143 by Aaron Bentley
Prevented get_trans_id from automatically versioning file ids
375
1092.1.24 by Robert Collins
move merge_core tests into the selftest package. Also reduce double-run of those tests
376
    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
377
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
378
        builder.add_file("1", builder.tree_root, "name1", "text1", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
379
        builder.change_perms("1", other=False)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
380
        builder.add_file("2", builder.tree_root, "name2", "text2", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
381
        builder.change_perms("2", base=False)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
382
        builder.add_file("3", builder.tree_root, "name3", "text3", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
383
        builder.change_perms("3", this=False)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
384
        builder.add_file('4', builder.tree_root, 'name4', 'text4', False)
1534.7.142 by Aaron Bentley
Fixed executability conflicts
385
        builder.change_perms('4', this=True)
386
        builder.remove_file('4', base=True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
387
        builder.merge()
388
        self.assertIs(builder.this.is_executable("1"), False)
389
        self.assertIs(builder.this.is_executable("2"), True)
390
        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
391
        builder.cleanup();
1092.1.25 by Robert Collins
prepare to write merge tests
392
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
393
    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
394
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
395
        builder.add_file("1", builder.tree_root, "name1", "text1", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
396
        builder.change_contents("1", other="text3")
1731.1.33 by Aaron Bentley
Revert no-special-root changes
397
        builder.add_file("2", builder.tree_root, "name1.new", "text2", True)
1534.7.130 by Aaron Bentley
More conflict handling, test porting
398
        builder.merge()
399
        os.lstat(builder.this.id2abspath("2"))
400
        builder.cleanup()
1185.50.50 by John Arbash Meinel
[patch] Aaron Bentley: Merge deletes foo.new
401
1558.7.12 by Aaron Bentley
Additional spurious conflict test
402
    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
403
        builder = MergeBuilder(getcwd())
1731.1.33 by Aaron Bentley
Revert no-special-root changes
404
        builder.add_file("1", builder.tree_root, "name1", "text1", False)
1558.7.12 by Aaron Bentley
Additional spurious conflict test
405
        builder.remove_file("1", other=True)
1731.1.33 by Aaron Bentley
Revert no-special-root changes
406
        builder.add_file("2", builder.tree_root, "name1", "text1", False, 
407
                         this=False, base=False)
1558.7.12 by Aaron Bentley
Additional spurious conflict test
408
        conflicts = builder.merge()
409
        self.assertEqual(conflicts, []) 
1997.1.3 by Robert Collins
All WorkingTree methods which write to the tree, but not to the branch
410
        builder.cleanup()
1558.7.12 by Aaron Bentley
Additional spurious conflict test
411
1448 by Robert Collins
revert symlinks correctly
412
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
413
class FunctionalMergeTest(TestCaseWithTransport):
1092.1.25 by Robert Collins
prepare to write merge tests
414
415
    def test_trivial_star_merge(self):
416
        """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
417
        # John starts a branch
1092.1.26 by Robert Collins
start writing star-topology test, realise we need smart-add change
418
        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.
419
        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.
420
        branch = tree.branch
1185.53.2 by Michael Ellerman
Add tests for bzr add --dry-run
421
        smart_add_tree(tree, ["original"])
1508.1.10 by Robert Collins
bzrlib.add.smart_add_branch is now smart_add_tree. (Robert Collins)
422
        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
423
        # Mary branches it.
1092.1.34 by Robert Collins
unbreak cmd_branch now that something tests the core of it..
424
        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.
425
        branch.bzrdir.clone("mary")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
426
        # Now John commits a change
427
        file = open("original/file1", "wt")
428
        file.write("John\n")
429
        file.close()
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
430
        tree.commit("change file1")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
431
        # Mary does too
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
432
        mary_tree = WorkingTree.open('mary')
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
433
        mary_branch = mary_tree.branch
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
434
        file = open("mary/file2", "wt")
435
        file.write("Mary\n")
436
        file.close()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
437
        mary_tree.commit("change file2")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
438
        # john should be able to merge with no conflicts.
1534.7.84 by Aaron Bentley
Added reprocess support, support for varying merge types
439
        merge_type = Merge3Merger
1092.1.41 by Robert Collins
merge from abently, take his fixes for merge in preference
440
        base = [None, None]
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
441
        other = ("mary", -1)
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
442
        self.assertRaises(BzrCommandError, merge, other, base, check_clean=True,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
443
                          merge_type=WeaveMerger, this_dir="original",
1185.12.87 by Aaron Bentley
Updated NEWS, error out if --show-base supplied and unsupported
444
                          show_base=True)
445
        merge(other, base, check_clean=True, merge_type=merge_type,
446
              this_dir="original")
1092.1.38 by Robert Collins
make a default merge choose a sane base with branch.common_ancestor
447
        self.assertEqual("John\n", open("original/file1", "rt").read())
448
        self.assertEqual("Mary\n", open("original/file2", "rt").read())
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
449
 
450
    def test_conflicts(self):
451
        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.
452
        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.
453
        a = wta.branch
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
454
        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.
455
        wta.add('file')
456
        wta.commit('base revision', allow_pointless=False)
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
457
        d_b = a.bzrdir.clone('b')
458
        b = d_b.open_branch()
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
459
        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.
460
        wta.commit('other revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
461
        file('b/file', 'wb').write('this contents contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
462
        wtb = d_b.open_workingtree()
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
463
        wtb.commit('this revision', allow_pointless=False)
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
464
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b'), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
465
        self.assert_(os.path.lexists('b/file.THIS'))
466
        self.assert_(os.path.lexists('b/file.BASE'))
467
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
468
        self.assertRaises(WorkingTreeNotRevision, merge, ['a', -1], 
469
                          [None, None], this_dir='b', check_clean=False,
1534.7.124 by Aaron Bentley
Fixed merge_core bug
470
                          merge_type=WeaveMerger)
1534.4.36 by Robert Collins
Finish deprecating Branch.working_tree()
471
        wtb.revert([])
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
472
        self.assertEqual(merge(['a', -1], [None, None], this_dir='b', 
1534.7.124 by Aaron Bentley
Fixed merge_core bug
473
                               check_clean=False, merge_type=WeaveMerger), 1)
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
474
        self.assert_(os.path.lexists('b/file'))
475
        self.assert_(os.path.lexists('b/file.THIS'))
476
        self.assert_(not os.path.lexists('b/file.BASE'))
477
        self.assert_(os.path.lexists('b/file.OTHER'))
1185.12.85 by Aaron Bentley
Added conflict handling for weave merges
478
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
479
    def test_merge_unrelated(self):
480
        """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.
481
        wta = self.make_branch_and_tree('a')
482
        a = wta.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
483
        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.
484
        wta.add('a_file')
485
        wta.commit('a_revision', allow_pointless=False)
486
        wtb = self.make_branch_and_tree('b')
487
        b = wtb.branch
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
488
        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.
489
        wtb.add('b_file')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
490
        b_rev = wtb.commit('b_revision', allow_pointless=False)
1185.12.98 by Aaron Bentley
Support for forcing merges of unrelated trees
491
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
492
        self.assert_(os.path.lexists('a/b_file'))
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
493
        self.assertEqual([b_rev], wta.get_parent_ids()[1:])
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
494
495
    def test_merge_unrelated_conflicting(self):
496
        """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.
497
        wta = self.make_branch_and_tree('a')
498
        a = wta.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
499
        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.
500
        wta.add('file')
501
        wta.commit('a_revision', allow_pointless=False)
502
        wtb = self.make_branch_and_tree('b')
503
        b = wtb.branch
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
504
        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.
505
        wtb.add('file')
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
506
        b_rev = wtb.commit('b_revision', allow_pointless=False)
1185.12.99 by Aaron Bentley
Handled conflicts with versioned files better
507
        merge(['b', -1], ['b', 0], this_dir='a')
1185.16.145 by Martin Pool
Remove all assert statements from test cases.
508
        self.assert_(os.path.lexists('a/file'))
509
        self.assert_(os.path.lexists('a/file.moved'))
1908.6.11 by Robert Collins
Remove usage of tree.pending_merges().
510
        self.assertEqual([b_rev], wta.get_parent_ids()[1:])
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
511
512
    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.
513
        wta = self.make_branch_and_tree('a')
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
514
        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.
515
        wta.add('file')
516
        wta.commit('a_revision', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
517
        self.run_bzr('branch', 'a', 'b')
518
        os.remove('a/file')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
519
        wta.commit('removed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
520
        file('b/file', 'wb').write('changed contents\n')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
521
        wtb = WorkingTree.open('b')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
522
        wtb.commit('changed file', allow_pointless=False)
1185.31.10 by John Arbash Meinel
Adding merge-delete-conflicts test case.
523
        merge(['a', -1], ['a', 1], this_dir='b')
524
        self.failIf(os.path.lexists('b/file'))
525
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
526
    def test_merge_metadata_vs_deletion(self):
527
        """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.
528
        a_wt = self.make_branch_and_tree('a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
529
        file('a/file', 'wb').write('contents\n')
1508.1.15 by Robert Collins
Merge from mpool.
530
        a_wt.add('file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
531
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
532
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
533
        b_wt = WorkingTree.open('b')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
534
        os.chmod('b/file', 0755)
535
        os.remove('a/file')
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
536
        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.
537
        self.assertEqual(a_wt.branch.revno(), 2)
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
538
        self.assertFalse(os.path.exists('a/file'))
1185.33.27 by Martin Pool
[merge] much integrated work from robert and john
539
        b_wt.commit('exec a')
1185.33.23 by Martin Pool
Add test for merging metadata change vs file deletion
540
        merge(['b', -1], ['b', 0], this_dir='a')
541
        self.assert_(os.path.exists('a/file'))
1185.31.14 by John Arbash Meinel
[merge] bzr.dev
542
1185.33.102 by Denys Duchier
two new tests suggested by abentley
543
    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.
544
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
545
        file('a/un','wb').write('UN')
546
        file('a/deux','wb').write('DEUX')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
547
        a_wt.add('un', 'un')
548
        a_wt.add('deux', 'deux')
549
        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.
550
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
551
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
552
        b_wt.rename_one('un','tmp')
553
        b_wt.rename_one('deux','un')
554
        b_wt.rename_one('tmp','deux')
1508.1.24 by Robert Collins
Add update command for use with checkouts.
555
        b_wt.commit('r1', rev_id='r1')
556
        self.assertEqual(0, merge(['b', -1], ['b', 1], this_dir='a'))
557
        self.failUnlessExists('a/un')
558
        self.failUnless('a/deux')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
559
        self.assertFalse(os.path.exists('a/tmp'))
560
        self.assertEqual(file('a/un').read(),'DEUX')
561
        self.assertEqual(file('a/deux').read(),'UN')
562
563
    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.
564
        a_wt = self.make_branch_and_tree('a')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
565
        file('a/file', 'wb').write('THIS')
566
        a_wt.add('file')
567
        a_wt.commit('r0')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
568
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
569
        b_wt = WorkingTree.open('b')
1185.33.102 by Denys Duchier
two new tests suggested by abentley
570
        os.remove('b/file')
571
        b_wt.commit('r1')
572
        file('b/file', 'wb').write('THAT')
573
        b_wt.add('file')
574
        b_wt.commit('r2')
575
        merge(['b', -1],['b', 1],this_dir='a')
576
        self.assert_(os.path.exists('a/file'))
577
        self.assertEqual(file('a/file').read(),'THAT')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
578
579
    def test_merge_rename_before_create(self):
580
        """rename before create
581
        
582
        This case requires that you must not do creates
583
        before move-into-place:
584
585
        $ touch foo
586
        $ bzr add foo
587
        $ bzr commit
588
        $ bzr mv foo bar
589
        $ touch foo
590
        $ bzr add foo
591
        $ bzr commit
592
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
593
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
594
        file('a/foo', 'wb').write('A/FOO')
595
        a_wt.add('foo')
596
        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.
597
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
598
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
599
        b_wt.rename_one('foo', 'bar')
600
        file('b/foo', 'wb').write('B/FOO')
601
        b_wt.add('foo')
602
        b_wt.commit('moved foo to bar, added new foo')
603
        merge(['b', -1],['b', 1],this_dir='a')
604
605
    def test_merge_create_before_rename(self):
606
        """create before rename, target parents before children
607
608
        This case requires that you must not do move-into-place
609
        before creates, and that you must not do children after
610
        parents:
611
612
        $ touch foo
613
        $ bzr add foo
614
        $ bzr commit
615
        $ bzr mkdir bar
616
        $ bzr add bar
617
        $ bzr mv foo bar/foo
618
        $ bzr commit
619
        """
620
        os.mkdir('a')
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
621
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
622
        file('a/foo', 'wb').write('A/FOO')
623
        a_wt.add('foo')
624
        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.
625
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
626
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
627
        os.mkdir('b/bar')
628
        b_wt.add('bar')
629
        b_wt.rename_one('foo', 'bar/foo')
630
        b_wt.commit('created bar dir, moved foo into bar')
631
        merge(['b', -1],['b', 1],this_dir='a')
632
633
    def test_merge_rename_to_temp_before_delete(self):
634
        """rename to temp before delete, source children before parents
635
636
        This case requires that you must not do deletes before
637
        move-out-of-the-way, and that you must not do children
638
        after parents:
639
        
640
        $ mkdir foo
641
        $ touch foo/bar
642
        $ bzr add foo/bar
643
        $ bzr commit
644
        $ bzr mv foo/bar bar
645
        $ rmdir foo
646
        $ bzr commit
647
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
648
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
649
        os.mkdir('a/foo')
650
        file('a/foo/bar', 'wb').write('A/FOO/BAR')
651
        a_wt.add('foo')
652
        a_wt.add('foo/bar')
653
        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.
654
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
655
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
656
        b_wt.rename_one('foo/bar', 'bar')
657
        os.rmdir('b/foo')
658
        b_wt.remove('foo')
659
        b_wt.commit('moved foo/bar to bar, deleted foo')
660
        merge(['b', -1],['b', 1],this_dir='a')
661
662
    def test_merge_delete_before_rename_to_temp(self):
663
        """delete before rename to temp
664
665
        This case requires that you must not do
666
        move-out-of-the-way before deletes:
667
        
668
        $ touch foo
669
        $ touch bar
670
        $ bzr add foo bar
671
        $ bzr commit
672
        $ rm foo
673
        $ bzr rm foo
674
        $ bzr mv bar foo
675
        $ bzr commit
676
        """
1534.4.26 by Robert Collins
Move working tree initialisation out from Branch.initialize, deprecated Branch.initialize to Branch.create.
677
        a_wt = self.make_branch_and_tree('a')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
678
        file('a/foo', 'wb').write('A/FOO')
679
        file('a/bar', 'wb').write('A/BAR')
680
        a_wt.add('foo')
681
        a_wt.add('bar')
682
        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.
683
        self.run_bzr('branch', 'a', 'b')
1508.1.19 by Robert Collins
Give format3 working trees their own last-revision marker.
684
        b_wt = WorkingTree.open('b')
1185.33.103 by Denys Duchier
4 new merge tests suggested by abentley
685
        os.unlink('b/foo')
686
        b_wt.remove('foo')
687
        b_wt.rename_one('bar', 'foo')
688
        b_wt.commit('deleted foo, renamed bar to foo')
689
        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.
690