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