From 990bbe32c14a367955ccc4264c2ac237b6a9adff Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Tue, 2 Oct 2018 21:09:47 +0300 Subject: [PATCH] gc: add a comfirmation prompt Signed-off-by: Ruslan Kuprieiev --- dvc/cli.py | 6 ++++++ dvc/command/gc.py | 16 ++++++++++++++++ tests/test_gc.py | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) 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, 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):