mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-18 07:18:26 +01:00
gc: add a new flag --time (#678)
fix #678 1. Add a new flag `--time` to `dvc gc`. 2. Modify the unit test of `dvc gc` 3. Fix an argument checking error and update the error msg. Co-authored-by: Dave Berenbaum <[email protected]>
This commit is contained in:
committed by
David de la Iglesia Castro
co-authored by
Dave Berenbaum
parent
9c59689aa7
commit
20d1f7a87d
@@ -17,6 +17,8 @@ class CmdGC(CmdBase):
|
||||
all_branches=self.args.all_branches,
|
||||
all_tags=self.args.all_tags,
|
||||
all_commits=self.args.all_commits,
|
||||
all_experiments=self.args.all_experiments,
|
||||
commit_time=self.args.commit_time,
|
||||
workspace=self.args.workspace,
|
||||
)
|
||||
|
||||
@@ -53,6 +55,7 @@ class CmdGC(CmdBase):
|
||||
all_tags=self.args.all_tags,
|
||||
all_commits=self.args.all_commits,
|
||||
all_experiments=self.args.all_experiments,
|
||||
commit_time=self.args.commit_time,
|
||||
cloud=self.args.cloud,
|
||||
remote=self.args.remote,
|
||||
force=self.args.force,
|
||||
@@ -104,6 +107,18 @@ def add_parser(subparsers, parent_parser):
|
||||
default=False,
|
||||
help="Keep data files for all Git commits.",
|
||||
)
|
||||
gc_parser.add_argument(
|
||||
"--time",
|
||||
type=str,
|
||||
dest="commit_time",
|
||||
metavar="<YYYY-MM-DD>",
|
||||
default=None,
|
||||
help=(
|
||||
"Keep cached data referenced in the commits after ( inclusive )"
|
||||
" a certain time. Date must match the extended ISO 8601 format "
|
||||
"(YYYY-MM-DD)."
|
||||
),
|
||||
)
|
||||
gc_parser.add_argument(
|
||||
"--all-experiments",
|
||||
action="store_true",
|
||||
|
||||
+4
-1
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
from dvc.exceptions import InvalidArgumentError
|
||||
|
||||
@@ -11,7 +12,7 @@ def _raise_error_if_all_disabled(**kwargs):
|
||||
if not any(kwargs.values()):
|
||||
raise InvalidArgumentError(
|
||||
"Either of `-w|--workspace`, `-a|--all-branches`, `-T|--all-tags` "
|
||||
"`--all-experiments` or `--all-commits` needs to be set."
|
||||
"`--all-experiments`, `--all-commits` or `--time` needs to be set."
|
||||
)
|
||||
|
||||
|
||||
@@ -25,6 +26,7 @@ def gc(
|
||||
all_tags=False,
|
||||
all_commits=False,
|
||||
all_experiments=False,
|
||||
commit_time: Optional[str] = None,
|
||||
force=False,
|
||||
jobs=None,
|
||||
repos=None,
|
||||
@@ -40,6 +42,7 @@ def gc(
|
||||
all_commits=all_commits,
|
||||
all_branches=all_branches,
|
||||
all_experiments=all_experiments,
|
||||
commit_time=commit_time,
|
||||
)
|
||||
|
||||
from contextlib import ExitStack
|
||||
|
||||
@@ -14,6 +14,8 @@ def test_(dvc, scm, mocker):
|
||||
"--all-branches",
|
||||
"--all-commits",
|
||||
"--all-experiments",
|
||||
"--time",
|
||||
"2022-06-30",
|
||||
"--cloud",
|
||||
"--remote",
|
||||
"origin",
|
||||
@@ -38,6 +40,7 @@ def test_(dvc, scm, mocker):
|
||||
all_branches=True,
|
||||
all_commits=True,
|
||||
all_experiments=True,
|
||||
commit_time="2022-06-30",
|
||||
cloud=True,
|
||||
remote="origin",
|
||||
force=True,
|
||||
|
||||
Reference in New Issue
Block a user