From 82b0a3088fa316bb5b60a33ba4e052773476fa68 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 21 Feb 2022 03:52:40 +0200 Subject: [PATCH] dvcfs: handle repo root Fixes #7407 --- dvc/fs/dvc.py | 2 +- tests/unit/fs/test_dvc.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dvc/fs/dvc.py b/dvc/fs/dvc.py index 1a0b8d674..cbe457139 100644 --- a/dvc/fs/dvc.py +++ b/dvc/fs/dvc.py @@ -44,7 +44,7 @@ class DvcFileSystem(FileSystem): # pylint:disable=abstract-method fs_key = "repo" key = self.path.parts(path) - if key == (".",): + if key == (".",) or key == ("",): key = () return (fs_key, *key) diff --git a/tests/unit/fs/test_dvc.py b/tests/unit/fs/test_dvc.py index a183eb0c1..4dd7a9c0c 100644 --- a/tests/unit/fs/test_dvc.py +++ b/tests/unit/fs/test_dvc.py @@ -10,6 +10,20 @@ from dvc.hash_info import HashInfo from dvc.utils.fs import remove +@pytest.mark.parametrize( + "path, key", + [ + ("", ("repo",)), + (".", ("repo",)), + ("foo", ("repo", "foo")), + (os.path.join("dir", "foo"), ("repo", "dir", "foo")), + ], +) +def test_get_key(tmp_dir, dvc, path, key): + fs = DvcFileSystem(repo=dvc) + assert fs._get_key(path) == key + + def test_exists(tmp_dir, dvc): tmp_dir.gen("foo", "foo") dvc.add("foo")