gc: disallow --remote without other flags

This commit is contained in:
dberenbaum
2023-05-16 17:18:57 +02:00
committed by David de la Iglesia Castro
parent 1e538ed87b
commit f888544554
3 changed files with 14 additions and 1 deletions
+1 -1
View File
@@ -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",
+3
View File
@@ -16,6 +16,9 @@ logger = logging.getLogger(__name__)
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"
+10
View File
@@ -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()