Fix error during external outputs checkout (#4570)

* Fix error during external outputs checkout

User in discord complained that external outputs' checkout
was failing. Looks like, during refactor of `HashInfo`,
this was forgotten, and as no tests existed before, we had
a regression from 1.6.5 onwards.

* fix tests

* Restyled by black (#4571)

Co-authored-by: Restyled.io <[email protected]>

Co-authored-by: restyled-io[bot] <32688539+restyled-io[bot]@users.noreply.github.com>
Co-authored-by: Restyled.io <[email protected]>
This commit is contained in:
Saugat Pachhai
2020-09-15 11:07:09 +03:00
committed by GitHub
co-authored by Restyled.io restyled-io[bot]
parent 4ebacf1e0a
commit 01abf7c19c
3 changed files with 21 additions and 6 deletions
+1 -1
View File
@@ -414,7 +414,7 @@ class CloudCache:
return self.changed_cache_file(hash_info)
def already_cached(self, path_info):
_, current = self.tree.get_hash(path_info)
current = self.tree.get_hash(path_info)
if not current:
return False
+1 -5
View File
@@ -94,11 +94,7 @@ class LocalCache(CloudCache):
def already_cached(self, path_info):
assert path_info.scheme in ["", "local"]
current = self.tree.get_hash(path_info)
if not current:
return False
return not self.changed_cache(current)
return super().already_cached(path_info)
def _verify_link(self, path_info, link_type):
if link_type == "hardlink" and self.tree.getsize(path_info) == 0:
+19
View File
@@ -850,3 +850,22 @@ def test_checkouts_for_pipeline_tracked_outs(tmp_dir, dvc, scm, run_copy):
(tmp_dir / "ipsum").unlink()
assert set(dvc.checkout()["added"]) == {"bar", "ipsum"}
@pytest.mark.parametrize(
"workspace", [pytest.lazy_fixture("s3")], indirect=True
)
def test_checkout_external_modified_file(tmp_dir, dvc, scm, mocker, workspace):
# regression: happened when file in external output changed and checkout
# was attempted without force, dvc checks if it's present in its cache
# before asking user to remove it.
workspace.gen("foo", "foo")
dvc.add(str(workspace / "foo"), external=True)
scm.add(["foo.dvc"])
scm.commit("add foo")
workspace.gen("foo", "foobar") # messing up the external outputs
mocker.patch("dvc.prompt.confirm", return_value=True)
dvc.checkout()
assert (workspace / "foo").read_text() == "foo"