From 651d92557867e2b2439c2c7cad317572ae49423b Mon Sep 17 00:00:00 2001 From: pawel Date: Wed, 4 Sep 2019 12:40:08 +0200 Subject: [PATCH] stage: don't unprotect outs on stage create --- dvc/stage.py | 2 -- tests/func/test_add.py | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dvc/stage.py b/dvc/stage.py index 142e94094..cc91c81e0 100644 --- a/dvc/stage.py +++ b/dvc/stage.py @@ -505,8 +505,6 @@ class Stage(object): stage.remove_outs(ignore_remove=False) logger.warning("Build cache is ignored when using --remove-outs.") ignore_build_cache = True - else: - stage.unprotect_outs() if os.path.exists(path) and any(out.persist for out in stage.outs): logger.warning("Build cache is ignored when persisting outputs.") diff --git a/tests/func/test_add.py b/tests/func/test_add.py index a9c52185c..6e7516c49 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -12,6 +12,7 @@ import posixpath import logging import colorama +from dvc.remote import RemoteLOCAL from dvc.system import System from mock import patch @@ -535,3 +536,20 @@ def test_windows_should_add_when_cache_on_different_drive( ret = main(["add", repo_dir.DATA]) assert ret == 0 + + +def test_readding_dir_should_not_unprotect_all(dvc_repo, repo_dir): + dvc_repo.cache.local.cache_types = ["symlink"] + dvc_repo.cache.local.protected = True + + dvc_repo.add(repo_dir.DATA_DIR) + new_file = os.path.join(repo_dir.DATA_DIR, "new_file") + + repo_dir.create(new_file, "new_content") + + unprotect_spy = spy(RemoteLOCAL.unprotect) + with patch.object(RemoteLOCAL, "unprotect", unprotect_spy): + dvc_repo.add(repo_dir.DATA_DIR) + + assert not unprotect_spy.mock.called + assert System.is_symlink(new_file)