From 02cfe33cf9f51dae0008ce9a9c66292501bc3849 Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Thu, 11 Feb 2021 14:53:40 +0200 Subject: [PATCH] output: handle missing hash_info.nfiles (#5448) --- dvc/output/base.py | 2 +- tests/func/test_checkout.py | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dvc/output/base.py b/dvc/output/base.py index cd0473292..14877a012 100644 --- a/dvc/output/base.py +++ b/dvc/output/base.py @@ -468,7 +468,7 @@ class BaseOutput: return 1 if not filter_info or filter_info == self.path_info: - return self.hash_info.nfiles + return self.hash_info.nfiles or 0 if not self.hash_info.dir_info: return 0 diff --git a/tests/func/test_checkout.py b/tests/func/test_checkout.py index eab728675..686087841 100644 --- a/tests/func/test_checkout.py +++ b/tests/func/test_checkout.py @@ -4,6 +4,7 @@ import logging import os import shutil import stat +import textwrap import pytest from mock import patch @@ -23,7 +24,7 @@ from dvc.stage.exceptions import StageFileDoesNotExistError from dvc.system import System from dvc.tree.local import LocalTree from dvc.utils import relpath -from dvc.utils.fs import walk_files +from dvc.utils.fs import remove, walk_files from dvc.utils.serialize import dump_yaml, load_yaml from tests.basic_env import TestDvc, TestDvcGit from tests.func.test_repro import TestRepro @@ -989,3 +990,20 @@ def test_checkout_file(tmp_dir, dvc): os.unlink("foo") stats = dvc.checkout("foo") assert stats["added"] == ["foo"] + + +def test_checkout_dir_compat(tmp_dir, dvc): + (stage,) = tmp_dir.dvc_gen({"data": {"foo": "foo"}}) + tmp_dir.gen( + "data.dvc", + textwrap.dedent( + f"""\ + outs: + - md5: {stage.outs[0].hash_info.value} + path: data + """ + ), + ) + remove("data") + dvc.checkout() + assert (tmp_dir / "data").read_text() == {"foo": "foo"}