diff --git a/dvc/repo/index.py b/dvc/repo/index.py index da8f73c7c..d6bee8489 100644 --- a/dvc/repo/index.py +++ b/dvc/repo/index.py @@ -526,9 +526,9 @@ def build_data_index( out_entry = DataIndexEntry(path=out_path, fs=fs) out_entry.key = key + data.add(out_entry) if not out_entry.meta or not out_entry.meta.isdir: - data.add(out_entry) continue for entry in build_entries( @@ -546,8 +546,7 @@ def build_data_index( tree_meta, tree = build_tree(data, key) out_entry.meta = tree_meta out_entry.hash_info = tree.hash_info - - out_entry.loaded = True - data.add(out_entry) + out_entry.loaded = True + data.add(out_entry) return data diff --git a/tests/func/test_data_status.py b/tests/func/test_data_status.py index e5a263c12..fa6c4a3ee 100644 --- a/tests/func/test_data_status.py +++ b/tests/func/test_data_status.py @@ -442,3 +442,18 @@ def test_root_from_file_to_dir(M, tmp_dir, dvc, scm): }, "git": M.dict(), } + + +def test_empty_dir(tmp_dir, scm, dvc, M): + # regression testing for https://github.com/iterative/dvc/issues/8958 + tmp_dir.dvc_gen({"data": {"foo": "foo"}}) + remove("data") + + (tmp_dir / "data").mkdir() + + assert dvc.data_status() == { + **EMPTY_STATUS, + "committed": {"added": [join("data", "")]}, + "uncommitted": {"modified": [join("data", "")]}, + "git": M.dict(), + }