From 41b67c3730b3da4783099d16dfb660ac4208ebd6 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Sun, 14 Apr 2019 20:07:12 +0300 Subject: [PATCH] move: move directory into an existing directory Signed-off-by: Ruslan Kuprieiev --- dvc/repo/move.py | 2 +- tests/func/test_move.py | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/dvc/repo/move.py b/dvc/repo/move.py index 9240880a7..ab40dc64b 100644 --- a/dvc/repo/move.py +++ b/dvc/repo/move.py @@ -5,7 +5,7 @@ from dvc.repo.scm_context import scm_context def _expand_target_path(from_path, to_path): - if os.path.isdir(to_path) and not os.path.isdir(from_path): + if os.path.isdir(to_path): return os.path.join(to_path, os.path.basename(from_path)) return to_path diff --git a/tests/func/test_move.py b/tests/func/test_move.py index 0ad451115..ccf2d3937 100644 --- a/tests/func/test_move.py +++ b/tests/func/test_move.py @@ -124,23 +124,31 @@ class TestMoveFileToDirectoryWithoutSpecifiedTargetName(TestDvc): class TestMoveDirectoryShouldNotOverwriteExisting(TestDvc): def test(self): - new_dir_name = "data_dir2" - os.mkdir(new_dir_name) + dir_name = "dir" + orig_listdir = set(os.listdir(self.DATA_DIR)) + ret = main(["add", self.DATA_DIR]) self.assertEqual(ret, 0) - ret = main(["move", self.DATA_DIR, new_dir_name]) + os.mkdir(dir_name) + new_dir_name = os.path.join(dir_name, self.DATA_DIR) + + ret = main(["move", self.DATA_DIR, dir_name]) self.assertEqual(ret, 0) + data_dir_stage = self.DATA_DIR + Stage.STAGE_FILE_SUFFIX self.assertFalse(os.path.exists(self.DATA_DIR)) - self.assertFalse( - os.path.exists(self.DATA_DIR + Stage.STAGE_FILE_SUFFIX) + self.assertFalse(os.path.exists(data_dir_stage)) + + self.assertTrue(os.path.exists(dir_name)) + self.assertEqual( + set(os.listdir(dir_name)), + set([".gitignore", data_dir_stage, self.DATA_DIR]), ) self.assertTrue(os.path.exists(new_dir_name)) self.assertTrue(os.path.isfile(new_dir_name + Stage.STAGE_FILE_SUFFIX)) - - self.assertEqual(os.listdir(new_dir_name), [self.DATA_DIR]) + self.assertEqual(set(os.listdir(new_dir_name)), orig_listdir) class TestMoveFileBetweenDirectories(TestDvc):