nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: iterative/dvc
Pull request #1182 (2018-10-02 20:36:04)

gc: add a comfirmation prompt
Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai>


Patch:
diff --git a/dvc/cli.py b/dvc/cli.py
index bc29bc7ba..79320c743 100644
--- a/dvc/cli.py
+++ b/dvc/cli.py
@@ -541,6 +541,12 @@ def parse_args(argv=None):
                         '-r',
                         '--remote',
                         help='Remote repository to collect garbage in.')
+    gc_parser.add_argument(
+                        '-f',
+                        '--force',
+                        action='store_true',
+                        default=False,
+                        help='Force garbage collection.')
     gc_parser.set_defaults(func=CmdGC)
 
     # Config
diff --git a/dvc/command/gc.py b/dvc/command/gc.py
index a43a05bb9..fa05faf86 100644
--- a/dvc/command/gc.py
+++ b/dvc/command/gc.py
@@ -3,6 +3,22 @@ from dvc.command.base import CmdBase
 
 class CmdGC(CmdBase):
     def run(self):
+        msg = 'This will remove all cache except the cache that is used in '
+        if not self.args.all_branches and not self.args.all_tags:
+            msg += 'the current git branch.'
+        elif self.args.all_branches and not self.args.all_tags:
+            msg += 'all git branches.'
+        elif not self.args.all_branches and self.args.all_tags:
+            msg += 'all git tags.'
+        else:
+            msg += 'all git branches and all git tags.'
+
+        self.project.logger.warn(msg)
+
+        msg = 'Are you sure you want to proceed?'
+        if not self.args.force and not self.project.prompt.prompt(msg):
+            return 1
+
         self.project.gc(all_branches=self.args.all_branches,
                         all_tags=self.args.all_tags,
                         cloud=self.args.cloud,


Test patch:
diff --git a/tests/test_gc.py b/tests/test_gc.py
index b2276ea5e..52da378be 100644
--- a/tests/test_gc.py
+++ b/tests/test_gc.py
@@ -29,7 +29,8 @@ class TestGC(TestDvc):
         self._test_gc()
 
     def test_cli(self):
-        ret = main(['gc'])
+        ret = main(['gc', '-f'])
+        self.assertEqual(ret, 0)
         self._test_gc()
 
     def _test_gc(self):
Repository: iterative/dvc
Pull request #1315 (2018-11-11 20:28:51)

state: add workaround for VACUUM bug on python 3.6 and 3.7
Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai>


Patch:
diff --git a/dvc/state.py b/dvc/state.py
index dded8444f..dcb95c34b 100644
--- a/dvc/state.py
+++ b/dvc/state.py
@@ -190,6 +190,12 @@ class State(object):
                 else:
                     raise
 
+    def _vacuum(self):
+        # NOTE: see https://bugs.python.org/issue28518
+        self.db.isolation_level = None
+        self._execute("VACUUM")
+        self.db.isolation_level = ''
+
     def dump(self):
         assert self.db is not None
 
@@ -213,7 +219,7 @@ class State(object):
                                      self.STATE_TABLE,
                                      delete))
 
-            self._execute("VACUUM")
+            self._vacuum()
 
             cmd = "SELECT COUNT(*) FROM {}"
 


Test patch:
diff --git a/tests/test_state.py b/tests/test_state.py
index fa7894db2..94e90c19d 100644
--- a/tests/test_state.py
+++ b/tests/test_state.py
@@ -5,6 +5,7 @@ import time
 from dvc.system import System
 from dvc.state import State
 from dvc.utils import file_md5
+from dvc.main import main
 
 from tests.basic_env import TestDvc
 
@@ -39,3 +40,20 @@ class TestState(TestDvc):
 
             entry_md5 = state.update(path)
             self.assertEqual(entry_md5, md5)
+
+
+class TestStateOverflow(TestDvc):
+    def test(self):
+        # NOTE: trying to add more entries than state can handle,
+        # to see if it will clean up and vacuum successfully
+        ret = main(['config', 'state.row_limit', '10'])
+        self.assertEqual(ret, 0)
+
+        dname = 'dir'
+        os.mkdir(dname)
+        for i in range(20):
+            with open(os.path.join(dname, str(i)), 'w+') as fobj:
+                fobj.write(str(i))
+
+        ret = main(['add', 'dir'])
+        self.assertEqual(ret, 0)