From 286153a6090df926e435d435429d19d87d2da15a Mon Sep 17 00:00:00 2001 From: Emil Gotsev Date: Tue, 17 Apr 2018 12:21:32 +0300 Subject: [PATCH] Proper adding of 'directory/' * added a test for adding single level directory with forward slash in the end * normalizing the path that is passed to the add method --- dvc/project.py | 2 +- tests/test_add.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/dvc/project.py b/dvc/project.py index 71f943f84..4a3ff8f63 100644 --- a/dvc/project.py +++ b/dvc/project.py @@ -80,7 +80,7 @@ class Project(object): return os.path.relpath(path, self.root_dir) def add(self, fname): - out = os.path.basename(fname) + out = os.path.basename(os.path.normpath(fname)) stage_fname = out + Stage.STAGE_FILE_SUFFIX cwd = os.path.dirname(os.path.abspath(fname)) stage = Stage.loads(project=self, diff --git a/tests/test_add.py b/tests/test_add.py index ad025d12e..b9e6a3a8c 100644 --- a/tests/test_add.py +++ b/tests/test_add.py @@ -49,6 +49,13 @@ class TestAddDirectory(TestDvc): self.create(os.path.join(dname, 'file'), 'file') self.dvc.add(dname) +class TestAddDirectoryWithForwardSlash(TestDvc): + def test(self): + dname = 'directory/' + os.mkdir(dname) + self.create(os.path.join(dname, 'file'), 'file') + stage = self.dvc.add(dname) + self.assertEquals(os.path.abspath('directory.dvc'), stage.path) class TestAddTrackedFile(TestDvc): def test(self):