Skip to content

Commit 29386a0

Browse files
authored
data status: add --remote option to check files against a different remote (#10843)
1 parent e027bc6 commit 29386a0

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

dvc/commands/data.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def run(self) -> int:
111111
targets=self.args.targets,
112112
granular=self.args.granular,
113113
untracked_files=self.args.untracked_files,
114+
remote=self.args.remote,
114115
not_in_remote=self.args.not_in_remote,
115116
remote_refresh=self.args.remote_refresh,
116117
)
@@ -182,6 +183,12 @@ def add_parser(subparsers, parent_parser):
182183
nargs="?",
183184
help="Show untracked files.",
184185
)
186+
data_status_parser.add_argument(
187+
"-r",
188+
"--remote",
189+
help="Remote storage to check (only applicable with --not-in-remote).",
190+
metavar="<name>",
191+
)
185192
data_status_parser.add_argument(
186193
"--not-in-remote",
187194
action="store_true",

dvc/repo/data.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,13 +404,22 @@ def status(
404404
*,
405405
granular: bool = False,
406406
untracked_files: str = "no",
407+
remote: Optional[str] = None,
407408
not_in_remote: bool = False,
408409
remote_refresh: bool = False,
410+
config: Optional[dict] = None,
409411
batch_size: Optional[int] = None,
410412
head: str = "HEAD",
411413
) -> Status:
412414
from dvc.scm import NoSCMError, SCMError
413415

416+
config = config or {}
417+
if remote and not_in_remote:
418+
logger.debug("Using remote %r", remote)
419+
core = config.setdefault("core", {})
420+
core["remote"] = remote
421+
repo.config.merge(config)
422+
414423
targets = targets or []
415424
filter_keys: list[DataIndexKey] = [repo.fs.relparts(os.fspath(t)) for t in targets]
416425
# try to remove duplicate and overlapping keys

tests/func/test_data_status.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,42 @@ def test_missing_dir_object_from_index(M, tmp_dir, dvc, scm):
398398
}
399399

400400

401+
def test_remote_check(M, tmp_dir, dvc, scm, make_remote):
402+
make_remote("default", default=True)
403+
make_remote("myremote", default=False)
404+
405+
tmp_dir.dvc_gen({"dir": {"foo": "foo", "bar": "bar"}})
406+
tmp_dir.dvc_gen("foobar", "foobar")
407+
assert dvc.push() == 4
408+
scm.add_commit(["dir.dvc", "foobar.dvc", ".gitignore"], message="add files")
409+
410+
entries = M.unordered("foobar", join("dir", ""))
411+
granular_entries = M.unordered(
412+
"foobar", join("dir", ""), join("dir", "foo"), join("dir", "bar")
413+
)
414+
expected_ng = EMPTY_STATUS | {"git": M.dict(), "unchanged": entries}
415+
expected_g = EMPTY_STATUS | {
416+
"not_in_remote": [],
417+
"git": M.dict(),
418+
"unchanged": granular_entries,
419+
}
420+
421+
opts = {"not_in_remote": True, "remote_refresh": True}
422+
assert dvc.data_status(**opts) == expected_ng
423+
assert dvc.data_status(granular=True, **opts) == expected_g
424+
425+
opts |= {"remote": "myremote"}
426+
assert dvc.data_status(**opts) == expected_ng | {"not_in_remote": entries}
427+
assert dvc.data_status(granular=True, **opts) == expected_g | {
428+
"not_in_remote": granular_entries
429+
}
430+
431+
dvc.push(remote="myremote")
432+
433+
assert dvc.data_status(**opts) == expected_ng
434+
assert dvc.data_status(granular=True, **opts) == expected_g
435+
436+
401437
def test_missing_remote_cache(M, tmp_dir, dvc, scm, local_remote):
402438
tmp_dir.dvc_gen({"dir": {"foo": "foo", "bar": "bar"}})
403439
tmp_dir.dvc_gen("foobar", "foobar")

tests/unit/command/test_data_status.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def test_cli(dvc, mocker, mocked_status):
4343
"--unchanged",
4444
"--untracked-files",
4545
"--granular",
46+
"--remote",
47+
"myremote",
4648
]
4749
)
4850

@@ -53,6 +55,7 @@ def test_cli(dvc, mocker, mocked_status):
5355
targets=[],
5456
untracked_files="all",
5557
not_in_remote=False,
58+
remote="myremote",
5659
remote_refresh=True,
5760
granular=True,
5861
)

0 commit comments

Comments
 (0)