65
64
class TestConflicts(tests.TestCaseWithTransport):
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'),
78
self.assertLength(6, list(tree.list_files()))
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')
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'),
351
377
scenarios = mirror_scenarios(
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')),
367
dict(actions='modify_file_B',
368
check='file_in_dir_has_content_B')),),
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'))]
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'))]
380
def check_file_has_content_A(self, path='file'):
381
self.assertFileEqual('trunk content\nfeature A\n',
382
osutils.pathjoin('branch', path))
384
def check_file_has_content_B(self, path='file'):
385
self.assertFileEqual('trunk content\nfeature B\n',
386
osutils.pathjoin('branch', path))
388
def do_create_file_in_dir(self):
389
return [('add', ('dir', 'dir-id', 'directory', '')),
390
] + self.do_create_file('dir/file')
392
def check_file_in_dir_has_content_A(self):
393
self.check_file_has_content_A('dir/file')
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')
400
def check_file_has_content_B(self):
401
self.assertFileEqual('trunk content\nfeature B\n', 'branch/file')
398
403
def _get_resolve_path_arg(self, wt, action):
399
404
return self._path
446
451
return [('unversion', 'file-id')]
448
453
def check_file_doesnt_exist(self):
449
self.assertPathDoesNotExist('branch/file')
454
self.failIfExists('branch/file')
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')
461
466
def check_file_in_dir_doesnt_exist(self):
462
self.assertPathDoesNotExist('branch/dir/file')
467
self.failIfExists('branch/dir/file')
464
469
def _get_resolve_path_arg(self, wt, action):
465
470
return self._path
540
545
return [('rename', ('file', 'new-file'))]
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')
546
551
def do_rename_file2(self):
547
552
return [('rename', ('file', 'new-file2'))]
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')
553
558
def do_rename_dir(self):
554
559
return [('rename', ('dir', 'new-dir'))]
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')
560
565
def do_rename_dir2(self):
561
566
return [('rename', ('dir', 'new-dir2'))]
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')
567
572
def do_delete_file(self):
568
573
return [('unversion', 'file-id')]
570
575
def check_file_doesnt_exist(self):
571
self.assertPathDoesNotExist('branch/file')
576
self.failIfExists('branch/file')
573
578
def do_delete_dir(self):
574
579
return [('unversion', 'dir-id')]
576
581
def check_dir_doesnt_exist(self):
577
self.assertPathDoesNotExist('branch/dir')
582
self.failIfExists('branch/dir')
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'))]
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')
590
595
def check_file_in_dir_doesnt_exist(self):
591
self.assertPathDoesNotExist('branch/dir/file')
596
self.failIfExists('branch/dir/file')
593
598
def _get_resolve_path_arg(self, wt, action):
594
599
tpath = self._this['path']
885
890
return [('rename', ('dir1', 'dir2/dir1'))]
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')
891
896
def do_move_dir2_into_dir1(self):
892
897
return [('rename', ('dir2', 'dir1/dir2'))]
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')
898
903
def do_create_dir1_4(self):
899
904
return [('add', ('dir1', 'dir1-id', 'directory', '')),
905
910
return [('rename', ('dir1', 'dir3/dir4/dir1'))]
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')
912
917
def do_move_dir3_into_dir2(self):
913
918
return [('rename', ('dir3', 'dir1/dir2/dir3'))]
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')
920
925
def _get_resolve_path_arg(self, wt, action):
921
926
# ParentLoop says: moving <conflict_path> into <path>. Cancelled move.