mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
move: move directory into an existing directory
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
|
||||
+15
-7
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user