Skip to content

Commit

Permalink
push: assume version_aware push should skip existing version_id
Browse files Browse the repository at this point in the history
  • Loading branch information
pmrowla committed Jan 5, 2023
1 parent 7e8c917 commit fb54f52
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions dvc/repo/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def outs_filter(out: "Output") -> bool:
return False
# If we are not enforcing push to latest version and have a version
# for this out, we assume it still exists and can skip pushing it
if push and not latest_only and out.meta.version_id is not None:
if push and not latest_only and _has_version_id(out):
return False
return True

Expand All @@ -70,6 +70,13 @@ def outs_filter(out: "Output") -> bool:
)


def _has_version_id(out: "Output"):
if not out.is_dir_checksum:
return out.meta.version_id is not None
tree = cast("Tree", out.get_obj())
return all(meta.version_id is not None for _, meta, _ in tree)


def fetch_worktree(
repo: "Repo",
remote: "Remote",
Expand Down Expand Up @@ -102,7 +109,7 @@ def push_worktree(
jobs: Optional[int] = None,
**kwargs,
) -> int:
from dvc_data.index import checkout
from dvc_data.index import DataIndex, checkout

view = worktree_view(
repo.index,
Expand All @@ -111,7 +118,16 @@ def push_worktree(
latest_only=remote.worktree,
**kwargs,
)
new_index = view.data["repo"]
if remote.worktree:
new_index = view.data["repo"]
else:
# We assume that if we have a version_id already, the specified object
# version still exists on the remote.
# See: https://github.com/iterative/dvc/issues/8359
new_index = DataIndex()
for key, entry in view.data["repo"].iteritems():
if entry.meta.version_id is None:
new_index[key] = entry
if remote.worktree:
logger.debug("indexing latest worktree for '%s'", remote.path)
old_index = _build_worktree_index(repo, remote, view)
Expand Down

0 comments on commit fb54f52

Please sign in to comment.