From f888544554f8acd903be55f03ae6657d56328ea3 Mon Sep 17 00:00:00 2001 From: dberenbaum Date: Thu, 11 May 2023 12:25:14 -0400 Subject: [PATCH] gc: disallow --remote without other flags --- dvc/commands/gc.py | 2 +- dvc/repo/gc.py | 3 +++ tests/unit/command/test_gc.py | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dvc/commands/gc.py b/dvc/commands/gc.py index 647c4a717f..46250c2e2e 100644 --- a/dvc/commands/gc.py +++ b/dvc/commands/gc.py @@ -175,7 +175,7 @@ def add_parser(subparsers, parent_parser): "--cloud", action="store_true", default=False, - help="Collect garbage in remote repository.", + help="Collect garbage in remote storage in addition to local cache.", ) gc_parser.add_argument( "-r", diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index 7a4eb28395..3b186bf1c6 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -16,6 +16,9 @@ def _validate_args(**kwargs): not_in_remote = kwargs.pop("not_in_remote", None) cloud = kwargs.pop("cloud", None) + remote = kwargs.pop("remote", None) + if remote and not (cloud or not_in_remote): + raise InvalidArgumentError("`--remote` requires `--cloud` or `--not-in-remote`") if not_in_remote and cloud: raise InvalidArgumentError( "`--not-in-remote` and `--cloud` are mutually exclusive" diff --git a/tests/unit/command/test_gc.py b/tests/unit/command/test_gc.py index 2b7ac4b1be..34c75acf7b 100644 --- a/tests/unit/command/test_gc.py +++ b/tests/unit/command/test_gc.py @@ -60,3 +60,13 @@ def test_(dvc, scm, mocker): cmd = cli_args.func(cli_args) with pytest.raises(InvalidArgumentError): cmd.run() + + cli_args = parse_args(["gc", "--cloud", "--not-in-remote"]) + cmd = cli_args.func(cli_args) + with pytest.raises(InvalidArgumentError): + cmd.run() + + cli_args = parse_args(["gc", "--remote", "myremote"]) + cmd = cli_args.func(cli_args) + with pytest.raises(InvalidArgumentError): + cmd.run()