318
320
def _get_check(self, name):
319
321
return getattr(self, 'check_%s' % name)
321
def assertConflict(self, wt):
322
confs = wt.conflicts()
323
self.assertLength(1, confs)
325
self.assertIsInstance(c, self._conflict_type)
326
self._assert_conflict(wt, c)
328
def check_resolved(self, wt, path, action):
329
conflicts.resolve(wt, [path], action=action)
330
# Check that we don't have any conflicts nor unknown left
331
self.assertLength(0, wt.conflicts())
332
self.assertLength(0, list(wt.unknowns()))
323
def do_nothing(self):
324
return (None, None, [])
334
326
def do_create_file(self):
335
327
return ('file', 'file-id',
336
328
[('add', ('file', 'file-id', 'file', 'trunk content\n'))])
330
def do_create_file_a(self):
331
return ('file', 'file-a-id',
332
[('add', ('file', 'file-a-id', 'file', 'file a content\n'))])
334
def check_file_content_a(self):
335
self.assertFileEqual('file a content\n', 'branch/file')
337
def do_create_file_b(self):
338
return ('file', 'file-b-id',
339
[('add', ('file', 'file-b-id', 'file', 'file b content\n'))])
341
def check_file_content_b(self):
342
self.assertFileEqual('file b content\n', 'branch/file')
338
344
def do_create_dir(self):
339
345
return ('dir', 'dir-id', [('add', ('dir', 'dir-id', 'directory', ''))])
384
397
wt.merge_from_branch(b, 'other')
400
def assertConflict(self, wt):
401
confs = wt.conflicts()
402
self.assertLength(1, confs)
404
self.assertIsInstance(c, self._conflict_type)
405
self._assert_conflict(wt, c)
407
def _get_resolve_path_arg(self, wt, action):
408
return self._item_path
410
def check_resolved(self, wt, action):
411
path = self._get_resolve_path_arg(wt, action)
412
conflicts.resolve(wt, [path], action=action)
413
# Check that we don't have any conflicts nor unknown left
414
self.assertLength(0, wt.conflicts())
415
self.assertLength(0, list(wt.unknowns()))
387
417
def test_resolve_taking_this(self):
388
418
wt = self._merge_other_into_this()
389
419
self.assertConflict(wt)
390
self.check_resolved(wt, self._item_path, 'take_this')
420
self.check_resolved(wt, 'take_this')
391
421
check_this = self._get_check(self._check_this)
394
424
def test_resolve_taking_other(self):
395
425
wt = self._merge_other_into_this()
396
426
self.assertConflict(wt)
397
self.check_resolved(wt, self._item_path, 'take_other')
427
self.check_resolved(wt, 'take_other')
398
428
check_other = self._get_check(self._check_other)
432
458
def scenarios(klass):
433
for_dirs = dict(_actions_base='create_dir',
459
for_file = dict(_actions_base='create_file',
460
_item_path='new-file', _item_id='file-id',)
461
for_dir = dict(_actions_base='create_dir',
434
462
_item_path='new-dir', _item_id='dir-id',)
435
463
base_scenarios = [
436
464
(('file_renamed',
437
465
dict(actions='rename_file', check='file_renamed')),
439
467
dict(actions='delete_file', check='file_doesnt_exist')),
440
dict(_actions_base='create_file',
441
_item_path='new-file', _item_id='file-id',)),
470
dict(actions='rename_file', check='file_renamed')),
472
dict(actions='rename_file2', check='file_renamed2')),
443
475
dict(actions='rename_dir', check='dir_renamed')),
445
477
dict(actions='delete_dir', check='dir_doesnt_exist')),
448
480
dict(actions='rename_dir', check='dir_renamed')),
450
482
dict(actions='rename_dir2', check='dir_renamed2')),
453
485
return klass.mirror_scenarios(base_scenarios)
478
510
wt.set_conflicts(conflicts.ConflictList([old_c]))
481
class TestResolveDuplicateEntry(TestResolveConflicts):
486
$ echo 'trunk content' >file
488
$ bzr commit -m 'Create trunk'
490
$ echo 'trunk content too' >file2
492
$ bzr commit -m 'Add file2 in trunk'
494
$ bzr branch . -r 1 ../branch
496
$ echo 'branch content' >file2
498
$ bzr commit -m 'Add file2 in branch'
502
2>R file2 => file2.moved
503
2>Conflict adding file file2. Moved existing file to file2.moved.
504
2>1 conflicts encountered.
507
def test_keep_this(self):
509
$ bzr rm file2 --force
510
$ bzr mv file2.moved file2
512
$ bzr commit --strict -m 'No more conflicts nor unknown files'
515
def test_keep_other(self):
516
self.failIfExists('branch/file2.moved')
518
$ bzr rm file2.moved --force
520
$ bzr commit --strict -m 'No more conflicts nor unknown files'
522
self.failIfExists('branch/file2.moved')
524
def test_resolve_taking_this(self):
526
$ bzr resolve --take-this file2
527
$ bzr commit --strict -m 'No more conflicts nor unknown files'
530
def test_resolve_taking_other(self):
532
$ bzr resolve --take-other file2
533
$ bzr commit --strict -m 'No more conflicts nor unknown files'
513
class TestResolveDuplicateEntry(TestParametrizedResolveConflicts):
515
_conflict_type = conflicts.DuplicateEntry,
517
def scenarios(klass):
519
(('filea_created', dict(actions='create_file_a',
520
check='file_content_a')),
521
('fileb_created', dict(actions='create_file_b',
522
check='file_content_b')),
523
dict(_actions_base='nothing', _item_path='file')),
525
return klass.mirror_scenarios(base_scenarios)
527
def assertDuplicateEntry(self, wt, c):
528
self.assertEqual(self._this_id, c.file_id)
529
self.assertEqual(self._item_path + '.moved', c.path)
530
self.assertEqual(self._item_path, c.conflict_path)
531
_assert_conflict = assertDuplicateEntry
537
534
class TestResolveUnversionedParent(TestResolveConflicts):
704
class OldTestResolvePathConflict(TestResolveConflicts):
711
$ bzr commit -m 'Create trunk'
713
$ bzr mv file file-in-trunk
714
$ bzr commit -m 'Renamed to file-in-trunk'
716
$ bzr branch . -r 1 ../branch
718
$ bzr mv file file-in-branch
719
$ bzr commit -m 'Renamed to file-in-branch'
722
2>R file-in-branch => file-in-trunk
723
2>Path conflict: file-in-branch / file-in-trunk
724
2>1 conflicts encountered.
727
def test_keep_source(self):
729
$ bzr resolve file-in-trunk
730
$ bzr commit --strict -m 'No more conflicts nor unknown files'
733
def test_keep_target(self):
735
$ bzr mv file-in-trunk file-in-branch
736
$ bzr resolve file-in-branch
737
$ bzr commit --strict -m 'No more conflicts nor unknown files'
740
def test_resolve_taking_this(self):
742
$ bzr resolve --take-this file-in-branch
743
$ bzr commit --strict -m 'No more conflicts nor unknown files'
746
def test_resolve_taking_other(self):
748
$ bzr resolve --take-other file-in-branch
749
$ bzr commit --strict -m 'No more conflicts nor unknown files'
753
class TestResolveParentLoop(TestResolveConflicts):
701
class TestResolveParentLoop(TestParametrizedResolveConflicts):
703
_conflict_type = conflicts.ParentLoop,
705
def scenarios(klass):
707
(('dir1_into_dir2', dict(actions='move_dir1_into_dir2',
708
check='dir1_moved')),
709
('dir2_into_dir1', dict(actions='move_dir2_into_dir1',
710
check='dir2_moved')),
711
dict(_actions_base='create_dir1_dir2')),
712
(('dir1_into_dir4', dict(actions='move_dir1_into_dir4',
713
check='dir1_2_moved')),
714
('dir3_into_dir2', dict(actions='move_dir3_into_dir2',
715
check='dir3_4_moved')),
716
dict(_actions_base='create_dir1_4')),
718
return klass.mirror_scenarios(base_scenarios)
720
def do_create_dir1_dir2(self):
722
[('add', ('dir1', 'dir1-id', 'directory', '')),
723
('add', ('dir2', 'dir2-id', 'directory', '')),
726
def do_move_dir1_into_dir2(self):
727
# The arguments are the file-id to move and the targeted file-id dir.
728
return ('dir1-id', 'dir2-id', [('rename', ('dir1', 'dir2/dir1'))])
730
def check_dir1_moved(self):
731
self.failIfExists('branch/dir1')
732
self.failUnlessExists('branch/dir2/dir1')
734
def do_move_dir2_into_dir1(self):
735
# The arguments are the file-id to move and the targeted file-id dir.
736
return ('dir2-id', 'dir1-id', [('rename', ('dir2', 'dir1/dir2'))])
738
def check_dir2_moved(self):
739
self.failIfExists('branch/dir2')
740
self.failUnlessExists('branch/dir1/dir2')
742
def do_create_dir1_4(self):
744
[('add', ('dir1', 'dir1-id', 'directory', '')),
745
('add', ('dir1/dir2', 'dir2-id', 'directory', '')),
746
('add', ('dir3', 'dir3-id', 'directory', '')),
747
('add', ('dir3/dir4', 'dir4-id', 'directory', '')),
750
def do_move_dir1_into_dir4(self):
751
# The arguments are the file-id to move and the targeted file-id dir.
752
return ('dir1-id', 'dir4-id',
753
[('rename', ('dir1', 'dir3/dir4/dir1'))])
755
def check_dir1_2_moved(self):
756
self.failIfExists('branch/dir1')
757
self.failUnlessExists('branch/dir3/dir4/dir1')
758
self.failUnlessExists('branch/dir3/dir4/dir1/dir2')
760
def do_move_dir3_into_dir2(self):
761
# The arguments are the file-id to move and the targeted file-id dir.
762
return ('dir3-id', 'dir2-id',
763
[('rename', ('dir3', 'dir1/dir2/dir3'))])
765
def check_dir3_4_moved(self):
766
self.failIfExists('branch/dir3')
767
self.failUnlessExists('branch/dir1/dir2/dir3')
768
self.failUnlessExists('branch/dir1/dir2/dir3/dir4')
770
def _get_resolve_path_arg(self, wt, action):
771
# ParentLoop is unsual as it says:
772
# moving <conflict_path> into <path>. Cancelled move.
773
# But since <path> doesn't exist in the working tree, we need to use
774
# <conflict_path> instead
775
path = wt.id2path(self._other_id)
778
def assertParentLoop(self, wt, c):
779
if 'taking_other(' in self.id() and 'dir4' in self.id():
780
raise tests.KnownFailure(
781
"ParentLoop doesn't carry enough info to resolve")
782
# The relevant file-ids are other_args swapped (which is the main
783
# reason why they should be renamed other_args instead of Other_path
784
# and other_id). In the conflict object, they represent:
785
# c.file_id: the directory being moved
786
# c.conflict_id_id: The target directory
787
self.assertEqual(self._other_path, c.file_id)
788
self.assertEqual(self._other_id, c.conflict_file_id)
789
# The conflict paths are irrelevant (they are deterministic but not
790
# worth checking since they don't provide the needed information
792
_assert_conflict = assertParentLoop
795
class OldTestResolveParentLoop(TestResolveConflicts):