mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
api: add globbing option for pushing (#5033)
* api: add globbing option for pushing Related: #4816 Signed-off-by: Ioana Grigoropol <[email protected]> * api: use utility function for push command Signed-off-by: Ioana Grigoropol <[email protected]>
This commit is contained in:
@@ -57,6 +57,7 @@ class CmdDataPush(CmdDataBase):
|
||||
with_deps=self.args.with_deps,
|
||||
recursive=self.args.recursive,
|
||||
run_cache=self.args.run_cache,
|
||||
glob=self.args.glob,
|
||||
)
|
||||
self.log_summary({"pushed": processed_files_count})
|
||||
except DvcException:
|
||||
@@ -240,6 +241,12 @@ def add_parser(subparsers, _parent_parser):
|
||||
default=False,
|
||||
help="Push run history for all stages.",
|
||||
)
|
||||
push_parser.add_argument(
|
||||
"--glob",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="Allows targets containing shell-style wildcards.",
|
||||
)
|
||||
push_parser.set_defaults(func=CmdDataPush)
|
||||
|
||||
# Fetch
|
||||
|
||||
+5
-1
@@ -1,3 +1,4 @@
|
||||
from ..utils import glob_targets
|
||||
from . import locked
|
||||
|
||||
|
||||
@@ -14,14 +15,17 @@ def push(
|
||||
all_commits=False,
|
||||
run_cache=False,
|
||||
revs=None,
|
||||
glob=False,
|
||||
):
|
||||
used_run_cache = self.stage_cache.push(remote) if run_cache else []
|
||||
|
||||
if isinstance(targets, str):
|
||||
targets = [targets]
|
||||
|
||||
expanded_targets = glob_targets(targets, glob=glob)
|
||||
|
||||
used = self.used_cache(
|
||||
targets,
|
||||
expanded_targets,
|
||||
all_branches=all_branches,
|
||||
all_tags=all_tags,
|
||||
all_commits=all_commits,
|
||||
|
||||
@@ -9,7 +9,7 @@ import dvc.data_cloud as cloud
|
||||
from dvc.cache import Cache
|
||||
from dvc.config import NoRemoteError
|
||||
from dvc.dvcfile import Dvcfile
|
||||
from dvc.exceptions import DownloadError, PathMissingError
|
||||
from dvc.exceptions import CollectCacheError, DownloadError, PathMissingError
|
||||
from dvc.external_repo import IsADVCRepoError
|
||||
from dvc.stage.exceptions import StagePathNotFoundError
|
||||
from dvc.system import System
|
||||
@@ -264,6 +264,36 @@ 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_wildcard_from_bare_git_repo(
|
||||
tmp_dir, make_tmp_dir, erepo_dir, local_cloud
|
||||
):
|
||||
import git
|
||||
|
||||
git.Repo.init(os.fspath(tmp_dir), bare=True)
|
||||
|
||||
erepo_dir.add_remote(config=local_cloud.config)
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen(
|
||||
{
|
||||
"dir123": {"foo": "foo content"},
|
||||
"dirextra": {"extrafoo": "extra foo content"},
|
||||
},
|
||||
commit="initial",
|
||||
)
|
||||
erepo_dir.dvc.push(
|
||||
[os.path.join(os.fspath(erepo_dir), "dire*")], glob=True
|
||||
)
|
||||
|
||||
erepo_dir.scm.gitpython.repo.create_remote("origin", os.fspath(tmp_dir))
|
||||
erepo_dir.scm.gitpython.repo.remote("origin").push("master")
|
||||
|
||||
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
|
||||
with dvc_repo.chdir():
|
||||
dvc_repo.dvc.imp(os.fspath(tmp_dir), "dirextra")
|
||||
with pytest.raises(CollectCacheError):
|
||||
dvc_repo.dvc.imp(os.fspath(tmp_dir), "dir123")
|
||||
|
||||
|
||||
def test_download_error_pulling_imported_stage(tmp_dir, dvc, erepo_dir):
|
||||
with erepo_dir.chdir():
|
||||
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")
|
||||
|
||||
@@ -96,6 +96,7 @@ def test_push(mocker):
|
||||
"--with-deps",
|
||||
"--recursive",
|
||||
"--run-cache",
|
||||
"--glob",
|
||||
]
|
||||
)
|
||||
assert cli_args.func == CmdDataPush
|
||||
@@ -115,4 +116,5 @@ def test_push(mocker):
|
||||
with_deps=True,
|
||||
recursive=True,
|
||||
run_cache=True,
|
||||
glob=True,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user