mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
gc: fix usage with --date
This commit is contained in:
+10
-1
@@ -32,7 +32,16 @@ def brancher( # noqa: E302
|
||||
- empty string it there is no branches to iterate over
|
||||
- "workspace" if there are uncommitted changes in the SCM repo
|
||||
"""
|
||||
if not any([revs, all_branches, all_tags, all_commits, all_experiments]):
|
||||
if not any(
|
||||
[
|
||||
revs,
|
||||
all_branches,
|
||||
all_tags,
|
||||
all_commits,
|
||||
all_experiments,
|
||||
commit_date,
|
||||
]
|
||||
):
|
||||
yield ""
|
||||
return
|
||||
|
||||
|
||||
+3
-3
@@ -242,9 +242,9 @@ def iter_revs( # noqa: C901
|
||||
|
||||
def _time_filter(rev):
|
||||
try:
|
||||
if scm.resolve_commit(rev).commit_date >= commit_datestamp:
|
||||
return True
|
||||
return False
|
||||
return (
|
||||
scm.resolve_commit(rev).commit_time >= commit_datestamp
|
||||
)
|
||||
except _SCMError:
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
@@ -327,3 +328,29 @@ def test_gc_rev_num(tmp_dir, scm, dvc):
|
||||
assert not cache.exists()
|
||||
else:
|
||||
assert cache.read_text() == str(i)
|
||||
|
||||
|
||||
def test_date(tmp_dir, scm, dvc):
|
||||
tmp_dir.dvc_gen("testfile", "content", commit="add testfile")
|
||||
|
||||
now = datetime.datetime.now()
|
||||
datestamp = now.date().replace(day=now.day + 1).isoformat()
|
||||
|
||||
tmp_dir.dvc_gen("testfile", "modified", commit="modified")
|
||||
|
||||
dvc.gc(commit_date=datestamp)
|
||||
|
||||
assert _count_files(dvc.odb.local.path) == 1
|
||||
assert dvc.odb.local.exists(
|
||||
"9ae73c65f418e6f79ceb4f0e4a4b98d5" # "modified"
|
||||
)
|
||||
|
||||
tmp_dir.dvc_gen("testfile", "modified, again", commit="modify")
|
||||
|
||||
datestamp = now.date().replace(day=now.day - 1).isoformat()
|
||||
dvc.gc(commit_date=datestamp)
|
||||
assert _count_files(dvc.odb.local.path) == 2
|
||||
assert dvc.odb.local.exists("9ae73c65f418e6f79ceb4f0e4a4b98d5")
|
||||
assert dvc.odb.local.exists(
|
||||
"3bcf3b1be3e794a97a5a6b93a005784c" # "modified, again"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user