Skip to content

Commit 79b9ae7

Browse files
authored
Merge pull request #1021 from efiop/master
dvc: properly resolve dvc name for external local files
2 parents adbfbfd + a46b1be commit 79b9ae7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

dvc/stage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ def _stage_fname_cwd(cls, fname, cwd, outs, add):
231231
if not fname:
232232
fname = path.basename(out.path) + cls.STAGE_FILE_SUFFIX
233233

234-
cwd = path.dirname(out.path) if not cwd or add else cwd
234+
if not cwd or (add and out.is_local):
235+
cwd = path.dirname(out.path)
235236

236237
return (fname, cwd)
237238

tests/test_add.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import os
22
import stat
33
import shutil
4+
import filecmp
5+
import tempfile
46

57
from dvc.main import main
68
from dvc.utils import file_md5
@@ -96,6 +98,22 @@ def test(self):
9698
self.assertEqual(stage.relpath, self.DATA_SUB + '.dvc')
9799

98100

101+
class TestAddExternalLocalFile(TestDvc):
102+
def test(self):
103+
dname = tempfile.mkdtemp()
104+
fname = os.path.join(dname, 'foo')
105+
shutil.copyfile(self.FOO, fname)
106+
107+
stage = self.dvc.add(fname)
108+
self.assertNotEqual(stage, None)
109+
self.assertEqual(len(stage.deps), 0)
110+
self.assertEqual(len(stage.outs), 1)
111+
self.assertEqual(stage.relpath, 'foo.dvc')
112+
self.assertEqual(len(os.listdir(dname)), 1)
113+
self.assertTrue(os.path.isfile(fname))
114+
self.assertTrue(filecmp.cmp(fname, 'foo', shallow=False))
115+
116+
99117
class TestCmdAdd(TestDvc):
100118
def test(self):
101119
ret = main(['add',

0 commit comments

Comments
 (0)