nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: dataversioncontrol/dvc
Pull request #723 (2018-05-21 14:00:54)

dvc: add cache dir to gitignore only if it is not external
Signed-off-by: Ruslan Kuprieiev <kupruser@gmail.com>


Patch:
diff --git a/dvc/project.py b/dvc/project.py
index e5aace784..eda8851f6 100644
--- a/dvc/project.py
+++ b/dvc/project.py
@@ -94,14 +94,18 @@ class Project(object):
         return proj
 
     def _ignore(self):
-        self.scm.ignore_list([self.cache.cache_dir,
-                              self.cache.link_state.state_file,
-                              self.cache.link_state._lock_file.lock_file,
-                              self.state.state_file,
-                              self.state._lock_file.lock_file,
-                              self.lock.lock_file,
-                              self.config.config_local_file,
-                              self.updater.updater_file])
+        l = [self.cache.link_state.state_file,
+             self.cache.link_state._lock_file.lock_file,
+             self.state.state_file,
+             self.state._lock_file.lock_file,
+             self.lock.lock_file,
+             self.config.config_local_file,
+             self.updater.updater_file]
+
+        if self.cache.cache_dir.startswith(self.root_dir):
+            l += [self.cache.cache_dir]
+
+        self.scm.ignore_list(l)
 
     def install(self):
         self.scm.install()


Test patch:
diff --git a/tests/test_cache.py b/tests/test_cache.py
index e3a8fa5a4..b917b328a 100644
--- a/tests/test_cache.py
+++ b/tests/test_cache.py
@@ -1,7 +1,10 @@
 import os
+import shutil
+import tempfile
 
 from dvc.cache import Cache
 from dvc.system import System
+from dvc.main import main
 
 from tests.basic_env import TestDvc
 
@@ -40,3 +43,22 @@ class TestCacheLoadBadDirCache(TestDvc):
         fname = 'not-list'
         self.create(fname, '{"a": "b"}')
         self._do_test(Cache.load_dir_cache(fname))
+
+
+class TestExternalCacheDir(TestDvc):
+    def test(self):
+        cache_dir = tempfile.mkdtemp()
+
+        ret = main(['config', 'cache.dir', cache_dir])
+        self.assertEqual(ret, 0)
+
+        shutil.rmtree('.dvc/cache')
+
+        main(['add', self.FOO])
+        self.assertEqual(ret, 0)
+
+        main(['add', self.DATA_DIR])
+        self.assertEqual(ret, 0)
+
+        self.assertFalse(os.path.exists('.dvc/cache'))
+        self.assertNotEquals(len(os.listdir(cache_dir)), 0)