Repository: iterative/dvc

Issue:
get/import: shoudln't use cache.type configured in the external repo
> Looks like we have a bug, where dvc tries to use link type that is configured for the external repo, instead of using reflink or copy for get. Same with import, where it should use link type from the repo you are importing into.

https://discuss.dvc.org/t/dvc-get-doesnt-work-with-absolute-paths-but-everything-else-seems-to/249/6


Discussion:

Resolving patch:
diff --git a/dvc/repo/get.py b/dvc/repo/get.py
--- a/dvc/repo/get.py
+++ b/dvc/repo/get.py
@@ -3,7 +3,6 @@
 
 import shortuuid
 
-from dvc.config import Config
 from dvc.exceptions import GetDVCFileError
 from dvc.exceptions import NotDvcRepoError
 from dvc.exceptions import OutputNotFoundError
@@ -48,11 +47,7 @@ def get(url, path, out=None, rev=None):
             #
             # Also, we can't use theoretical "move" link type here, because
             # the same cache file might be used a few times in a directory.
-            repo.config.set(
-                Config.SECTION_CACHE,
-                Config.SECTION_CACHE_TYPE,
-                "reflink,hardlink,copy",
-            )
+            repo.cache.local.cache_types = ["reflink", "hardlink", "copy"]
 
             o = repo.find_out_by_relpath(path)
             with repo.state:


Test patch:
diff --git a/tests/func/test_gc.py b/tests/func/test_gc.py
--- a/tests/func/test_gc.py
+++ b/tests/func/test_gc.py
@@ -188,10 +188,10 @@ def add_and_commit():
     cache_dir = os.path.join(dvc_repo.root_dir, ".dvc", "cache")
     testfile = pathlib.Path("testfile")
 
-    testfile.write_text("uncommited")
+    testfile.write_text("uncommitted")
     dvc_repo.add(str(testfile))
 
-    testfile.write_text("commited")
+    testfile.write_text("committed")
     add_and_commit()
 
     testfile.write_text("modified")
@@ -200,12 +200,12 @@ def add_and_commit():
     testfile.write_text("workspace")
     dvc_repo.add(str(testfile))
 
-    N = _count_files(cache_dir)
+    n = _count_files(cache_dir)
 
     dvc_repo.gc(all_commits=True)
 
-    # Only one uncommited file should go away
-    assert _count_files(cache_dir) == N - 1
+    # Only one uncommitted file should go away
+    assert _count_files(cache_dir) == n - 1
 
 
 def _count_files(path):
diff --git a/tests/func/test_get.py b/tests/func/test_get.py
--- a/tests/func/test_get.py
+++ b/tests/func/test_get.py
@@ -5,9 +5,11 @@
 
 import pytest
 
+from dvc.config import Config
 from dvc.exceptions import GetDVCFileError
 from dvc.exceptions import UrlNotDvcRepoError
 from dvc.repo import Repo
+from dvc.system import System
 from dvc.utils import makedirs
 from tests.utils import trees_equal
 
@@ -34,6 +36,23 @@ def test_get_repo_dir(repo_dir, erepo):
     trees_equal(src, dst)
 
 
+def test_cache_type_is_properly_overridden(repo_dir, erepo):
+    erepo.dvc.config.set(
+        Config.SECTION_CACHE, Config.SECTION_CACHE_TYPE, "symlink"
+    )
+    erepo.dvc.scm.add([erepo.dvc.config.config_file])
+    erepo.dvc.scm.commit("set cache type to symlinks")
+
+    src = erepo.FOO
+    dst = erepo.FOO + "_imported"
+
+    Repo.get(erepo.root_dir, src, dst)
+
+    assert not System.is_symlink(dst)
+    assert os.path.exists(dst)
+    assert os.path.isfile(dst)
+
+
 def test_get_repo_rev(repo_dir, erepo):
     src = "version"
     dst = src
diff --git a/tests/func/test_import.py b/tests/func/test_import.py
--- a/tests/func/test_import.py
+++ b/tests/func/test_import.py
@@ -7,8 +7,10 @@
 import pytest
 from mock import patch
 
+from dvc.config import Config
 from dvc.exceptions import DownloadError
 from dvc.stage import Stage
+from dvc.system import System
 from dvc.utils import makedirs
 from tests.utils import trees_equal
 
@@ -68,6 +70,25 @@ def test_pull_imported_stage(dvc_repo, erepo):
     assert os.path.isfile(dst_cache)
 
 
+def test_cache_type_is_properly_overridden(repo_dir, git, dvc_repo, erepo):
+    erepo.dvc.config.set(
+        Config.SECTION_CACHE, Config.SECTION_CACHE_TYPE, "symlink"
+    )
+    erepo.dvc.scm.add([erepo.dvc.config.config_file])
+    erepo.dvc.scm.commit("set source repo cache type to symlinks")
+
+    src = erepo.FOO
+    dst = erepo.FOO + "_imported"
+
+    dvc_repo.imp(erepo.root_dir, src, dst)
+
+    assert not System.is_symlink(dst)
+    assert os.path.exists(dst)
+    assert os.path.isfile(dst)
+    assert filecmp.cmp(repo_dir.FOO, dst, shallow=False)
+    assert git.git.check_ignore(dst)
+
+
 def test_pull_imported_directory_stage(dvc_repo, erepo):
     src = erepo.DATA_DIR
     dst = erepo.DATA_DIR + "_imported"