status: add unknown state

This commit is contained in:
Saugat Pachhai (सौगात)
2022-08-25 13:23:18 +03:00
committed by Ruslan Kuprieiev
parent 5cf1421c61
commit 2374c72105
3 changed files with 28 additions and 6 deletions
+1
View File
@@ -51,6 +51,7 @@ class CmdDataStatus(CmdBase):
file: state
for state, files in stage_status.items()
for file in files
if state != "unknown"
}
if not items:
continue
+17 -3
View File
@@ -99,8 +99,20 @@ def _granular_diff(
return dict(output)
def _get_obj_items(root: str, obj: Optional["HashFile"]) -> List[str]:
if not obj:
return []
from dvc_data.objects.tree import Tree
sep = os.path.sep
if isinstance(obj, Tree):
return [sep.join([root, *key]) for key, _, _ in obj]
return [root]
def _diff(
root,
root: str,
old_oid: Optional["HashInfo"],
old_obj: Optional["HashFile"],
new_oid: Optional["HashInfo"],
@@ -108,12 +120,14 @@ def _diff(
odb: "HashFileDB",
with_dirs: bool = False,
granular: bool = False,
):
) -> Dict[str, List[str]]:
if not granular:
return _shallow_diff(root, old_oid, new_oid, odb)
if (old_oid and not old_obj) or (new_oid and not new_obj):
# we don't have enough information to give full details
return _shallow_diff(root, old_oid, new_oid, odb)
unknown = _get_obj_items(root, new_obj or old_obj)
shallow_diff = _shallow_diff(root, old_oid, new_oid, odb)
return {**shallow_diff, "unknown": unknown}
return _granular_diff(root, old_obj, new_obj, odb, with_dirs=with_dirs)
+10 -3
View File
@@ -171,7 +171,6 @@ def test_missing_cache_workspace_exists(M, tmp_dir, dvc, scm):
**EMPTY_STATUS,
"untracked": M.unordered("foobar.dvc", "dir.dvc", ".gitignore"),
"committed": {"added": M.unordered("foobar", join("dir", ""))},
"uncommitted": {},
"not_in_cache": M.unordered("foobar", join("dir", "")),
"git": M.dict(),
}
@@ -184,7 +183,9 @@ def test_missing_cache_workspace_exists(M, tmp_dir, dvc, scm):
# "foobar", join("dir", "foo"), join("dir", "bar")
# )},
"committed": {"added": M.unordered("foobar", join("dir", ""))},
"uncommitted": {},
"uncommitted": {
"unknown": M.unordered(join("dir", "foo"), join("dir", "bar"))
},
# even though we don't have cache obj, we can repurpose
# what we have in the workspace
"not_in_cache": M.unordered(
@@ -238,6 +239,9 @@ def test_git_committed_missing_cache_workspace_exists(M, tmp_dir, dvc, scm):
"foobar",
join("dir", ""),
),
"uncommitted": {
"unknown": M.unordered(join("dir", "foo"), join("dir", "bar"))
},
"git": M.dict(),
# TODO: clarify what is unchanged
"unchanged": M.unordered("foobar", join("dir", "")),
@@ -303,7 +307,10 @@ def test_missing_dir_object_from_head(M, tmp_dir, dvc, scm):
}
assert dvc.data_status(granular=True) == {
**EMPTY_STATUS,
"committed": {"modified": [join("dir", "")]},
"committed": {
"modified": [join("dir", "")],
"unknown": [join("dir", "foobar")],
},
"git": M.dict(),
}