Skip to content

Commit b24983b

Browse files
committed
✨ Add respect_no_push flag to status
1 parent 4f8ad22 commit b24983b

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

dvc/repo/data.py

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
from typing import TYPE_CHECKING, Any, TypedDict, Union
55

66
from dvc.fs.callbacks import DEFAULT_CALLBACK
7+
from dvc.log import logger
78
from dvc.ui import ui
89

10+
logger = logger.getChild(__name__)
11+
912
if TYPE_CHECKING:
1013
from dvc.fs.callbacks import Callback
1114
from dvc.repo import Repo
@@ -217,7 +220,29 @@ def _transform_git_paths_to_dvc(repo: "Repo", files: Iterable[str]) -> list[str]
217220
return [repo.fs.relpath(file, start) for file in files]
218221

219222

220-
def status(repo: "Repo", untracked_files: str = "no", **kwargs: Any) -> Status:
223+
def _filter_out_push_false_outs(repo: "Repo", not_in_remote: list[str]) -> list[str]:
224+
"""Filter out paths that are not pushable."""
225+
filtered_not_in_remote = []
226+
227+
for path in not_in_remote:
228+
(out,) = repo.find_outs_by_path(path)
229+
230+
if out.can_push:
231+
filtered_not_in_remote.append(path)
232+
else:
233+
logger.trace(
234+
f"Eliminating {path} from not_in_remote, because it is not pushable"
235+
)
236+
237+
return filtered_not_in_remote
238+
239+
240+
def status(
241+
repo: "Repo",
242+
untracked_files: str = "no",
243+
respect_no_push: bool = False,
244+
**kwargs: Any,
245+
) -> Status:
221246
from dvc.scm import NoSCMError, SCMError
222247

223248
head = kwargs.pop("head", "HEAD")
@@ -234,10 +259,17 @@ def status(repo: "Repo", untracked_files: str = "no", **kwargs: Any) -> Status:
234259
git_info = _git_info(repo.scm, untracked_files=untracked_files)
235260
untracked = git_info.get("untracked", [])
236261
untracked = _transform_git_paths_to_dvc(repo, untracked)
262+
263+
not_in_remote = uncommitted_diff.pop("not_in_remote", [])
264+
265+
if respect_no_push:
266+
logger.debug("Filtering out paths that are not pushable")
267+
not_in_remote = _filter_out_push_false_outs(repo, not_in_remote)
268+
237269
# order matters here
238270
return Status(
239271
not_in_cache=uncommitted_diff.pop("not_in_cache", []),
240-
not_in_remote=uncommitted_diff.pop("not_in_remote", []),
272+
not_in_remote=not_in_remote,
241273
committed=committed_diff,
242274
uncommitted=uncommitted_diff,
243275
untracked=untracked,

tests/func/test_data_status.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,23 +438,22 @@ def dvc_pipeline_with_push_false(
438438
assert set(
439439
dvc.data_status(remote_refresh=True, not_in_remote=True)["not_in_remote"]
440440
) == {"foo", "bar"}
441+
dvc.push()
441442

442443

443-
def test_missing_remote_push_false(dvc_pipeline_with_push_false: None, dvc: TmpDir):
444-
dvc.push()
444+
def test_missing_remote_push_false(dvc_pipeline_with_push_false: None, dvc: Repo):
445445
assert set(
446446
dvc.data_status(remote_refresh=True, not_in_remote=True)["not_in_remote"]
447447
) == {"foo"}
448448

449449

450450
def test_missing_remote_push_false_respects_no_push_flag(
451-
dvc_pipeline_with_push_false: None, dvc: TmpDir
451+
dvc_pipeline_with_push_false: None, dvc: Repo
452452
):
453-
dvc.push()
454453
assert (
455-
dvc.data_status(
456-
remote_refresh=True, not_in_remote=True, not_in_remote_no_push=True
457-
)["not_in_remote"]
454+
dvc.data_status(remote_refresh=True, not_in_remote=True, respect_no_push=True)[
455+
"not_in_remote"
456+
]
458457
== []
459458
)
460459

0 commit comments

Comments
 (0)