From d1a219df0a031c8b46113ba8ceb416fe94e95e18 Mon Sep 17 00:00:00 2001 From: yehiyam Date: Tue, 22 Jun 2021 13:12:20 +0300 Subject: [PATCH] repo: preserve meta field on move (#6201) fixes #6200 --- dvc/repo/move.py | 6 +++++- tests/func/test_move.py | 24 +++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dvc/repo/move.py b/dvc/repo/move.py index 0e0ec33d7..a4f1a7c14 100644 --- a/dvc/repo/move.py +++ b/dvc/repo/move.py @@ -62,7 +62,11 @@ def move(self, from_path, to_path): ) to_path = os.path.relpath(to_path, new_wdir) new_stage = self.stage.create( - single_stage=True, fname=new_fname, wdir=new_wdir, outs=[to_path] + single_stage=True, + fname=new_fname, + wdir=new_wdir, + outs=[to_path], + meta=stage.meta, ) os.unlink(stage.path) diff --git a/tests/func/test_move.py b/tests/func/test_move.py index 08c5b7037..468a9421e 100644 --- a/tests/func/test_move.py +++ b/tests/func/test_move.py @@ -1,11 +1,12 @@ import os +import textwrap import pytest from dvc.dvcfile import DVC_FILE_SUFFIX from dvc.exceptions import DvcException, MoveNotDataSourceError from dvc.main import main -from dvc.utils.serialize import load_yaml +from dvc.utils.serialize import dump_yaml, load_yaml from tests.basic_env import TestDvc, TestDvcGit from tests.func.test_repro import TestRepro from tests.utils import cd @@ -244,3 +245,24 @@ def test_move_output_overlap(tmp_dir, dvc): assert (tmp_dir / "foo.dvc").exists() assert not (tmp_dir / "dir" / "foo").exists() assert not (tmp_dir / "dir" / "foo.dvc").exists() + + +def test_move_meta(tmp_dir, dvc): + (stage,) = tmp_dir.dvc_gen("foo", "foo") + data = load_yaml(stage.path) + data["meta"] = {"custom_key": 42} + dump_yaml(stage.path, data) + + dvc.move("foo", "bar") + res = (tmp_dir / "bar.dvc").read_text() + print(res) + assert res == textwrap.dedent( + """\ + outs: + - md5: acbd18db4cc2f85cedef654fccc4a4d8 + size: 3 + path: bar + meta: + custom_key: 42 + """ + )