Fail on sync when there is no match for glob.

This commit is contained in:
Karthikeyan Singaravelan
2022-05-11 18:37:09 +03:00
committed by Ruslan Kuprieiev
parent a80a85e6bd
commit e177f041c8
4 changed files with 38 additions and 2 deletions
+6
View File
@@ -349,3 +349,9 @@ class CircularImportError(DvcException):
class PrettyDvcException(DvcException):
def __pretty_exc__(self, **kwargs):
"""Print prettier exception message."""
class GlobDoesNotMatchError(DvcException):
def __init__(self, glob):
msg = f"Glob {glob} has no matches."
super().__init__(msg)
+4
View File
@@ -1,6 +1,7 @@
import logging
from typing import TYPE_CHECKING, Optional
from dvc.exceptions import GlobDoesNotMatchError
from dvc.repo import locked
from dvc.utils import glob_targets
@@ -31,6 +32,9 @@ def pull(
expanded_targets = glob_targets(targets, glob=glob)
if targets and not expanded_targets:
raise GlobDoesNotMatchError(targets)
processed_files_count = self.fetch(
expanded_targets,
jobs,
+8 -1
View File
@@ -1,6 +1,10 @@
from typing import TYPE_CHECKING, Optional
from dvc.exceptions import FileTransferError, UploadError
from dvc.exceptions import (
FileTransferError,
GlobDoesNotMatchError,
UploadError,
)
from ..utils import glob_targets
from . import locked
@@ -35,6 +39,9 @@ def push(
expanded_targets = glob_targets(targets, glob=glob)
if targets and not expanded_targets:
raise GlobDoesNotMatchError(targets)
used = self.used_objs(
expanded_targets,
all_branches=all_branches,
+20 -1
View File
@@ -9,7 +9,11 @@ from scmrepo.git import Git
from dvc.config import NoRemoteError
from dvc.data.db import ODBManager
from dvc.dvcfile import Dvcfile
from dvc.exceptions import DownloadError, PathMissingError
from dvc.exceptions import (
DownloadError,
GlobDoesNotMatchError,
PathMissingError,
)
from dvc.stage.exceptions import StagePathNotFoundError
from dvc.system import System
from dvc.utils.fs import makedirs, remove
@@ -266,6 +270,21 @@ def test_pull_wildcard_imported_directory_stage(tmp_dir, dvc, erepo_dir):
assert (tmp_dir / "dir_imported123").read_text() == {"foo": "foo content"}
def test_push_pull_glob_no_match(
tmp_dir, dvc, erepo_dir, run_copy, local_remote
):
tmp_dir.gen("foo", "foo")
erepo_dir.add_remote(config=local_remote.config)
with erepo_dir.chdir():
with pytest.raises(GlobDoesNotMatchError):
dvc.push(targets="b*", glob=True)
with pytest.raises(GlobDoesNotMatchError):
dvc.pull(targets="b*", glob=True)
assert not os.path.exists(erepo_dir.dvc.stage_cache.cache_dir)
def test_push_wildcard_from_bare_git_repo(
tmp_dir, make_tmp_dir, erepo_dir, local_cloud
):