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