Ensure relpath accepts str and Path-like objects

This commit is contained in:
Aman Sharma
2020-01-02 02:17:02 +05:30
parent f6162fee47
commit f08c90fc6e
2 changed files with 12 additions and 5 deletions
+4 -5
View File
@@ -429,14 +429,13 @@ class State(object): # pylint: disable=too-many-instance-attributes
path_info (dict): path info to add to the list of links.
"""
assert path_info.scheme == "local"
path = fspath_py35(path_info)
if not os.path.exists(path):
if not os.path.exists(fspath_py35(path_info)):
return
mtime, _ = get_mtime_and_size(path, self.repo.tree)
inode = get_inode(path)
relative_path = relpath(path, self.root_dir)
mtime, _ = get_mtime_and_size(path_info, self.repo.tree)
inode = get_inode(path_info)
relative_path = relpath(path_info, self.root_dir)
cmd = "REPLACE INTO {}(path, inode, mtime) " "VALUES (?, ?, ?)".format(
self.LINK_STATE_TABLE
+8
View File
@@ -9,6 +9,7 @@ from dvc.utils import copyfile
from dvc.utils import file_md5
from dvc.utils import fix_env
from dvc.utils import makedirs
from dvc.utils import relpath
from dvc.utils import to_chunks
from dvc.utils import tmp_fname
from tests.basic_env import TestDir
@@ -139,3 +140,10 @@ def test_tmp_fname():
tmp_fname(file_path_info),
re.IGNORECASE,
)
def test_relpath():
path = "path"
path_info = PathInfo(path)
assert relpath(path) == relpath(path_info)