~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
18
18
import os
19
19
 
20
20
from bzrlib import (
21
 
    branchbuilder,
22
21
    bzrdir,
23
22
    conflicts,
24
23
    errors,
25
24
    option,
 
25
    osutils,
26
26
    tests,
27
 
    workingtree,
28
 
    )
29
 
from bzrlib.tests import script
30
 
 
31
 
 
32
 
def load_tests(standard_tests, module, loader):
33
 
    result = loader.suiteClass()
34
 
 
35
 
    sp_tests, remaining_tests = tests.split_suite_by_condition(
36
 
        standard_tests, tests.condition_isinstance((
37
 
                TestParametrizedResolveConflicts,
38
 
                )))
39
 
    # Each test class defines its own scenarios. This is needed for
40
 
    # TestResolvePathConflictBefore531967 that verifies that the same tests as
41
 
    # TestResolvePathConflict still pass.
42
 
    for test in tests.iter_suite_tests(sp_tests):
43
 
        tests.apply_scenarios(test, test.scenarios(), result)
44
 
 
45
 
    # No parametrization for the remaining tests
46
 
    result.addTests(remaining_tests)
47
 
 
48
 
    return result
 
27
    )
 
28
from bzrlib.tests import (
 
29
    script,
 
30
    scenarios,
 
31
    )
 
32
 
 
33
 
 
34
load_tests = scenarios.load_tests_apply_scenarios
49
35
 
50
36
 
51
37
# TODO: Test commit with some added, and added-but-missing files
78
64
 
79
65
class TestConflicts(tests.TestCaseWithTransport):
80
66
 
81
 
    def test_conflicts(self):
82
 
        """Conflicts are detected properly"""
83
 
        # Use BzrDirFormat6 so we can fake conflicts
84
 
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
85
 
        self.build_tree_contents([('hello', 'hello world4'),
86
 
                                  ('hello.THIS', 'hello world2'),
87
 
                                  ('hello.BASE', 'hello world1'),
88
 
                                  ('hello.OTHER', 'hello world3'),
89
 
                                  ('hello.sploo.BASE', 'yellowworld'),
90
 
                                  ('hello.sploo.OTHER', 'yellowworld2'),
91
 
                                  ])
92
 
        tree.lock_read()
93
 
        self.assertLength(6, list(tree.list_files()))
94
 
        tree.unlock()
95
 
        tree_conflicts = tree.conflicts()
96
 
        self.assertLength(2, tree_conflicts)
97
 
        self.assertTrue('hello' in tree_conflicts[0].path)
98
 
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
99
 
        conflicts.restore('hello')
100
 
        conflicts.restore('hello.sploo')
101
 
        self.assertLength(0, tree.conflicts())
102
 
        self.assertFileEqual('hello world2', 'hello')
103
 
        self.assertFalse(os.path.lexists('hello.sploo'))
104
 
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
105
 
        self.assertRaises(errors.NotConflicted,
106
 
                          conflicts.restore, 'hello.sploo')
107
 
 
108
67
    def test_resolve_conflict_dir(self):
109
68
        tree = self.make_branch_and_tree('.')
