Skip to content

Commit

Permalink
gc: disallow --remote without other flags
Browse files Browse the repository at this point in the history
  • Loading branch information
dberenbaum authored and daavoo committed May 16, 2023
1 parent 1e538ed commit f888544
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dvc/commands/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions dvc/repo/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/command/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit f888544

Please sign in to comment.