Files
dvc/tests/unit/test_external_repo.py
T
b349b39d62 Decoupling dvcignore and fs (#5812)
* Decoupling dvcignore and fs

[x] remove dvcignore from fs objects
[x] attach dvcignore to repo
[x] add ignore check to functions(add, checkout, output, pipeline, etc)
[x] pass all tests
[x] final check

* Solve all of the arugments error.

* add dvcignore to dvc list

* Solve some test_ignore cases

* add dvcignore to checkout.

1. add dvcignore to 'checkout', 'add'
2. add ignore_filter to fs

* Solve two tests

* Get rid of ignore_filter

* Add ignore examine to download

* Solve a test issue

* Solve dvcignore and subrepo problems

* Solve sub repo error

* Revert some changes

* pass all tests

* Remove debug codes

* Some final exams

* dvcignore trie tree only update when needed

* reuse of the dir result in path walk.

* Some change after code review.

* Recover something from false `--force` push

* add abspath trans to dvcginore

* pass pylint

* pylint related

* Update dvc/fs/repo.py

Co-authored-by: Ruslan Kuprieiev <[email protected]>

* Changes related to reviews.

* dvcignore call api change

from dvcignore.walk_files(fs.walk(path_info)) to dvcignore.walk_files(fs, path_info)

* Get rid of PathInfo in test_ignore.py

* fs.walk follow the arguments of os.walk

* Dvcignore as parameters

* pass dvcignore as arguments to checkouts

* Decoupling state and repo

* Update dvc/dvcfile.py

Co-authored-by: Paweł Redzyński <[email protected]>

* Update dvc/objects/stage.py

Co-authored-by: Paweł Redzyński <[email protected]>

* Solve some small problems

* Add tests to verify that dependency now not ignore

fix#5256

* Update dvc/ignore.py

* Update dvc/fs/git.py

* Update dvc/repo/__init__.py

* Some small improvements

* pass black

* Refactor is_ignored

* Update dvc/output/base.py

* repofs: use dvcignore in exists/isdir/isfile

Per https://github.com/iterative/dvc/pull/5812/files#r630604524

Co-authored-by: myname <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
Co-authored-by: Paweł Redzyński <[email protected]>
Co-authored-by: Ruslan Kuprieiev <[email protected]>
2021-05-12 05:29:04 +03:00

91 lines
2.8 KiB
Python

import os
from unittest.mock import call
import pytest
from dvc.external_repo import external_repo
from tests.unit.fs.test_repo import make_subrepo
def test_hook_is_called(tmp_dir, erepo_dir, mocker):
subrepo_paths = [
"subrepo1",
"subrepo2",
os.path.join("dir", "subrepo3"),
os.path.join("dir", "subrepo4"),
"subrepo5",
os.path.join("subrepo5", "subrepo6"),
]
subrepos = [erepo_dir / path for path in subrepo_paths]
for repo in subrepos:
make_subrepo(repo, erepo_dir.scm)
for repo in subrepos + [erepo_dir]:
with repo.chdir():
repo.scm_gen("foo", "foo", commit=f"git add {repo}/foo")
repo.dvc_gen("bar", "bar", commit=f"dvc add {repo}/bar")
with external_repo(str(erepo_dir)) as repo:
spy = mocker.spy(repo.repo_fs, "repo_factory")
list(repo.repo_fs.walk(repo.root_dir, ignore_subrepos=False)) # drain
assert spy.call_count == len(subrepos)
paths = [os.path.join(repo.root_dir, path) for path in subrepo_paths]
spy.assert_has_calls(
[
call(
path,
scm=repo.scm,
rev=repo.get_rev(),
repo_factory=repo.repo_fs.repo_factory,
)
for path in paths
],
any_order=True,
)
@pytest.mark.parametrize("root_is_dvc", [False, True])
def test_subrepo_is_constructed_properly(
tmp_dir, scm, mocker, make_tmp_dir, root_is_dvc
):
if root_is_dvc:
make_subrepo(tmp_dir, scm)
subrepo = tmp_dir / "subrepo"
make_subrepo(subrepo, scm)
local_cache = subrepo.dvc.odb.local.cache_dir
tmp_dir.scm_gen("bar", "bar", commit="add bar")
subrepo.dvc_gen("foo", "foo", commit="add foo")
cache_dir = make_tmp_dir("temp-cache")
with external_repo(
str(tmp_dir), cache_dir=str(cache_dir), cache_types=["symlink"]
) as repo:
spy = mocker.spy(repo.repo_fs, "repo_factory")
list(repo.repo_fs.walk(repo.root_dir, ignore_subrepos=False)) # drain
assert spy.call_count == 1
subrepo = spy.spy_return
assert repo.url == str(tmp_dir)
assert repo.config["cache"]["dir"] == str(cache_dir)
assert repo.odb.local.cache_dir == str(cache_dir)
assert subrepo.odb.local.cache_dir == str(cache_dir)
assert repo.config["cache"]["type"] == ["symlink"]
assert repo.odb.local.cache_types == ["symlink"]
assert subrepo.odb.local.cache_types == ["symlink"]
assert (
subrepo.config["remote"]["auto-generated-upstream"]["url"]
== local_cache
)
if root_is_dvc:
main_cache = tmp_dir.dvc.odb.local.cache_dir
assert repo.config["remote"]["auto-generated-upstream"][
"url"
] == str(main_cache)