|
6 | 6 | from funcy import merge |
7 | 7 |
|
8 | 8 | from .local import DependencyLOCAL |
| 9 | +from dvc.external_repo import cached_clone |
9 | 10 | from dvc.external_repo import external_repo |
| 11 | +from dvc.exceptions import NotDvcRepoError |
10 | 12 | from dvc.exceptions import OutputNotFoundError |
11 | 13 | from dvc.exceptions import PathMissingError |
12 | 14 | from dvc.utils.fs import fs_copy |
@@ -75,27 +77,35 @@ def fetch(self): |
75 | 77 | return out |
76 | 78 |
|
77 | 79 | @staticmethod |
78 | | - def _is_git_file(repo, path): |
79 | | - if not os.path.isabs(path): |
80 | | - try: |
81 | | - output = repo.find_out_by_relpath(path) |
82 | | - if not output.use_cache: |
83 | | - return True |
84 | | - except OutputNotFoundError: |
85 | | - return True |
86 | | - return False |
| 80 | + def _is_git_file(repo_dir, path): |
| 81 | + from dvc.repo import Repo |
| 82 | + |
| 83 | + if os.path.isabs(path): |
| 84 | + return False |
| 85 | + |
| 86 | + try: |
| 87 | + repo = Repo(repo_dir) |
| 88 | + except NotDvcRepoError: |
| 89 | + return True |
| 90 | + |
| 91 | + try: |
| 92 | + output = repo.find_out_by_relpath(path) |
| 93 | + return not output.use_cache |
| 94 | + except OutputNotFoundError: |
| 95 | + return True |
| 96 | + finally: |
| 97 | + repo.close() |
87 | 98 |
|
88 | 99 | def _copy_if_git_file(self, to_path): |
89 | 100 | src_path = self.def_path |
90 | | - with self._make_repo( |
91 | | - cache_dir=self.repo.cache.local.cache_dir |
92 | | - ) as repo: |
93 | | - if not self._is_git_file(repo, src_path): |
94 | | - return False |
| 101 | + repo_dir = cached_clone(**self.def_repo) |
| 102 | + |
| 103 | + if not self._is_git_file(repo_dir, src_path): |
| 104 | + return False |
95 | 105 |
|
96 | | - src_full_path = os.path.join(repo.root_dir, src_path) |
97 | | - dst_full_path = os.path.abspath(to_path) |
98 | | - fs_copy(src_full_path, dst_full_path) |
| 106 | + src_full_path = os.path.join(repo_dir, src_path) |
| 107 | + dst_full_path = os.path.abspath(to_path) |
| 108 | + fs_copy(src_full_path, dst_full_path) |
99 | 109 | return True |
100 | 110 |
|
101 | 111 | def download(self, to): |
|
0 commit comments