mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
* erepo: load external repos directly from git tree * erepo: add fetch_external * remote/RepoTree: add callback for keeping track of download counts when saving tree to cache * repo: use erepo.fetch_external() in repo.fetch() * erepo: return cache save_infos in fetch_external * DependencyRepo: use erepo.fetch_external and cache.checkout instead of pull_to * erepo: remove pull_to * DvcTree: support granularity for isdir() * DvcTree: fix indentation bug * RepoTree: add copytree() method * LocalRemote: use working tree for local cache walk_files * repo: state should be noop for GitTree based erepos * erepo: add get_external() * test_get: remove unneeded caplog check * erepo: add get_rev() * tests: fix erepo test bug * ls: use RepoTree * remote: support trees in _collect_dir * remote: support trees in get_dir_checksum * RepoTree: fix dir_cache relpaths in windows * remote: fix duplicated fetch bug * utils: don't skip md5 dos2unix check for git blobs * otherwise md5 checksums will not match when comparing git version to cached filesystem version on windows
124 lines
3.6 KiB
Python
124 lines
3.6 KiB
Python
import os
|
|
|
|
from mock import patch
|
|
|
|
from dvc.external_repo import external_repo
|
|
from dvc.path_info import PathInfo
|
|
from dvc.remote import LocalRemote
|
|
from dvc.scm.git import Git
|
|
from dvc.utils import relpath
|
|
from dvc.utils.fs import remove
|
|
|
|
|
|
def test_external_repo(erepo_dir):
|
|
with erepo_dir.chdir():
|
|
with erepo_dir.branch("branch", new=True):
|
|
erepo_dir.dvc_gen("file", "branch", commit="create file on branch")
|
|
erepo_dir.dvc_gen("file", "master", commit="create file on master")
|
|
|
|
url = os.fspath(erepo_dir)
|
|
|
|
with patch.object(Git, "clone", wraps=Git.clone) as mock:
|
|
with external_repo(url) as repo:
|
|
with repo.open_by_relpath("file") as fd:
|
|
assert fd.read() == "master"
|
|
|
|
with external_repo(url, rev="branch") as repo:
|
|
with repo.open_by_relpath("file") as fd:
|
|
assert fd.read() == "branch"
|
|
|
|
assert mock.call_count == 1
|
|
|
|
|
|
def test_source_change(erepo_dir):
|
|
url = os.fspath(erepo_dir)
|
|
with external_repo(url) as repo:
|
|
old_rev = repo.scm.get_rev()
|
|
|
|
erepo_dir.scm_gen("file", "text", commit="a change")
|
|
|
|
with external_repo(url) as repo:
|
|
new_rev = repo.scm.get_rev()
|
|
|
|
assert old_rev != new_rev
|
|
|
|
|
|
def test_cache_reused(erepo_dir, mocker, setup_remote):
|
|
setup_remote(erepo_dir.dvc)
|
|
with erepo_dir.chdir():
|
|
erepo_dir.dvc_gen("file", "text", commit="add file")
|
|
erepo_dir.dvc.push()
|
|
|
|
download_spy = mocker.spy(LocalRemote, "download")
|
|
|
|
# Use URL to prevent any fishy optimizations
|
|
url = f"file://{erepo_dir}"
|
|
with external_repo(url) as repo:
|
|
repo.fetch()
|
|
assert download_spy.mock.call_count == 1
|
|
|
|
# Should not download second time
|
|
erepo_dir.scm.branch("branch")
|
|
with external_repo(url, "branch") as repo:
|
|
repo.fetch()
|
|
assert download_spy.mock.call_count == 1
|
|
|
|
|
|
def test_known_sha(erepo_dir):
|
|
erepo_dir.scm.commit("init")
|
|
|
|
url = f"file://{erepo_dir}"
|
|
with external_repo(url) as repo:
|
|
rev = repo.scm.get_rev()
|
|
prev_rev = repo.scm.resolve_rev("HEAD^")
|
|
|
|
# Hits cache
|
|
with external_repo(url, rev) as repo:
|
|
pass
|
|
|
|
# No clone, no pull, copies a repo, checks out the known sha
|
|
with external_repo(url, prev_rev) as repo:
|
|
pass
|
|
|
|
|
|
def test_pull_subdir_file(tmp_dir, erepo_dir):
|
|
with erepo_dir.chdir():
|
|
subdir = erepo_dir / "subdir"
|
|
subdir.mkdir()
|
|
(subdir / "file").write_text("contents")
|
|
erepo_dir.dvc_add(subdir / "file", commit="create file")
|
|
|
|
dest = tmp_dir / "file"
|
|
with external_repo(os.fspath(erepo_dir)) as repo:
|
|
_, _, save_infos = repo.fetch_external(
|
|
[os.path.join("subdir", "file")]
|
|
)
|
|
repo.cache.local.checkout(PathInfo(dest), save_infos[0])
|
|
|
|
assert dest.is_file()
|
|
assert dest.read_text() == "contents"
|
|
|
|
|
|
def test_relative_remote(erepo_dir, tmp_dir, setup_remote):
|
|
# these steps reproduce the script on this issue:
|
|
# https://github.com/iterative/dvc/issues/2756
|
|
with erepo_dir.chdir():
|
|
erepo_dir.dvc_gen("file", "contents", commit="create file")
|
|
|
|
upstream_dir = tmp_dir
|
|
upstream_url = relpath(upstream_dir, erepo_dir)
|
|
setup_remote(erepo_dir.dvc, url=upstream_url, name="upstream")
|
|
|
|
erepo_dir.dvc.push()
|
|
|
|
(erepo_dir / "file").unlink()
|
|
remove(erepo_dir.dvc.cache.local.cache_dir)
|
|
|
|
url = os.fspath(erepo_dir)
|
|
|
|
with external_repo(url) as repo:
|
|
assert os.path.isabs(repo.config["remote"]["upstream"]["url"])
|
|
assert os.path.isdir(repo.config["remote"]["upstream"]["url"])
|
|
with repo.open_by_relpath("file") as fd:
|
|
assert fd.read() == "contents"
|