Skip to content

Commit

Permalink
api: add globbing option for pushing (#5033)
Browse files Browse the repository at this point in the history
* api: add globbing option for pushing

Related: #4816

Signed-off-by: Ioana Grigoropol <ioana.grigoropol@gmail.com>

* api: use utility function for push command

Signed-off-by: Ioana Grigoropol <ioana.grigoropol@gmail.com>
  • Loading branch information
ju0gri authored Dec 25, 2020
1 parent 11382cc commit fa4bf40
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 2 deletions.
7 changes: 7 additions & 0 deletions dvc/command/data_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def run(self):
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:
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion dvc/repo/push.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ..utils import glob_targets
from . import locked


Expand All @@ -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,
Expand Down
32 changes: 31 additions & 1 deletion tests/func/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
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
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/command/test_data_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ def test_push(mocker):
"--with-deps",
"--recursive",
"--run-cache",
"--glob",
]
)
assert cli_args.func == CmdDataPush
Expand All @@ -115,4 +116,5 @@ def test_push(mocker):
with_deps=True,
recursive=True,
run_cache=True,
glob=True,
)

0 comments on commit fa4bf40

Please sign in to comment.