From 90b919325043b3ab95e17253065f4cba9170ad9e Mon Sep 17 00:00:00 2001 From: Peter Rowlands Date: Thu, 22 Jun 2023 15:32:57 +0900 Subject: [PATCH] output: preserve legacy hash_name on save() for unchanged data --- dvc/output.py | 2 +- tests/func/test_commit.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dvc/output.py b/dvc/output.py index 7003d4717..4e86d6f98 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -692,7 +692,7 @@ class Output: if self.metric: self.verify_metric() - if self.hash_name == "md5-dos2unix": + if self.hash_name == "md5-dos2unix" and self.changed_checksum(): self.hash_name = "md5" if self.use_cache: _, self.meta, self.obj = build( diff --git a/tests/func/test_commit.py b/tests/func/test_commit.py index 962fd58b1..2c91dab61 100644 --- a/tests/func/test_commit.py +++ b/tests/func/test_commit.py @@ -316,9 +316,12 @@ def test_commit_dos2unix(tmp_dir, dvc): } ) legacy_content = (tmp_dir / "foo.dvc").read_text() + assert "hash: md5" not in legacy_content - dvc.commit("foo.dvc") + dvc.commit("foo.dvc", force=True) assert (tmp_dir / "foo.dvc").read_text() == legacy_content + + tmp_dir.gen("foo", "modified") dvc.commit("foo.dvc", force=True) content = (tmp_dir / "foo.dvc").read_text() assert "hash: md5" in content