472
472
expected_added=[('b',)])
475
class TestRenameTricky(TestCaseForGenericProcessor):
477
def file_command_iter(self, path1, old_path2, new_path2, kind='file'):
478
# Revno 1: create two files or symlinks in a directory
479
# Revno 2: rename the second file so that it implicitly deletes the
480
# first one because either:
481
# * the new file is a in directory with the old file name
482
# * the new file has the same name as the directory of the first
484
author = ['', 'bugs@a.com', time.time(), time.timezone]
485
committer = ['', 'elmer@a.com', time.time(), time.timezone]
487
yield commands.FileModifyCommand(path1, kind, False,
489
yield commands.FileModifyCommand(old_path2, kind, False,
491
yield commands.CommitCommand('head', '1', author,
492
committer, "commit 1", None, [], files_one)
494
yield commands.FileRenameCommand(old_path2, new_path2)
495
yield commands.CommitCommand('head', '2', author,
496
committer, "commit 2", ":1", [], files_two)
500
def test_rename_file_becomes_directory(self):
501
handler, branch = self.get_handler()
505
handler.process(self.file_command_iter(path1, old_path2, new_path2))
506
revtree0, revtree1 = self.assertChanges(branch, 1,
507
expected_added=[('a',), (path1,), (old_path2,)])
508
revtree1, revtree2 = self.assertChanges(branch, 2,
509
expected_renamed=[(old_path2, new_path2)],
510
expected_kind_changed=[(path1, 'file', 'directory')])
511
self.assertContent(branch, revtree1, path1, "aaa")
512
self.assertContent(branch, revtree2, new_path2, "bbb")
514
def test_rename_directory_becomes_file(self):
515
handler, branch = self.get_handler()
519
handler.process(self.file_command_iter(path1, old_path2, new_path2))
520
revtree0, revtree1 = self.assertChanges(branch, 1,
521
expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
522
revtree1, revtree2 = self.assertChanges(branch, 2,
523
expected_renamed=[(old_path2, new_path2)],
524
expected_removed=[(path1,), (new_path2,)])
525
self.assertContent(branch, revtree1, path1, "aaa")
526
self.assertContent(branch, revtree2, new_path2, "bbb")
528
def test_rename_symlink_becomes_directory(self):
529
handler, branch = self.get_handler()
533
handler.process(self.file_command_iter(path1, old_path2, new_path2,
535
revtree0, revtree1 = self.assertChanges(branch, 1,
536
expected_added=[('a',), (path1,), (old_path2,)])
537
revtree1, revtree2 = self.assertChanges(branch, 2,
538
expected_renamed=[(old_path2, new_path2)],
539
expected_kind_changed=[(path1, 'symlink', 'directory')])
540
self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
541
self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
543
def test_rename_directory_becomes_symlink(self):
544
handler, branch = self.get_handler()
548
handler.process(self.file_command_iter(path1, old_path2, new_path2,
550
revtree0, revtree1 = self.assertChanges(branch, 1,
551
expected_added=[('a',), ('a/b',), (path1,), (old_path2,)])
552
revtree1, revtree2 = self.assertChanges(branch, 2,
553
expected_renamed=[(old_path2, new_path2)],
554
expected_removed=[(path1,), (new_path2,)])
555
self.assertSymlinkTarget(branch, revtree1, path1, "aaa")
556
self.assertSymlinkTarget(branch, revtree2, new_path2, "bbb")
475
559
class TestCopy(TestCaseForGenericProcessor):
477
561
def file_command_iter(self, src_path, dest_path, kind='file'):