110
69
        self.build_tree_contents([('hello', 'hello world4'),
210
169
        self.run_script(self.preamble)
211
170
 
212
171
 
213
 
class TestResolveTextConflicts(TestResolveConflicts):
214
 
    # TBC
215
 
    pass
216
 
 
217
 
 
218
172
def mirror_scenarios(base_scenarios):
219
173
    """Return a list of mirrored scenarios.
220
174
 
293
247
    _this = None
294
248
    _other = None
295
249
 
296
 
    @staticmethod
297
 
    def scenarios():
298
 
        """Return the scenario list for the conflict type defined by the class.
299
 
 
300
 
        Each scenario is of the form:
301
 
        (common, (left_name, left_dict), (right_name, right_dict))
302
 
 
303
 
        * common is a dict
304
 
 
305
 
        * left_name and right_name are the scenario names that will be combined
306
 
 
307
 
        * left_dict and right_dict are the attributes specific to each half of
308
 
          the scenario. They should include at least 'actions' and 'check' and
309
 
          will be available as '_this' and '_other' test instance attributes.
310
 
 
311
 
        Daughters classes are free to add their specific attributes as they see
312
 
        fit in any of the three dicts.
313
 
 
314
 
        This is a class method so that load_tests can find it.
315
 
 
316
 
        '_base_actions' in the common dict, 'actions' and 'check' in the left
317
 
        and right dicts use names that map to methods in the test classes. Some
318
 
        prefixes are added to these names to get the correspong methods (see
319
 
        _get_actions() and _get_check()). The motivation here is to avoid
320
 
        collisions in the class namespace.
321
 
        """
322
 
        # Only concrete classes return actual scenarios
323
 
        return []
 
250
    scenarios = []
 
251
    """The scenario list for the conflict type defined by the class.
 
252
 
 
253
    Each scenario is of the form:
 
254
    (common, (left_name, left_dict), (right_name, right_dict))
 
255
 
 
256
    * common is a dict
 
257
 
 
258
    * left_name and right_name are the scenario names that will be combined
 
259
 
 
260
    * left_dict and right_dict are the attributes specific to each half of
 
261
      the scenario. They should include at least 'actions' and 'check' and
 
262
      will be available as '_this' and '_other' test instance attributes.
 
263
 
 
264
    Daughters classes are free to add their specific attributes as they see
 
265
    fit in any of the three dicts.
 
266
 
 
267
    This is a class method so that load_tests can find it.
 
268
 
 
269
    '_base_actions' in the common dict, 'actions' and 'check' in the left
 
270
    and right dicts use names that map to methods in the test classes. Some
 
271
    prefixes are added to these names to get the correspong methods (see
 
272
    _get_actions() and _get_check()). The motivation here is to avoid
 
273
    collisions in the class namespace.
 
274
    """
324
275
 
325
276
    def setUp(self):
326
277
        super(TestParametrizedResolveConflicts, self).setUp()
388
339
        check_other()
389
340
 
390
341
 
 
342
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
 
343
 
 
344
    _conflict_type = conflicts.TextConflict
 
345
 
 
346
    # Set by the scenarios
 
347
    # path and file-id for the file involved in the conflict
 
348
    _path = None
 
349
    _file_id = None
 
350
 
 
351
    scenarios = mirror_scenarios(
 
352
        [
 
353
            # File modified on both sides
 
354
            (dict(_base_actions='create_file',
 
355
                  _path='file', _file_id='file-id'),
 
356
             ('filed_modified_A',
 
357
              dict(actions='modify_file_A', check='file_has_content_A')),
 
358
             ('file_modified_B',
 
359
              dict(actions='modify_file_B', check='file_has_content_B')),),
 
360
            # File modified on both sides in dir
 
361
            (dict(_base_actions='create_file_in_dir',
 
362
                  _path='dir/file', _file_id='file-id'),
 
363
             ('filed_modified_A_in_dir',
 
364
              dict(actions='modify_file_A',
 
365
                   check='file_in_dir_has_content_A')),
 
366
             ('file_modified_B',
 
367
              dict(actions='modify_file_B',
 
368
                   check='file_in_dir_has_content_B')),),
 
369
            ])
 
370
 
 
371
    def do_create_file(self, path='file'):
 
372
        return [('add', (path, 'file-id', 'file', 'trunk content\n'))]
 
373
 
 
374
    def do_modify_file_A(self):
 
375
        return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
 
376
 
 
377
    def do_modify_file_B(self):
 
378
        return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
 
379
 
 
380
    def check_file_has_content_A(self, path='file'):
 
381
        self.assertFileEqual('trunk content\nfeature A\n',
 
382
                             osutils.pathjoin('branch', path))
 
383
 
 
384
    def check_file_has_content_B(self, path='file'):
 
385
        self.assertFileEqual('trunk content\nfeature B\n',
 
386
                             osutils.pathjoin('branch', path))
 
387
 
 
388
    def do_create_file_in_dir(self):
 
389
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
390
            ] + self.do_create_file('dir/file')
 
391
 
 
392
    def check_file_in_dir_has_content_A(self):
 
393
        self.check_file_has_content_A('dir/file')
 
394
 
 
395
    def check_file_in_dir_has_content_B(self):
 
396
        self.check_file_has_content_B('dir/file')
 
397
 
 
398
    def _get_resolve_path_arg(self, wt, action):
 
399
        return self._path
 
400
 
 
401
    def assertTextConflict(self, wt, c):
 
402
        self.assertEqual(self._file_id, c.file_id)
 
403
        self.assertEqual(self._path, c.path)
 
404
    _assert_conflict = assertTextConflict
 
405
 
 
406
 
391
407
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
392
408
 
393
 
    _conflict_type = conflicts.ContentsConflict,
 
409
    _conflict_type = conflicts.ContentsConflict
394
410
 
395
 
    # Set by load_tests from scenarios()
 
411
    # Set by the scenarios
396
412
    # path and file-id for the file involved in the conflict
397
413
    _path = None
398
414
    _file_id = None
399
415
 
400
 
    @staticmethod
401
 
    def scenarios():
402
 
        base_scenarios = [
 
416
    scenarios = mirror_scenarios(
 
417
        [
403
418
            # File modified/deleted
404
419
            (dict(_base_actions='create_file',
405
420
                  _path='file', _file_id='file-id'),
407
422
              dict(actions='modify_file', check='file_has_more_content')),
408
423
             ('file_deleted',
409
424
              dict(actions='delete_file', check='file_doesnt_exist')),),
410
 
            ]
411
 
        return mirror_scenarios(base_scenarios)
 
425
            # File modified/deleted in dir
 
426
            (dict(_base_actions='create_file_in_dir',
 
427
                  _path='dir/file', _file_id='file-id'),
 
428
             ('file_modified_in_dir',
 
429
              dict(actions='modify_file_in_dir',
 
430
                   check='file_in_dir_has_more_content')),
 
431
             ('file_deleted_in_dir',
 
432
              dict(actions='delete_file',
 
433
                   check='file_in_dir_doesnt_exist')),),
 
434
            ])
412
435
 
413
436
    def do_create_file(self):
414
437
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
423
446
        return [('unversion', 'file-id')]
424
447
 
425
448
    def check_file_doesnt_exist(self):
426
 
        self.failIfExists('branch/file')
 
449
        self.assertPathDoesNotExist('branch/file')
 
450
 
 
451
    def do_create_file_in_dir(self):
 
452
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
453
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
454
 
 
455
    def do_modify_file_in_dir(self):
 
456
        return [('modify', ('file-id', 'trunk content\nmore content\n'))]
 
457
 
 
458
    def check_file_in_dir_has_more_content(self):
 
459
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
 
460
 
 
461
    def check_file_in_dir_doesnt_exist(self):
 
462
        self.assertPathDoesNotExist('branch/dir/file')
427
463
 
428
464
    def _get_resolve_path_arg(self, wt, action):
429
465
        return self._path
436
472
 
437
473
class TestResolvePathConflict(TestParametrizedResolveConflicts):
438
474
 
439
 
    _conflict_type = conflicts.PathConflict,
 
475
    _conflict_type = conflicts.PathConflict
440
476
 
441
477
    def do_nothing(self):
442
478
        return []
443
479
 
444
 
    @staticmethod
445
 
    def scenarios():
446
 
        # Each side dict additionally defines:
447
 
        # - path path involved (can be '<deleted>')
448
 
        # - file-id involved
449
 
        base_scenarios = [
 
480
    # Each side dict additionally defines:
 
481
    # - path path involved (can be '<deleted>')
 
482
    # - file-id involved
 
483
    scenarios = mirror_scenarios(
 
484
        [
450
485
            # File renamed/deleted
451
486
            (dict(_base_actions='create_file'),
452
487
             ('file_renamed',
457
492
                   # PathConflicts deletion handling requires a special
458
493
                   # hard-coded value
459
494
                   path='<deleted>', file_id='file-id')),),
 
495
            # File renamed/deleted in dir
 
496
            (dict(_base_actions='create_file_in_dir'),
 
497
             ('file_renamed_in_dir',
 
498
              dict(actions='rename_file_in_dir', check='file_in_dir_renamed',
 
499
                   path='dir/new-file', file_id='file-id')),
 
500
             ('file_deleted',
 
501
              dict(actions='delete_file', check='file_in_dir_doesnt_exist',
 
502
                   # PathConflicts deletion handling requires a special
 
503
                   # hard-coded value
 
504
                   path='<deleted>', file_id='file-id')),),
460
505
            # File renamed/renamed differently
461
506
            (dict(_base_actions='create_file'),
462
507
             ('file_renamed',
483
528
             ('dir_renamed2',
484
529
              dict(actions='rename_dir2', check='dir_renamed2',
485
530
                   path='new-dir2', file_id='dir-id')),),
486
 
        ]
487
 
        return mirror_scenarios(base_scenarios)
 
531
            ])
488
532
 
489
533
    def do_create_file(self):
490
534
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
496
540
        return [('rename', ('file', 'new-file'))]
497
541
 
498
542
    def check_file_renamed(self):
499
 
        self.failIfExists('branch/file')
500
 
        self.failUnlessExists('branch/new-file')
 
543
        self.assertPathDoesNotExist('branch/file')
 
544
        self.assertPathExists('branch/new-file')
501
545
 
502
546
    def do_rename_file2(self):
503
547
        return [('rename', ('file', 'new-file2'))]
504
548
 
505
549
    def check_file_renamed2(self):
506
 
        self.failIfExists('branch/file')
507
 
        self.failUnlessExists('branch/new-file2')
 
550
        self.assertPathDoesNotExist('branch/file')
 
551
        self.assertPathExists('branch/new-file2')
508
552
 
509
553
    def do_rename_dir(self):
510
554
        return [('rename', ('dir', 'new-dir'))]
511
555
 
512
556
    def check_dir_renamed(self):
513
 
        self.failIfExists('branch/dir')
514
 
        self.failUnlessExists('branch/new-dir')
 
557
        self.assertPathDoesNotExist('branch/dir')
 
558
        self.assertPathExists('branch/new-dir')
515
559
 
516
560
    def do_rename_dir2(self):
517
561
        return [('rename', ('dir', 'new-dir2'))]
518
562
 
519
563
    def check_dir_renamed2(self):
520
 
        self.failIfExists('branch/dir')
521
 
        self.failUnlessExists('branch/new-dir2')
 
564
        self.assertPathDoesNotExist('branch/dir')
 
565
        self.assertPathExists('branch/new-dir2')
522
566
 
523
567
    def do_delete_file(self):
524
568
        return [('unversion', 'file-id')]
525
569
 
526
570
    def check_file_doesnt_exist(self):
527
 
        self.failIfExists('branch/file')
 
571
        self.assertPathDoesNotExist('branch/file')
528
572
 
529
573
    def do_delete_dir(self):
530
574
        return [('unversion', 'dir-id')]
531
575
 
532
576
    def check_dir_doesnt_exist(self):
533
 
        self.failIfExists('branch/dir')
 
577
        self.assertPathDoesNotExist('branch/dir')
 
578
 
 
579
    def do_create_file_in_dir(self):
 
580
        return [('add', ('dir', 'dir-id', 'directory', '')),
 
581
                ('add', ('dir/file', 'file-id', 'file', 'trunk content\n'))]
 
582
 
 
583
    def do_rename_file_in_dir(self):
 
584
        return [('rename', ('dir/file', 'dir/new-file'))]
 
585
 
 
586
    def check_file_in_dir_renamed(self):
 
587
        self.assertPathDoesNotExist('branch/dir/file')
 
588
        self.assertPathExists('branch/dir/new-file')
 
589
 
 
590
    def check_file_in_dir_doesnt_exist(self):
 
591
        self.assertPathDoesNotExist('branch/dir/file')
534
592
 
535
593
    def _get_resolve_path_arg(self, wt, action):
536
594
        tpath = self._this['path']
568
626
 
569
627
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
570
628
 
571
 
    _conflict_type = conflicts.DuplicateEntry,
 
629
    _conflict_type = conflicts.DuplicateEntry
572
630
 
573
 
    @staticmethod
574
 
    def scenarios():
575
 
        # Each side dict additionally defines:
576
 
        # - path involved
577
 
        # - file-id involved
578
 
        base_scenarios = [
 
631
    scenarios = mirror_scenarios(
 
632
        [
579
633
            # File created with different file-ids
580
634
            (dict(_base_actions='nothing'),
581
635
             ('filea_created',
584
638
             ('fileb_created',
585
639
              dict(actions='create_file_b', check='file_content_b',
586
640
                   path='file', file_id='file-b-id')),),
587
 
            ]
588
 
        return mirror_scenarios(base_scenarios)
 
641
            ])
589
642
 
590
643
    def do_nothing(self):
591
644
        return []
625
678
    # tests MissingParent resolution :-/
626
679
    preamble = """
627
680
$ bzr init trunk
 
681
...
628
682
$ cd trunk
629
683
$ mkdir dir
630
 
$ bzr add dir
631
 
$ bzr commit -m 'Create trunk'
632
 
 
 
684
$ bzr add -q dir
 
685
$ bzr commit -m 'Create trunk' -q
633
686
$ echo 'trunk content' >dir/file
634
 
$ bzr add dir/file
635
 
$ bzr commit -m 'Add dir/file in trunk'
636
 
 
637
 
$ bzr branch . -r 1 ../branch
 
687
$ bzr add -q dir/file
 
688
$ bzr commit -q -m 'Add dir/file in trunk'
 
689
$ bzr branch -q . -r 1 ../branch
638
690
$ cd ../branch
639
 
$ bzr rm dir
640
 
$ bzr commit -m 'Remove dir in branch'
641
 
 
 
691
$ bzr rm dir -q
 
692
$ bzr commit -q -m 'Remove dir in branch'
642
693
$ bzr merge ../trunk
643
694
2>+N  dir/
644
695
2>+N  dir/file
649
700
 
650
701
    def test_take_this(self):
651
702
        self.run_script("""
652
 
$ bzr rm dir  --force
 
703
$ bzr rm -q dir  --force
653
704
$ bzr resolve dir
654
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
705
2>2 conflict(s) resolved, 0 remaining
 
706
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
655
707
""")
656
708
 
657
709
    def test_take_other(self):
658
710
        self.run_script("""
659
711
$ bzr resolve dir
660
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
712
2>2 conflict(s) resolved, 0 remaining
 
713
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
661
714
""")
662
715
 
663
716
 
665
718
 
666
719
    preamble = """
667
720
$ bzr init trunk
 
721
...
668
722
$ cd trunk
669
723
$ mkdir dir
670
724
$ echo 'trunk content' >dir/file
671
 
$ bzr add
672
 
$ bzr commit -m 'Create trunk'
673
 
 
 
725
$ bzr add -q
 
726
$ bzr commit -m 'Create trunk' -q
674
727
$ echo 'trunk content' >dir/file2
675
 
$ bzr add dir/file2
676
 
$ bzr commit -m 'Add dir/file2 in branch'
677
 
 
678
 
$ bzr branch . -r 1 ../branch
 
728
$ bzr add -q dir/file2
 
729
$ bzr commit -q -m 'Add dir/file2 in branch'
 
730
$ bzr branch -q . -r 1 ../branch
679
731
$ cd ../branch
680
 
$ bzr rm dir/file --force
681
 
$ bzr rm dir
682
 
$ bzr commit -m 'Remove dir/file'
683
 
 
 
732
$ bzr rm -q dir/file --force
 
733
$ bzr rm -q dir
 
734
$ bzr commit -q -m 'Remove dir/file'
684
735
$ bzr merge ../trunk
685
736
2>+N  dir/
686
737
2>+N  dir/file2
692
743
    def test_keep_them_all(self):
693
744
        self.run_script("""
694
745
$ bzr resolve dir
695
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
746
2>2 conflict(s) resolved, 0 remaining
 
747
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
696
748
""")
697
749
 
698
750
    def test_adopt_child(self):
699
751
        self.run_script("""
700
 
$ bzr mv dir/file2 file2
701
 
$ bzr rm dir --force
 
752
$ bzr mv -q dir/file2 file2
 
753
$ bzr rm -q dir --force
702
754
$ bzr resolve dir
703
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
755
2>2 conflict(s) resolved, 0 remaining
 
756
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
704
757
""")
705
758
 
706
759
    def test_kill_them_all(self):
707
760
        self.run_script("""
708
 
$ bzr rm dir --force
 
761
$ bzr rm -q dir --force
709
762
$ bzr resolve dir
710
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
763
2>2 conflict(s) resolved, 0 remaining
 
764
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
711
765
""")
712
766
 
713
767
    def test_resolve_taking_this(self):
714
768
        self.run_script("""
715
769
$ bzr resolve --take-this dir
716
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
770
2>...
 
771
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
717
772
""")
718
773
 
719
774
    def test_resolve_taking_other(self):
720
775
        self.run_script("""
721
776
$ bzr resolve --take-other dir
722
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
777
2>...
 
778
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
723
779
""")
724
780
 
725
781
 
727
783
 
728
784
    preamble = """
729
785
$ bzr init trunk
 
786
...
730
787
$ cd trunk
731
788
$ mkdir dir
732
789
$ echo 'trunk content' >dir/file
733
 
$ bzr add
734
 
$ bzr commit -m 'Create trunk'
735
 
 
736
 
$ bzr rm dir/file --force
737
 
$ bzr rm dir --force
738
 
$ bzr commit -m 'Remove dir/file'
739
 
 
740
 
$ bzr branch . -r 1 ../branch
 
790
$ bzr add -q
 
791
$ bzr commit -m 'Create trunk' -q
 
792
$ bzr rm -q dir/file --force
 
793
$ bzr rm -q dir --force
 
794
$ bzr commit -q -m 'Remove dir/file'
 
795
$ bzr branch -q . -r 1 ../branch
741
796
$ cd ../branch
742
797
$ echo 'branch content' >dir/file2
743
 
$ bzr add dir/file2
744
 
$ bzr commit -m 'Add dir/file2 in branch'
745
 
 
 
798
$ bzr add -q dir/file2
 
799
$ bzr commit -q -m 'Add dir/file2 in branch'
746
800
$ bzr merge ../trunk
747
801
2>-D  dir/file
748
802
2>Conflict: can't delete dir because it is not empty.  Not deleting.
753
807
    def test_keep_them_all(self):
754
808
        self.run_script("""
755
809
$ bzr resolve dir
756
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
810
2>2 conflict(s) resolved, 0 remaining
 
811
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
757
812
""")
758
813
 
759
814
    def test_adopt_child(self):
760
815
        self.run_script("""
761
 
$ bzr mv dir/file2 file2
762
 
$ bzr rm dir --force
 
816
$ bzr mv -q dir/file2 file2
 
817
$ bzr rm -q dir --force
763
818
$ bzr resolve dir
764
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
819
2>2 conflict(s) resolved, 0 remaining
 
820
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
765
821
""")
766
822
 
767
823
    def test_kill_them_all(self):
768
824
        self.run_script("""
769
 
$ bzr rm dir --force
 
825
$ bzr rm -q dir --force
770
826
$ bzr resolve dir
771
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
827
2>2 conflict(s) resolved, 0 remaining
 
828
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
772
829
""")
773
830
 
774
831
    def test_resolve_taking_this(self):
775
832
        self.run_script("""
776
833
$ bzr resolve --take-this dir
777
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
834
2>2 conflict(s) resolved, 0 remaining
 
835
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
778
836
""")
779
837
 
780
838
    def test_resolve_taking_other(self):
781
839
        self.run_script("""
782
840
$ bzr resolve --take-other dir
783
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
841
2>deleted dir/file2
 
842
2>deleted dir
 
843
2>2 conflict(s) resolved, 0 remaining
 
844
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
784
845
""")
785
846
 
786
847
 
787
848
class TestResolveParentLoop(TestParametrizedResolveConflicts):
788
849
 
789
 
    _conflict_type = conflicts.ParentLoop,
 
850
    _conflict_type = conflicts.ParentLoop
790
851
 
791
852
    _this_args = None
792
853
    _other_args = None
793
854
 
794
 
    @staticmethod
795
 
    def scenarios():
796
 
        # Each side dict additionally defines:
797
 
        # - dir_id: the directory being moved
798
 
        # - target_id: The target directory
799
 
        # - xfail: whether the test is expected to fail if the action is
800
 
        #     involved as 'other'
801
 
        base_scenarios = [
 
855
    # Each side dict additionally defines:
 
856
    # - dir_id: the directory being moved
 
857
    # - target_id: The target directory
 
858
    # - xfail: whether the test is expected to fail if the action is
 
859
    #   involved as 'other'
 
860
    scenarios = mirror_scenarios(
 
861
        [
802
862
            # Dirs moved into each other
803
863
            (dict(_base_actions='create_dir1_dir2'),
804
864
             ('dir1_into_dir2',
815
875
             ('dir3_into_dir2',
816
876
              dict(actions='move_dir3_into_dir2', check='dir3_4_moved',
817
877
                   dir_id='dir3-id', target_id='dir2-id', xfail=True))),
818
 
            ]
819
 
        return mirror_scenarios(base_scenarios)
 
878
            ])
820
879
 
821
880
    def do_create_dir1_dir2(self):
822
881
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
826
885
        return [('rename', ('dir1', 'dir2/dir1'))]
827
886
 
828
887
    def check_dir1_moved(self):
829
 
        self.failIfExists('branch/dir1')
830
 
        self.failUnlessExists('branch/dir2/dir1')
 
888
        self.assertPathDoesNotExist('branch/dir1')
 
889
        self.assertPathExists('branch/dir2/dir1')
831
890
 
832
891
    def do_move_dir2_into_dir1(self):
833
892
        return [('rename', ('dir2', 'dir1/dir2'))]
834
893
 
835
894
    def check_dir2_moved(self):
836
 
        self.failIfExists('branch/dir2')
837
 
        self.failUnlessExists('branch/dir1/dir2')
 
895
        self.assertPathDoesNotExist('branch/dir2')
 
896
        self.assertPathExists('branch/dir1/dir2')
838
897
 
839
898
    def do_create_dir1_4(self):
840
899
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
846
905
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
847
906
 
848
907
    def check_dir1_2_moved(self):
849
 
        self.failIfExists('branch/dir1')
850
 
        self.failUnlessExists('branch/dir3/dir4/dir1')
851
 
        self.failUnlessExists('branch/dir3/dir4/dir1/dir2')
 
908
        self.assertPathDoesNotExist('branch/dir1')
 
909
        self.assertPathExists('branch/dir3/dir4/dir1')
 
910
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
852
911
 
853
912
    def do_move_dir3_into_dir2(self):
854
913
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
855
914
 
856
915
    def check_dir3_4_moved(self):
857
 
        self.failIfExists('branch/dir3')
858
 
        self.failUnlessExists('branch/dir1/dir2/dir3')
859
 
        self.failUnlessExists('branch/dir1/dir2/dir3/dir4')
 
916
        self.assertPathDoesNotExist('branch/dir3')
 
917
        self.assertPathExists('branch/dir1/dir2/dir3')
 
918
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
860
919
 
861
920
    def _get_resolve_path_arg(self, wt, action):
862
921
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.
882
941
 
883
942
    preamble = """
884
943
$ bzr init trunk
 
944
...
885
945
$ cd trunk
886
946
$ bzr mkdir foo
887
 
$ bzr commit -m 'Create trunk'
 
947
...
 
948
$ bzr commit -m 'Create trunk' -q
888
949
$ echo "Boing" >foo/bar
889
 
$ bzr add foo/bar
890
 
$ bzr commit -m 'Add foo/bar'
891
 
 
892
 
$ bzr branch . -r 1 ../branch
 
950
$ bzr add -q foo/bar
 
951
$ bzr commit -q -m 'Add foo/bar'
 
952
$ bzr branch -q . -r 1 ../branch
893
953
$ cd ../branch
894
954
$ rm -r foo
895
955
$ echo "Boo!" >foo
896
 
$ bzr commit -m 'foo is now a file'
897
 
 
 
956
$ bzr commit -q -m 'foo is now a file'
898
957
$ bzr merge ../trunk
899
958
2>+N  foo.new/bar
900
959
2>RK  foo => foo.new/
906
965
 
907
966
    def test_take_this(self):
908
967
        self.run_script("""
909
 
$ bzr rm foo.new --force
 
968
$ bzr rm -q foo.new --force
910
969
# FIXME: Isn't it weird that foo is now unkown even if foo.new has been put
911
970
# aside ? -- vila 090916
912
 
$ bzr add foo
 
971
$ bzr add -q foo
913
972
$ bzr resolve foo.new
914
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
973
2>1 conflict(s) resolved, 0 remaining
 
974
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
915
975
""")
916
976
 
917
977
    def test_take_other(self):
918
978
        self.run_script("""
919
 
$ bzr rm foo --force
920
 
$ bzr mv foo.new foo
 
979
$ bzr rm -q foo --force
 
980
$ bzr mv -q foo.new foo
921
981
$ bzr resolve foo
922
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
982
2>1 conflict(s) resolved, 0 remaining
 
983
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
923
984
""")
924
985
 
925
986
    def test_resolve_taking_this(self):
926
987
        self.run_script("""
927
988
$ bzr resolve --take-this foo.new
928
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
989
2>...
 
990
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
929
991
""")
930
992
 
931
993
    def test_resolve_taking_other(self):
932
994
        self.run_script("""
933
995
$ bzr resolve --take-other foo.new
934
 
$ bzr commit --strict -m 'No more conflicts nor unknown files'
 
996
2>...
 
997
$ bzr commit -q --strict -m 'No more conflicts nor unknown files'
935
998
""")
936
999
 
937
1000
 
943
1006
        # conflict.
944
1007
        self.run_script("""
945
1008
$ bzr init trunk
 
1009
...
946
1010
$ cd trunk
947
1011
$ bzr mkdir foo
948
 
$ bzr commit -m 'Create trunk'
 
1012
...
 
1013
$ bzr commit -m 'Create trunk' -q
949
1014
$ rm -r foo
950
1015
$ echo "Boo!" >foo
951
 
$ bzr commit -m 'foo is now a file'
952
 
 
953
 
$ bzr branch . -r 1 ../branch
 
1016
$ bzr commit -m 'foo is now a file' -q
 
1017
$ bzr branch -q . -r 1 ../branch -q
954
1018
$ cd ../branch
955
1019
$ echo "Boing" >foo/bar
956
 
$ bzr add foo/bar
957
 
$ bzr commit -m 'Add foo/bar'
958
 
 
 
1020
$ bzr add -q foo/bar -q
 
1021
$ bzr commit -m 'Add foo/bar' -q
959
1022
$ bzr merge ../trunk
960
1023
2>bzr: ERROR: Tree transform is malformed [('unversioned executability', 'new-1')]
961
1024
""")