Skip to content

Commit 29afb38

Browse files
authored
Merge pull request #3018 from pared/2914_3
local-related methods should verify that WorkingTree is in use
2 parents 7f92cc3 + 3642738 commit 29afb38

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

dvc/remote/local.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from dvc.exceptions import DownloadError
1212
from dvc.exceptions import DvcException
1313
from dvc.exceptions import UploadError
14-
from dvc.ignore import CleanTree
1514
from dvc.path_info import PathInfo
1615
from dvc.progress import Tqdm
1716
from dvc.remote.base import RemoteBASE
@@ -20,7 +19,7 @@
2019
from dvc.remote.base import STATUS_MISSING
2120
from dvc.remote.base import STATUS_NEW
2221
from dvc.scheme import Schemes
23-
from dvc.scm.tree import WorkingTree
22+
from dvc.scm.tree import is_working_tree
2423
from dvc.system import System
2524
from dvc.utils import copyfile
2625
from dvc.utils import file_md5
@@ -136,9 +135,7 @@ def getsize(path_info):
136135
return os.path.getsize(fspath_py35(path_info))
137136

138137
def walk_files(self, path_info):
139-
assert isinstance(self.repo.tree, CleanTree) and isinstance(
140-
self.repo.tree.tree, WorkingTree
141-
)
138+
assert is_working_tree(self.repo.tree)
142139

143140
for fname in self.repo.tree.walk_files(path_info):
144141
yield PathInfo(fname)
@@ -429,7 +426,7 @@ def _unprotect_file(path):
429426
os.chmod(path, os.stat(path).st_mode | stat.S_IWRITE)
430427

431428
def _unprotect_dir(self, path):
432-
assert isinstance(self.repo.tree, CleanTree)
429+
assert is_working_tree(self.repo.tree)
433430

434431
for fname in self.repo.tree.walk_files(path):
435432
RemoteLOCAL._unprotect_file(fname)

dvc/scm/tree.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,9 @@ def onerror(e):
7474
top, topdown=topdown, onerror=onerror
7575
):
7676
yield os.path.normpath(root), dirs, files
77+
78+
79+
def is_working_tree(tree):
80+
return isinstance(tree, WorkingTree) or isinstance(
81+
getattr(tree, "tree", None), WorkingTree
82+
)

dvc/utils/fs.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from shortuuid import uuid
99

1010
from dvc.exceptions import DvcException
11+
from dvc.scm.tree import is_working_tree
1112
from dvc.system import System
1213
from dvc.utils import dict_md5
1314
from dvc.utils import fspath
@@ -32,11 +33,10 @@ def get_inode(path):
3233

3334

3435
def get_mtime_and_size(path, tree):
35-
from dvc.ignore import CleanTree
36-
37-
assert isinstance(tree, CleanTree)
3836

3937
if os.path.isdir(fspath_py35(path)):
38+
assert is_working_tree(tree)
39+
4040
size = 0
4141
files_mtimes = {}
4242
for file_path in tree.walk_files(path):

0 commit comments

Comments
 (0)