~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_merge_core.py

merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
from bzrlib.inventory import RootEntry
12
12
import bzrlib.inventory as inventory
13
13
from bzrlib.merge import Merge3Merger, Diff3Merger, WeaveMerger
14
 
from bzrlib.osutils import (file_kind, mkdtemp, pathjoin, rename, rmtree,
 
14
from bzrlib.osutils import (file_kind, getcwd, mkdtemp, pathjoin, rename, rmtree,
15
15
                            sha_file, 
16
16
                            )
17
17
from bzrlib.transform import TreeTransform
20
20
 
21
21
 
22
22
class MergeBuilder(object):
23
 
    def __init__(self):
24
 
        self.dir = mkdtemp(prefix="merge-test")
 
23
    def __init__(self, dir=None):
 
24
        self.dir = mkdtemp(prefix="merge-test", dir=dir)
25
25
        def wt(name):
26
26
           path = pathjoin(self.dir, name)
27
27
           os.mkdir(path)
166
166
        rmtree(self.dir)
167
167
 
168
168
 
169
 
class MergeTest(TestCase):
 
169
class MergeTest(TestCaseWithTransport):
170
170
 
171
171
    def test_change_name(self):
172
172
        """Test renames"""
173
 
        builder = MergeBuilder()
 
173
        builder = MergeBuilder(getcwd())
174
174
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", True)
175
175
        builder.change_name("1", other="name2")
176
176
        builder.add_file("2", "TREE_ROOT", "name3", "hello2", True)
179
179
        builder.change_name("3", this="name6")
180
180
        builder.merge()
181
181
        builder.cleanup()
182
 
        builder = MergeBuilder()
 
182
        builder = MergeBuilder(getcwd())
183
183
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", False)
184
184
        builder.change_name("1", other="name2", this="name3")
185
185
        conflicts = builder.merge()
187
187
        builder.cleanup()
188
188
 
189
189
    def test_merge_one(self):
190
 
        builder = MergeBuilder()
 
190
        builder = MergeBuilder(getcwd())
191
191
        builder.add_file("1", "TREE_ROOT", "name1", "hello1", True)
192
192
        builder.change_contents("1", other="text4")
193
193
        builder.add_file("2", "TREE_ROOT", "name2", "hello1", True)
198
198
        
199
199
    def test_file_moves(self):
200
200
        """Test moves"""
201
 
        builder = MergeBuilder()
 
201
        builder = MergeBuilder(getcwd())
202
202
        builder.add_dir("1", "TREE_ROOT", "dir1")
203
203
        builder.add_dir("2", "TREE_ROOT", "dir2")
204
204
        builder.add_file("3", "1", "file1", "hello1", True)
210
210
        builder.merge()
211
211
        builder.cleanup()
212
212
 
213
 
        builder = MergeBuilder()
 
213
        builder = MergeBuilder(getcwd())
214
214
        builder.add_dir("1", "TREE_ROOT", "dir1")
215
215
        builder.add_dir("2", "TREE_ROOT", "dir2")
216
216
        builder.add_dir("3", "TREE_ROOT", "dir3")
239
239
 
240
240
    def test_reprocess_weave(self):
241
241
        # Reprocess works on weaves, and behaves as expected
242
 
        builder = MergeBuilder()
 
242
        builder = MergeBuilder(getcwd())
243
243
        builder.add_file('a', 'TREE_ROOT', 'blah', 'a', False)
244
244
        builder.change_contents('a', this='b\nc\nd\ne\n', other='z\nc\nd\ny\n')
245
245
        builder.merge(WeaveMerger, reprocess=True)
267
267
        self.contents_test_conflicts(merge_factory)
268
268
 
269
269
    def contents_test_success(self, merge_factory):
270
 
        builder = MergeBuilder()
 
270
        builder = MergeBuilder(getcwd())
271
271
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
272
272
        builder.change_contents("1", other="text4")
273
273
        builder.add_file("2", "TREE_ROOT", "name3", "text2", False)
289
289
        return builder
290
290
 
291
291
    def contents_test_conflicts(self, merge_factory):
292
 
        builder = MergeBuilder()
 
292
        builder = MergeBuilder(getcwd())
293
293
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
294
294
        builder.change_contents("1", other="text4", this="text3")
295
295
        builder.add_file("2", "TREE_ROOT", "name2", "text1", True)
307
307
 
308
308
    def test_symlink_conflicts(self):
309
309
        if sys.platform != "win32":
310
 
            builder = MergeBuilder()
 
310
            builder = MergeBuilder(getcwd())
311
311
            builder.add_symlink("2", "TREE_ROOT", "name2", "target1")
312
312
            builder.change_target("2", other="target4", base="text3")
313
313
            conflicts = builder.merge()
317
317
 
318
318
    def test_symlink_merge(self):
319
319
        if sys.platform != "win32":
320
 
            builder = MergeBuilder()
 
320
            builder = MergeBuilder(getcwd())
321
321
            builder.add_symlink("1", "TREE_ROOT", "name1", "target1")
322
322
            builder.add_symlink("2", "TREE_ROOT", "name2", "target1")
323
323
            builder.add_symlink("3", "TREE_ROOT", "name3", "target1")
331
331
            builder.cleanup()
332
332
 
333
333
    def test_no_passive_add(self):
334
 
        builder = MergeBuilder()
 
334
        builder = MergeBuilder(getcwd())
335
335
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
336
336
        builder.remove_file("1", this=True)
337
337
        builder.merge()
338
338
        builder.cleanup()
339
339
 
340
340
    def test_perms_merge(self):
341
 
        builder = MergeBuilder()
 
341
        builder = MergeBuilder(getcwd())
342
342
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
343
343
        builder.change_perms("1", other=False)
344
344
        builder.add_file("2", "TREE_ROOT", "name2", "text2", True)
355
355
        builder.cleanup();
356
356
 
357
357
    def test_new_suffix(self):
358
 
        builder = MergeBuilder()
 
358
        builder = MergeBuilder(getcwd())
359
359
        builder.add_file("1", "TREE_ROOT", "name1", "text1", True)
360
360
        builder.change_contents("1", other="text3")
361
361
        builder.add_file("2", "TREE_ROOT", "name1.new", "text2", True)
364
364
        builder.cleanup()
365
365
 
366
366
    def test_spurious_conflict(self):
367
 
        builder = MergeBuilder()
 
367
        builder = MergeBuilder(getcwd())
368
368
        builder.add_file("1", "TREE_ROOT", "name1", "text1", False)
369
369
        builder.remove_file("1", other=True)
370
370
        builder.add_file("2", "TREE_ROOT", "name1", "text1", False, this=False,