worktree push: only index known (tracked) files/dirs in the remote

This commit is contained in:
Peter Rowlands
2022-12-07 18:48:34 +09:00
committed by Peter Rowlands (변기호)
parent b9bf73f043
commit e98ca36f39
+22 -2
View File
@@ -94,7 +94,7 @@ def fetch_worktree(
def push_worktree(
repo: "Repo", remote: "Remote", targets: Optional["TargetType"] = None
) -> int:
from dvc_data.index import build, checkout
from dvc_data.index import checkout
view = worktree_view(
repo.index, push=True, targets=targets, latest_only=remote.worktree
@@ -102,7 +102,7 @@ def push_worktree(
new_index = view.data["repo"]
if remote.worktree:
logger.debug("indexing latest worktree for '%s'", remote.path)
old_index = build(remote.path, remote.fs)
old_index = _build_worktree_index(repo, remote, view)
logger.debug("Pushing worktree changes to '%s'", remote.path)
else:
old_index = None
@@ -140,6 +140,26 @@ def push_worktree(
return pushed
def _build_worktree_index(
repo: "Repo", remote: "Remote", view: "IndexView"
) -> "DataIndex":
from dvc_data.index import DataIndex
from dvc_data.index.build import build_entries
index = DataIndex()
for out in view.outs:
_workspace, key = out.index_key
parts = out.fs.path.relparts(out.fs_path, repo.root_dir)
path = remote.fs.path.join(remote.path, *parts)
for entry in build_entries(path, remote.fs):
if not entry.key or entry.key == ("",):
entry.key = key
else:
entry.key = key + entry.key
index.add(entry)
return index
def _update_out_meta(
out: "Output", index: Union["DataIndex", "DataIndexView"]
):