From a2ff22aa168dc5dfe1c4d71f8d165a86a4018fba Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Tue, 17 Mar 2020 17:22:35 +0545 Subject: [PATCH 1/2] gc: ask for specifier when using -c flag --- dvc/command/gc.py | 1 - dvc/repo/gc.py | 1 - tests/func/test_gc.py | 23 ++++++++++++++++++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/dvc/command/gc.py b/dvc/command/gc.py index b4b710ae73..64e634d3ae 100644 --- a/dvc/command/gc.py +++ b/dvc/command/gc.py @@ -19,7 +19,6 @@ def run(self): all_tags=self.args.all_tags, all_commits=self.args.all_commits, workspace=self.args.workspace, - cloud=self.args.cloud, ) msg = "This will remove all cache except items used in " diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index a19c3932ba..5f988244d0 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -46,7 +46,6 @@ def gc( all_tags=all_tags, all_commits=all_commits, all_branches=all_branches, - cloud=cloud, ) from contextlib import ExitStack diff --git a/tests/func/test_gc.py b/tests/func/test_gc.py index bb395669ab..85790ebebc 100644 --- a/tests/func/test_gc.py +++ b/tests/func/test_gc.py @@ -236,6 +236,20 @@ def test_gc_without_workspace_raises_error(tmp_dir, dvc): dvc.gc(force=True, workspace=False) +def test_gc_cloud_with_or_without_specifier(tmp_dir, erepo_dir): + dvc = erepo_dir.dvc + with erepo_dir.chdir(): + from dvc.exceptions import InvalidArgumentError + + with pytest.raises(InvalidArgumentError): + dvc.gc(force=True, cloud=True) + + dvc.gc(cloud=True, all_tags=True) + dvc.gc(cloud=True, all_commits=True) + dvc.gc(cloud=True, all_branches=True) + dvc.gc(cloud=True, all_commits=False, all_branches=True, all_tags=True) + + def test_gc_without_workspace_on_tags_branches_commits(tmp_dir, dvc): dvc.gc(force=True, all_tags=True) dvc.gc(force=True, all_commits=True) @@ -253,6 +267,13 @@ def test_gc_without_workspace(tmp_dir, dvc, caplog): assert "Invalid Arguments" in caplog.text +def test_gc_cloud_without_any_specifier(tmp_dir, dvc, caplog): + with caplog.at_level(logging.WARNING, logger="dvc"): + assert main(["gc", "-cvf"]) == 255 + + assert "Invalid Arguments" in caplog.text + + def test_gc_with_possible_args_positive(tmp_dir, dvc): for flag in [ "-w", @@ -274,5 +295,5 @@ def test_gc_cloud_positive(tmp_dir, dvc, tmp_path_factory): dvc.push() - for flag in ["-c", "-ca", "-cT", "-caT", "-cwT"]: + for flag in ["-cw", "-ca", "-cT", "-caT", "-cwT"]: assert main(["gc", "-vf", flag]) == 0 From d5e2f8114538c9a04d793f433fb541e3dd9212b9 Mon Sep 17 00:00:00 2001 From: Saugat Pachhai Date: Tue, 17 Mar 2020 18:22:20 +0545 Subject: [PATCH 2/2] tests: add -w flag with gc -c --- tests/func/test_data_cloud.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/func/test_data_cloud.py b/tests/func/test_data_cloud.py index aaf1a12c5c..1e875f79c3 100644 --- a/tests/func/test_data_cloud.py +++ b/tests/func/test_data_cloud.py @@ -367,7 +367,7 @@ def _test_cloud(self, remote=None): self.assertTrue(os.path.isfile(cache_dir)) # NOTE: check if remote gc works correctly on directories - self.main(["gc", "-c", "-f"] + args) + self.main(["gc", "-cw", "-f"] + args) shutil.move( self.dvc.cache.local.cache_dir, self.dvc.cache.local.cache_dir + ".back",