commit: make sure deps/outs exist (#4305)

Fixes #4266
This commit is contained in:
Ruslan Kuprieiev
2020-07-30 16:09:00 +03:00
committed by GitHub
parent 815444ffdc
commit 9592246746
4 changed files with 33 additions and 6 deletions
+4 -1
View File
@@ -67,7 +67,7 @@ class RepoDependency(LocalDependency):
return self.repo.cache.local.tree.get_hash(path, tree=tree)
return tree.get_file_hash(path)
def status(self):
def workspace_status(self):
current_checksum = self._get_checksum(locked=True)
updated_checksum = self._get_checksum(locked=False)
@@ -76,6 +76,9 @@ class RepoDependency(LocalDependency):
return {}
def status(self):
return self.workspace_status()
def save(self):
pass
+8 -4
View File
@@ -199,10 +199,7 @@ class BaseOutput:
return self.cache.changed_cache(self.checksum, filter_info=filter_info)
def status(self):
if self.checksum and self.use_cache and self.changed_cache():
return {str(self): "not in cache"}
def workspace_status(self):
if not self.exists:
return {str(self): "deleted"}
@@ -214,6 +211,12 @@ class BaseOutput:
return {}
def status(self):
if self.checksum and self.use_cache and self.changed_cache():
return {str(self): "not in cache"}
return self.workspace_status()
def changed(self):
status = self.status()
logger.debug(str(status))
@@ -280,6 +283,7 @@ class BaseOutput:
self.info = self.save_info()
def commit(self):
assert self.info
if self.use_cache:
self.cache.save(self.path_info, self.cache.tree, self.info)
+1 -1
View File
@@ -396,7 +396,7 @@ class Stage(params.StageParams):
@staticmethod
def _changed_entries(entries):
return [str(entry) for entry in entries if entry.changed_checksum()]
return [str(entry) for entry in entries if entry.workspace_status()]
def _changed_stage_entry(self):
return f"'md5' of {self} changed."
+20
View File
@@ -2,7 +2,9 @@ from os import fspath
import pytest
from dvc.dependency.base import DependencyDoesNotExistError
from dvc.dvcfile import PIPELINE_FILE
from dvc.output.base import OutputDoesNotExistError
from dvc.stage.exceptions import StageCommitError
from dvc.utils.yaml import dump_yaml, load_yaml
@@ -86,6 +88,24 @@ def test_commit_no_exec(tmp_dir, dvc):
assert dvc.status(stage.path) == {}
def test_commit_no_exec_missing_dep(tmp_dir, dvc):
stage = dvc.run(
name="my", cmd="mycmd", deps=["dep"], outs=["out"], no_exec=True
)
assert dvc.status(stage.path)
with pytest.raises(DependencyDoesNotExistError):
dvc.commit(stage.path, force=True)
def test_commit_no_exec_missing_out(tmp_dir, dvc):
stage = dvc.run(name="my", cmd="mycmd", outs=["out"], no_exec=True)
assert dvc.status(stage.path)
with pytest.raises(OutputDoesNotExistError):
dvc.commit(stage.path, force=True)
def test_commit_pipeline_stage(tmp_dir, dvc, run_copy):
tmp_dir.gen("foo", "foo")
stage = run_copy("foo", "bar", no_commit=True, name="copy-foo-bar")