index: build_data_index: handle empty dirs (#8959)

Fixes https://github.com/iterative/dvc/issues/8958
This commit is contained in:
Ruslan Kuprieiev
2023-02-06 01:44:15 +02:00
committed by GitHub
parent 4ec6d64629
commit 8e1b75feb5
2 changed files with 18 additions and 4 deletions
+3 -4
View File
@@ -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
+15
View File
@@ -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(),
}