Skip to content

Commit fa4bf40

Browse files
authored
api: add globbing option for pushing (#5033)
* 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>
1 parent 11382cc commit fa4bf40

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

dvc/command/data_sync.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ def run(self):
5757
with_deps=self.args.with_deps,
5858
recursive=self.args.recursive,
5959
run_cache=self.args.run_cache,
60+
glob=self.args.glob,
6061
)
6162
self.log_summary({"pushed": processed_files_count})
6263
except DvcException:
@@ -240,6 +241,12 @@ def add_parser(subparsers, _parent_parser):
240241
default=False,
241242
help="Push run history for all stages.",
242243
)
244+
push_parser.add_argument(
245+
"--glob",
246+
action="store_true",
247+
default=False,
248+
help="Allows targets containing shell-style wildcards.",
249+
)
243250
push_parser.set_defaults(func=CmdDataPush)
244251

245252
# Fetch

dvc/repo/push.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from ..utils import glob_targets
12
from . import locked
23

34

@@ -14,14 +15,17 @@ def push(
1415
all_commits=False,
1516
run_cache=False,
1617
revs=None,
18+
glob=False,
1719
):
1820
used_run_cache = self.stage_cache.push(remote) if run_cache else []
1921

2022
if isinstance(targets, str):
2123
targets = [targets]
2224

25+
expanded_targets = glob_targets(targets, glob=glob)
26+
2327
used = self.used_cache(
24-
targets,
28+
expanded_targets,
2529
all_branches=all_branches,
2630
all_tags=all_tags,
2731
all_commits=all_commits,

tests/func/test_import.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from dvc.cache import Cache
1010
from dvc.config import NoRemoteError
1111
from dvc.dvcfile import Dvcfile
12-
from dvc.exceptions import DownloadError, PathMissingError
12+
from dvc.exceptions import CollectCacheError, DownloadError, PathMissingError
1313
from dvc.external_repo import IsADVCRepoError
1414
from dvc.stage.exceptions import StagePathNotFoundError
1515
from dvc.system import System
@@ -264,6 +264,36 @@ def test_pull_wildcard_imported_directory_stage(tmp_dir, dvc, erepo_dir):
264264
assert (tmp_dir / "dir_imported123").read_text() == {"foo": "foo content"}
265265

266266

267+
def test_push_wildcard_from_bare_git_repo(
268+
tmp_dir, make_tmp_dir, erepo_dir, local_cloud
269+
):
270+
import git
271+
272+
git.Repo.init(os.fspath(tmp_dir), bare=True)
273+
274+
erepo_dir.add_remote(config=local_cloud.config)
275+
with erepo_dir.chdir():
276+
erepo_dir.dvc_gen(
277+
{
278+
"dir123": {"foo": "foo content"},
279+
"dirextra": {"extrafoo": "extra foo content"},
280+
},
281+
commit="initial",
282+
)
283+
erepo_dir.dvc.push(
284+
[os.path.join(os.fspath(erepo_dir), "dire*")], glob=True
285+
)
286+
287+
erepo_dir.scm.gitpython.repo.create_remote("origin", os.fspath(tmp_dir))
288+
erepo_dir.scm.gitpython.repo.remote("origin").push("master")
289+
290+
dvc_repo = make_tmp_dir("dvc-repo", scm=True, dvc=True)
291+
with dvc_repo.chdir():
292+
dvc_repo.dvc.imp(os.fspath(tmp_dir), "dirextra")
293+
with pytest.raises(CollectCacheError):
294+
dvc_repo.dvc.imp(os.fspath(tmp_dir), "dir123")
295+
296+
267297
def test_download_error_pulling_imported_stage(tmp_dir, dvc, erepo_dir):
268298
with erepo_dir.chdir():
269299
erepo_dir.dvc_gen("foo", "foo content", commit="create foo")

tests/unit/command/test_data_sync.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def test_push(mocker):
9696
"--with-deps",
9797
"--recursive",
9898
"--run-cache",
99+
"--glob",
99100
]
100101
)
101102
assert cli_args.func == CmdDataPush
@@ -115,4 +116,5 @@ def test_push(mocker):
115116
with_deps=True,
116117
recursive=True,
117118
run_cache=True,
119+
glob=True,
118120
)

0 commit comments

Comments
 (0)