Skip to content

Commit

Permalink
diff: account for deleted workspace data (iterative#5205)
Browse files Browse the repository at this point in the history
* diff: add test for deleted data in addition to .dvc file

* diff: handle deleted data when checking for missing cache
  • Loading branch information
pmrowla authored Jan 5, 2021
1 parent b779a11 commit 37f8904
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions dvc/repo/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,14 @@ def _dir_output_paths(repo_tree, output, targets=None):
def _filter_missing(repo, paths):
repo_tree = RepoTree(repo, stream=True)
for path in paths:
metadata = repo_tree.metadata(path)
if metadata.is_dvc:
out = metadata.outs[0]
if out.status().get(str(out)) == "not in cache":
yield path
try:
metadata = repo_tree.metadata(path)
if metadata.is_dvc:
out = metadata.outs[0]
if out.status().get(str(out)) == "not in cache":
yield path
except FileNotFoundError:
pass


def _targets_to_path_infos(repo, targets):
Expand Down
5 changes: 4 additions & 1 deletion tests/func/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,12 @@ def test_no_cache_entry(tmp_dir, scm, dvc):
}


def test_deleted(tmp_dir, scm, dvc):
@pytest.mark.parametrize("delete_data", [True, False])
def test_deleted(tmp_dir, scm, dvc, delete_data):
tmp_dir.dvc_gen("file", "text", commit="add file")
(tmp_dir / "file.dvc").unlink()
if delete_data:
(tmp_dir / "file").unlink()

assert dvc.diff() == {
"added": [],
Expand Down

0 comments on commit 37f8904

Please sign in to comment.