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

worktree push: do not push existing versions #8606

Merged
merged 2 commits into from
Nov 23, 2022
Merged
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
31 changes: 26 additions & 5 deletions dvc/repo/worktree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from typing import TYPE_CHECKING, Optional

from dvc.fs.callbacks import Callback

if TYPE_CHECKING:
from dvc.cloud import Remote
from dvc.index import Index, IndexView
Expand Down Expand Up @@ -30,7 +32,11 @@ def stage_filter(stage: "Stage") -> bool:
return True

def outs_filter(out: "Output") -> bool:
if not out.is_in_repo or (push and not out.can_push):
if (
not out.is_in_repo
or not out.use_cache
or (push and not out.can_push)
):
return False
return True

Expand All @@ -53,8 +59,12 @@ def fetch_worktree(repo: "Repo", remote: "Remote") -> int:
remote.path,
*key,
)
save(index)
return len(index)
total = len(index)
with Callback.as_tqdm_callback(
unit="file", desc="Fetch", disable=total == 0
) as cb:
cb.set_size(total)
return save(index, callback=cb)


def push_worktree(repo: "Repo", remote: "Remote") -> int:
Expand All @@ -63,7 +73,18 @@ def push_worktree(repo: "Repo", remote: "Remote") -> int:

view = worktree_view(repo.index, push=True)
index = view.data["repo"]
checkout(index, remote.path, remote.fs)
total = len(index)
with Callback.as_tqdm_callback(
unit="file", desc="Push", disable=total == 0
) as cb:
cb.set_size(total)
pushed = checkout(
index,
remote.path,
remote.fs,
latest_only=False,
callback=cb,
)

for stage in view.stages:
for out in stage.outs:
Expand Down Expand Up @@ -97,4 +118,4 @@ def push_worktree(repo: "Repo", remote: "Remote") -> int:
out.meta = entry.meta
stage.dvcfile.dump(stage, with_files=True, update_pipeline=False)

return len(index)
return pushed