~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_conflicts.py

  • Committer: Martin Pool
  • Date: 2011-02-07 01:39:42 UTC
  • mto: This revision was merged to the branch mainline in revision 5650.
  • Revision ID: mbp@canonical.com-20110207013942-roj88kez6jir13tr
Add brief user documentation of command line splitting

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
    conflicts,
23
23
    errors,
24
24
    option,
25
 
    osutils,
26
25
    tests,
27
26
    )
28
27
from bzrlib.tests import (
64
63
 
65
64
class TestConflicts(tests.TestCaseWithTransport):
66
65
 
 
66
    def test_conflicts(self):
 
67
        """Conflicts are detected properly"""
 
68
        # Use BzrDirFormat6 so we can fake conflicts
 
69
        tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
 
70
        self.build_tree_contents([('hello', 'hello world4'),
 
71
                                  ('hello.THIS', 'hello world2'),
 
72
                                  ('hello.BASE', 'hello world1'),
 
73
                                  ('hello.OTHER', 'hello world3'),
 
74
                                  ('hello.sploo.BASE', 'yellowworld'),
 
75
                                  ('hello.sploo.OTHER', 'yellowworld2'),
 
76
                                  ])
 
77
        tree.lock_read()
 
78
        self.assertLength(6, list(tree.list_files()))
 
79
        tree.unlock()
 
80
        tree_conflicts = tree.conflicts()
 
81
        self.assertLength(2, tree_conflicts)
 
82
        self.assertTrue('hello' in tree_conflicts[0].path)
 
83
        self.assertTrue('hello.sploo' in tree_conflicts[1].path)
 
84
        conflicts.restore('hello')
 
85
        conflicts.restore('hello.sploo')
 
86
        self.assertLength(0, tree.conflicts())
 
87
        self.assertFileEqual('hello world2', 'hello')
 
88
        self.assertFalse(os.path.lexists('hello.sploo'))
 
89
        self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
 
90
        self.assertRaises(errors.NotConflicted,
 
91
                          conflicts.restore, 'hello.sploo')
 
92
 
67
93
    def test_resolve_conflict_dir(self):
68
94
        tree = self.make_branch_and_tree('.')
69
95
        self.build_tree_contents([('hello', 'hello world4'),
350
376
 
351
377
    scenarios = mirror_scenarios(
352
378
        [
353
 
            # File modified on both sides
 
379
            # File modified/deleted
354
380
            (dict(_base_actions='create_file',
355
381
                  _path='file', _file_id='file-id'),
356
382
             ('filed_modified_A',
357
383
              dict(actions='modify_file_A', check='file_has_content_A')),
358
384
             ('file_modified_B',
359
385
              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
386
            ])
370
387
 
371
 
    def do_create_file(self, path='file'):
372
 
        return [('add', (path, 'file-id', 'file', 'trunk content\n'))]
 
388
    def do_create_file(self):
 
389
        return [('add', ('file', 'file-id', 'file', 'trunk content\n'))]
373
390
 
374
391
    def do_modify_file_A(self):
375
392
        return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
377
394
    def do_modify_file_B(self):
378
395
        return [('modify', ('file-id', 'trunk content\nfeature B\n'))]
379
396
 
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
    def check_file_has_content_A(self):
 
398
        self.assertFileEqual('trunk content\nfeature A\n', 'branch/file')
 
399
 
 
400
    def check_file_has_content_B(self):
 
401
        self.assertFileEqual('trunk content\nfeature B\n', 'branch/file')
397
402
 
398
403
    def _get_resolve_path_arg(self, wt, action):
399
404
        return self._path
446
451
        return [('unversion', 'file-id')]
447
452
 
448
453
    def check_file_doesnt_exist(self):
449
 
        self.assertPathDoesNotExist('branch/file')
 
454
        self.failIfExists('branch/file')
450
455
 
451
456
    def do_create_file_in_dir(self):
452
457
        return [('add', ('dir', 'dir-id', 'directory', '')),
459
464
        self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
460
465
 
461
466
    def check_file_in_dir_doesnt_exist(self):
462
 
        self.assertPathDoesNotExist('branch/dir/file')
 
467
        self.failIfExists('branch/dir/file')
463
468
 
464
469
    def _get_resolve_path_arg(self, wt, action):
465
470
        return self._path
540
545
        return [('rename', ('file', 'new-file'))]
541
546
 
542
547
    def check_file_renamed(self):
543
 
        self.assertPathDoesNotExist('branch/file')
544
 
        self.assertPathExists('branch/new-file')
 
548
        self.failIfExists('branch/file')
 
549
        self.failUnlessExists('branch/new-file')
545
550
 
546
551
    def do_rename_file2(self):
547
552
        return [('rename', ('file', 'new-file2'))]
548
553
 
549
554
    def check_file_renamed2(self):
550
 
        self.assertPathDoesNotExist('branch/file')
551
 
        self.assertPathExists('branch/new-file2')
 
555
        self.failIfExists('branch/file')
 
556
        self.failUnlessExists('branch/new-file2')
552
557
 
553
558
    def do_rename_dir(self):
554
559
        return [('rename', ('dir', 'new-dir'))]
555
560
 
556
561
    def check_dir_renamed(self):
557
 
        self.assertPathDoesNotExist('branch/dir')
558
 
        self.assertPathExists('branch/new-dir')
 
562
        self.failIfExists('branch/dir')
 
563
        self.failUnlessExists('branch/new-dir')
559
564
 
560
565
    def do_rename_dir2(self):
561
566
        return [('rename', ('dir', 'new-dir2'))]
562
567
 
563
568
    def check_dir_renamed2(self):
564
 
        self.assertPathDoesNotExist('branch/dir')
565
 
        self.assertPathExists('branch/new-dir2')
 
569
        self.failIfExists('branch/dir')
 
570
        self.failUnlessExists('branch/new-dir2')
566
571
 
567
572
    def do_delete_file(self):
568
573
        return [('unversion', 'file-id')]
569
574
 
570
575
    def check_file_doesnt_exist(self):
571
 
        self.assertPathDoesNotExist('branch/file')
 
576
        self.failIfExists('branch/file')
572
577
 
573
578
    def do_delete_dir(self):
574
579
        return [('unversion', 'dir-id')]
575
580
 
576
581
    def check_dir_doesnt_exist(self):
577
 
        self.assertPathDoesNotExist('branch/dir')
 
582
        self.failIfExists('branch/dir')
578
583
 
579
584
    def do_create_file_in_dir(self):
580
585
        return [('add', ('dir', 'dir-id', 'directory', '')),
584
589
        return [('rename', ('dir/file', 'dir/new-file'))]
585
590
 
586
591
    def check_file_in_dir_renamed(self):
587
 
        self.assertPathDoesNotExist('branch/dir/file')
588
 
        self.assertPathExists('branch/dir/new-file')
 
592
        self.failIfExists('branch/dir/file')
 
593
        self.failUnlessExists('branch/dir/new-file')
589
594
 
590
595
    def check_file_in_dir_doesnt_exist(self):
591
 
        self.assertPathDoesNotExist('branch/dir/file')
 
596
        self.failIfExists('branch/dir/file')
592
597
 
593
598
    def _get_resolve_path_arg(self, wt, action):
594
599
        tpath = self._this['path']
885
890
        return [('rename', ('dir1', 'dir2/dir1'))]
886
891
 
887
892
    def check_dir1_moved(self):
888
 
        self.assertPathDoesNotExist('branch/dir1')
889
 
        self.assertPathExists('branch/dir2/dir1')
 
893
        self.failIfExists('branch/dir1')
 
894
        self.failUnlessExists('branch/dir2/dir1')
890
895
 
891
896
    def do_move_dir2_into_dir1(self):
892
897
        return [('rename', ('dir2', 'dir1/dir2'))]
893
898
 
894
899
    def check_dir2_moved(self):
895
 
        self.assertPathDoesNotExist('branch/dir2')
896
 
        self.assertPathExists('branch/dir1/dir2')
 
900
        self.failIfExists('branch/dir2')
 
901
        self.failUnlessExists('branch/dir1/dir2')
897
902
 
898
903
    def do_create_dir1_4(self):
899
904
        return [('add', ('dir1', 'dir1-id', 'directory', '')),
905
910
        return [('rename', ('dir1', 'dir3/dir4/dir1'))]
906
911
 
907
912
    def check_dir1_2_moved(self):
908
 
        self.assertPathDoesNotExist('branch/dir1')
909
 
        self.assertPathExists('branch/dir3/dir4/dir1')
910
 
        self.assertPathExists('branch/dir3/dir4/dir1/dir2')
 
913
        self.failIfExists('branch/dir1')
 
914
        self.failUnlessExists('branch/dir3/dir4/dir1')
 
915
        self.failUnlessExists('branch/dir3/dir4/dir1/dir2')
911
916
 
912
917
    def do_move_dir3_into_dir2(self):
913
918
        return [('rename', ('dir3', 'dir1/dir2/dir3'))]
914
919
 
915
920
    def check_dir3_4_moved(self):
916
 
        self.assertPathDoesNotExist('branch/dir3')
917
 
        self.assertPathExists('branch/dir1/dir2/dir3')
918
 
        self.assertPathExists('branch/dir1/dir2/dir3/dir4')
 
921
        self.failIfExists('branch/dir3')
 
922
        self.failUnlessExists('branch/dir1/dir2/dir3')
 
923
        self.failUnlessExists('branch/dir1/dir2/dir3/dir4')
919
924
 
920
925
    def _get_resolve_path_arg(self, wt, action):
921
926
        # ParentLoop says: moving <conflict_path> into <path>. Cancelled move.