66
65
class TestConflicts(tests.TestCaseWithTransport):
68
def test_conflicts(self):
69
"""Conflicts are detected properly"""
70
# Use BzrDirFormat6 so we can fake conflicts
71
tree = self.make_branch_and_tree('.', format=bzrdir.BzrDirFormat6())
72
self.build_tree_contents([('hello', 'hello world4'),
73
('hello.THIS', 'hello world2'),
74
('hello.BASE', 'hello world1'),
75
('hello.OTHER', 'hello world3'),
76
('hello.sploo.BASE', 'yellowworld'),
77
('hello.sploo.OTHER', 'yellowworld2'),
80
self.assertLength(6, list(tree.list_files()))
82
tree_conflicts = tree.conflicts()
83
self.assertLength(2, tree_conflicts)
84
self.assertTrue('hello' in tree_conflicts[0].path)
85
self.assertTrue('hello.sploo' in tree_conflicts[1].path)
86
conflicts.restore('hello')
87
conflicts.restore('hello.sploo')
88
self.assertLength(0, tree.conflicts())
89
self.assertFileEqual('hello world2', 'hello')
90
self.assertFalse(os.path.lexists('hello.sploo'))
91
self.assertRaises(errors.NotConflicted, conflicts.restore, 'hello')
92
self.assertRaises(errors.NotConflicted,
93
conflicts.restore, 'hello.sploo')
95
67
def test_resolve_conflict_dir(self):
96
68
tree = self.make_branch_and_tree('.')
97
69
self.build_tree_contents([('hello', 'hello world4'),
342
class TestResolveTextConflicts(TestParametrizedResolveConflicts):
344
_conflict_type = conflicts.TextConflict
346
# Set by the scenarios
347
# path and file-id for the file involved in the conflict
351
scenarios = mirror_scenarios(
353
# File modified on both sides
354
(dict(_base_actions='create_file',
355
_path='file', _file_id='file-id'),
357
dict(actions='modify_file_A', check='file_has_content_A')),
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')),
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'))]
374
def do_modify_file_A(self):
375
return [('modify', ('file-id', 'trunk content\nfeature A\n'))]
377
def do_modify_file_B(self):
378
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')
398
def _get_resolve_path_arg(self, wt, action):
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
375
407
class TestResolveContentsConflict(TestParametrizedResolveConflicts):
377
409
_conflict_type = conflicts.ContentsConflict
390
422
dict(actions='modify_file', check='file_has_more_content')),
392
424
dict(actions='delete_file', check='file_doesnt_exist')),),
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')),),
395
436
def do_create_file(self):
407
448
def check_file_doesnt_exist(self):
408
449
self.failIfExists('branch/file')
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'))]
455
def do_modify_file_in_dir(self):
456
return [('modify', ('file-id', 'trunk content\nmore content\n'))]
458
def check_file_in_dir_has_more_content(self):
459
self.assertFileEqual('trunk content\nmore content\n', 'branch/dir/file')
461
def check_file_in_dir_doesnt_exist(self):
462
self.failIfExists('branch/dir/file')
410
464
def _get_resolve_path_arg(self, wt, action):
411
465
return self._path
438
492
# PathConflicts deletion handling requires a special
439
493
# hard-coded value
440
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')),
501
dict(actions='delete_file', check='file_in_dir_doesnt_exist',
502
# PathConflicts deletion handling requires a special
504
path='<deleted>', file_id='file-id')),),
441
505
# File renamed/renamed differently
442
506
(dict(_base_actions='create_file'),
512
576
def check_dir_doesnt_exist(self):
513
577
self.failIfExists('branch/dir')
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'))]
583
def do_rename_file_in_dir(self):
584
return [('rename', ('dir/file', 'dir/new-file'))]
586
def check_file_in_dir_renamed(self):
587
self.failIfExists('branch/dir/file')
588
self.failUnlessExists('branch/dir/new-file')
590
def check_file_in_dir_doesnt_exist(self):
591
self.failIfExists('branch/dir/file')
515
593
def _get_resolve_path_arg(self, wt, action):
516
594
tpath = self._this['path']
517
595
opath = self._other['path']