From ad8334642e84dc9f48aefd4c622d74d7ef6e89c7 Mon Sep 17 00:00:00 2001 From: David de la Iglesia Castro Date: Tue, 24 Jan 2023 18:26:54 +0100 Subject: [PATCH] stage.save: Remove `merge_versioned` option. If we want `add`, `commit` and `move` to work for cloud versioning, option must be always True so it is the same as not having it. Closes #8828 (We were not passing `merge_versioned=True` in `dvc commit`) --- dvc/repo/add.py | 2 +- dvc/repo/worktree.py | 2 +- dvc/stage/__init__.py | 43 ++++++++++++----------------- tests/func/test_commit.py | 58 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 28 deletions(-) diff --git a/dvc/repo/add.py b/dvc/repo/add.py index 761aa624be..d662c41974 100644 --- a/dvc/repo/add.py +++ b/dvc/repo/add.py @@ -194,7 +194,7 @@ def add( # noqa: C901 stage.transfer(source, to_remote=to_remote, odb=odb, **kwargs) else: try: - stage.save(merge_versioned=True) + stage.save() if not no_commit: stage.commit() except CacheLinkError: diff --git a/dvc/repo/worktree.py b/dvc/repo/worktree.py index 9336044076..46470d87de 100644 --- a/dvc/repo/worktree.py +++ b/dvc/repo/worktree.py @@ -228,7 +228,7 @@ def outs_filter(out: "Output") -> bool: ) continue _fetch_out_changes(out, local_index, remote_index, remote) - stage.save(merge_versioned=True) + stage.save() for out in stage.outs: _update_out_meta(out, remote_index) stage.dump(with_files=True, update_pipeline=False) diff --git a/dvc/stage/__init__.py b/dvc/stage/__init__.py index e3eb38fcea..6e3e48391c 100644 --- a/dvc/stage/__init__.py +++ b/dvc/stage/__init__.py @@ -486,17 +486,11 @@ def compute_md5(self) -> Optional[str]: logger.debug("Computed %s md5: '%s'", self, m) return m - def save( - self, - allow_missing: bool = False, - merge_versioned: bool = False, - run_cache: bool = True, - ): + def save(self, allow_missing: bool = False, run_cache: bool = True): self.save_deps(allow_missing=allow_missing) - self.save_outs( - allow_missing=allow_missing, merge_versioned=merge_versioned - ) + self.save_outs(allow_missing=allow_missing) + self.md5 = self.compute_md5() if run_cache: @@ -512,29 +506,26 @@ def save_deps(self, allow_missing=False): if not allow_missing: raise - def save_outs( - self, allow_missing: bool = False, merge_versioned: bool = False - ): + def save_outs(self, allow_missing: bool = False): from dvc.output import OutputDoesNotExistError from .exceptions import StageFileDoesNotExistError, StageNotFound - if merge_versioned: - try: - old = self.reload() - old_outs = {out.def_path: out for out in old.outs} - merge_versioned = any( - ( - out.files is not None - or ( - out.meta is not None - and out.meta.version_id is not None - ) + try: + old = self.reload() + old_outs = {out.def_path: out for out in old.outs} + merge_versioned = any( + ( + out.files is not None + or ( + out.meta is not None + and out.meta.version_id is not None ) - for out in old_outs.values() ) - except (StageFileDoesNotExistError, StageNotFound): - merge_versioned = False + for out in old_outs.values() + ) + except (StageFileDoesNotExistError, StageNotFound): + merge_versioned = False for out in self.outs: try: diff --git a/tests/func/test_commit.py b/tests/func/test_commit.py index d58bce9088..89355e53f3 100644 --- a/tests/func/test_commit.py +++ b/tests/func/test_commit.py @@ -245,3 +245,61 @@ def test_imported_entries_unchanged(tmp_dir, dvc, erepo_dir): stage = dvc.imp(os.fspath(erepo_dir), "file") assert stage.changed_entries() == ([], [], None) + + +def test_commit_updates_to_cloud_versioning_dir(tmp_dir, dvc): + data_dvc = tmp_dir / "data.dvc" + data_dvc.dump( + { + "outs": [ + { + "path": "data", + "files": [ + { + "size": 3, + "version_id": "WYRG4BglP7pD.gEoJP6a4AqOhl.FRA.h", + "etag": "acbd18db4cc2f85cedef654fccc4a4d8", + "md5": "acbd18db4cc2f85cedef654fccc4a4d8", + "relpath": "bar", + }, + { + "size": 3, + "version_id": "0vL53tFVY5vVAoJ4HG2jCS1mEcohDPE0", + "etag": "acbd18db4cc2f85cedef654fccc4a4d8", + "md5": "acbd18db4cc2f85cedef654fccc4a4d8", + "relpath": "foo", + }, + ], + } + ] + } + ) + + data = tmp_dir / "data" + data.mkdir() + (data / "foo").write_text("foo") + (data / "bar").write_text("bar2") + + dvc.commit("data", force=True) + + assert (tmp_dir / "data.dvc").parse() == { + "outs": [ + { + "path": "data", + "files": [ + { + "size": 4, + "md5": "224e2539f52203eb33728acd228b4432", + "relpath": "bar", + }, + { + "size": 3, + "version_id": "0vL53tFVY5vVAoJ4HG2jCS1mEcohDPE0", + "etag": "acbd18db4cc2f85cedef654fccc4a4d8", + "md5": "acbd18db4cc2f85cedef654fccc4a4d8", + "relpath": "foo", + }, + ], + } + ] + }