Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync: skip if remote doesn't match output remote #10365

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _onerror(entry, exc):
return _onerror


def _collect_indexes( # noqa: PLR0913
def _collect_indexes( # noqa: PLR0913, C901
repo,
targets=None,
remote=None,
Expand Down Expand Up @@ -56,6 +56,8 @@ def stage_filter(stage: "Stage") -> bool:
def outs_filter(out: "Output") -> bool:
if push and not out.can_push:
return False
if remote and out.remote and remote != out.remote:
return False
return True

for rev in repo.brancher(
Expand Down
52 changes: 52 additions & 0 deletions tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,58 @@ def test_target_remote(tmp_dir, dvc, make_remote):
}


def test_output_target_remote(tmp_dir, dvc, make_remote):
make_remote("default", default=True)
make_remote("for_foo", default=False)
make_remote("for_bar", default=False)

tmp_dir.dvc_gen("foo", "foo")
tmp_dir.dvc_gen("bar", "bar")
tmp_dir.dvc_gen("data", {"one": "one", "two": "two"})

with (tmp_dir / "foo.dvc").modify() as d:
d["outs"][0]["remote"] = "for_foo"

with (tmp_dir / "bar.dvc").modify() as d:
d["outs"][0]["remote"] = "for_bar"

# push foo and data to for_foo remote
dvc.push(remote="for_foo")

default = dvc.cloud.get_remote_odb("default")
for_foo = dvc.cloud.get_remote_odb("for_foo")
for_bar = dvc.cloud.get_remote_odb("for_bar")

# hashes for foo and data, but not bar
expected = {
"acbd18db4cc2f85cedef654fccc4a4d8",
"f97c5d29941bfb1b2fdab0874906ab82",
"6b18131dc289fd37006705affe961ef8.dir",
"b8a9f715dbb64fd5c56e7783c6820a61",
}

assert set(default.all()) == set()
assert set(for_foo.all()) == expected
assert set(for_bar.all()) == set()

# push everything without specifying remote
dvc.push()
assert set(default.all()) == {
"f97c5d29941bfb1b2fdab0874906ab82",
"6b18131dc289fd37006705affe961ef8.dir",
"b8a9f715dbb64fd5c56e7783c6820a61",
}
assert set(for_foo.all()) == expected
assert set(for_bar.all()) == {"37b51d194a7513e45b56f6524f2d51f2"}

clean(["foo", "bar", "data"], dvc)

# pull foo and data from for_foo remote
dvc.pull(remote="for_foo", allow_missing=True)

assert set(dvc.cache.local.all()) == expected


def test_pull_allow_missing(tmp_dir, dvc, local_remote):
dvc.stage.add(name="bar", outs=["bar"], cmd="echo bar > bar")

Expand Down
Loading