From 2374c721055efc73696a28a39e96656c36ec2985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Wed, 24 Aug 2022 19:12:05 +0545 Subject: [PATCH] status: add unknown state --- dvc/commands/data.py | 1 + dvc/repo/data.py | 20 +++++++++++++++++--- tests/func/test_data_status.py | 13 ++++++++++--- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/dvc/commands/data.py b/dvc/commands/data.py index 6a98acaeb..e26899fc4 100644 --- a/dvc/commands/data.py +++ b/dvc/commands/data.py @@ -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 diff --git a/dvc/repo/data.py b/dvc/repo/data.py index 4c5311a48..26884c25b 100644 --- a/dvc/repo/data.py +++ b/dvc/repo/data.py @@ -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) diff --git a/tests/func/test_data_status.py b/tests/func/test_data_status.py index 47b54d979..89f9a15a7 100644 --- a/tests/func/test_data_status.py +++ b/tests/func/test_data_status.py @@ -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(), }