Repository: iterative/dvc

Issue:
gc: clarify behavior of cloud/remote options
Extracted from https://github.com/iterative/dvc.org/pull/2917#discussion_r747749772:

> @dberenbaum
> What happens if you use --remote without --cloud?
> 
> @jorgeorpinel
> Looks like the remote is ignored and it operates locally instead. A bit confusing but this text is correct ATM.
> 
> p.s. It should probably fail or give a clearer warning at least...
the warning is always the same even with -c:
> 
> `WARNING: This will remove all cache except items used in the workspace of the current repo.`
> 
> No mention of cloud/remotes.

Warnings should be clarified with respect to using `--cloud` and `--remote` options. Also, should `--remote` imply `--cloud` so that both aren't required?


Discussion:
Yes, it is quite confusing, only after tried myself can I ascertain its behavior.
https://github.com/iterative/dvc.org/pull/2917 clarified that `gc --cloud` cleans up the remote **in addition to** the local cache. Is this intended behavior? Seems like it would be more useful to have `gc --cloud` be independent and not clean up the local cache.
@daavoo Since you recently updated these options, do you recall if these issues still exist?
> @daavoo Since you recently updated these options, do you recall if these issues still exist?

The `--remote` flag only doesn't give any hints or warning if `--cloud` or `--not-in-remote` is missing. Failing should be a simple change to do.

---

Were you also referring to this one?:

> Seems like it would be more useful to have gc --cloud be independent and not clean up the local cache.

This sounds more like a feature request / change in default behavior which would be a breaking change




Resolving patch:
diff --git a/dvc/commands/gc.py b/dvc/commands/gc.py
--- 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
--- 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"


Test patch:
diff --git a/tests/unit/command/test_gc.py b/tests/unit/command/test_gc.py
--- 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()