Skip to content

Commit d53b740

Browse files
authored
state: always use working trees (#3871)
* tests: add test case for push/pull with --all-commits * state: always use working tree
1 parent 9198fa7 commit d53b740

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

dvc/state.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from urllib.parse import urlencode, urlunparse
88

99
from dvc.exceptions import DvcException
10+
from dvc.scm.tree import WorkingTree
1011
from dvc.utils import current_timestamp, relpath, to_chunks
1112
from dvc.utils.fs import get_inode, get_mtime_and_size, remove
1213

@@ -91,6 +92,7 @@ class State: # pylint: disable=too-many-instance-attributes
9192
def __init__(self, repo):
9293
self.repo = repo
9394
self.root_dir = repo.root_dir
95+
self.tree = WorkingTree(self.root_dir)
9496

9597
state_config = repo.config.get("state", {})
9698
self.row_limit = state_config.get("row_limit", self.STATE_ROW_LIMIT)
@@ -364,9 +366,7 @@ def save(self, path_info, checksum):
364366
assert checksum is not None
365367
assert os.path.exists(path_info)
366368

367-
actual_mtime, actual_size = get_mtime_and_size(
368-
path_info, self.repo.tree
369-
)
369+
actual_mtime, actual_size = get_mtime_and_size(path_info, self.tree)
370370
actual_inode = get_inode(path_info)
371371

372372
existing_record = self.get_state_record_for_inode(actual_inode)
@@ -397,7 +397,7 @@ def get(self, path_info):
397397
if not os.path.exists(path):
398398
return None
399399

400-
actual_mtime, actual_size = get_mtime_and_size(path, self.repo.tree)
400+
actual_mtime, actual_size = get_mtime_and_size(path, self.tree)
401401
actual_inode = get_inode(path)
402402

403403
existing_record = self.get_state_record_for_inode(actual_inode)
@@ -423,7 +423,7 @@ def save_link(self, path_info):
423423
if not os.path.exists(path_info):
424424
return
425425

426-
mtime, _ = get_mtime_and_size(path_info, self.repo.tree)
426+
mtime, _ = get_mtime_and_size(path_info, self.tree)
427427
inode = get_inode(path_info)
428428
relative_path = relpath(path_info, self.root_dir)
429429

@@ -450,7 +450,7 @@ def get_unused_links(self, used):
450450
continue
451451

452452
actual_inode = get_inode(path)
453-
actual_mtime, _ = get_mtime_and_size(path, self.repo.tree)
453+
actual_mtime, _ = get_mtime_and_size(path, self.tree)
454454

455455
if (inode, mtime) == (actual_inode, actual_mtime):
456456
logger.debug("Removing '%s' as unused link.", path)

tests/func/test_data_cloud.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,3 +912,23 @@ def test_pull_stats(tmp_dir, dvc, caplog, setup_remote):
912912
with caplog.at_level(level=logging.INFO, logger="dvc"):
913913
main(["pull"])
914914
assert "Everything is up to date." in caplog.text
915+
916+
917+
@pytest.mark.parametrize(
918+
"key,expected", [("all_tags", 2), ("all_branches", 3), ("all_commits", 3)]
919+
)
920+
def test_push_pull_all(tmp_dir, scm, dvc, setup_remote, key, expected):
921+
setup_remote(dvc)
922+
tmp_dir.dvc_gen({"foo": "foo"}, commit="first")
923+
scm.tag("v1")
924+
dvc.remove("foo.dvc")
925+
tmp_dir.dvc_gen({"bar": "bar"}, commit="second")
926+
scm.tag("v2")
927+
with tmp_dir.branch("branch", new=True):
928+
dvc.remove("bar.dvc")
929+
tmp_dir.dvc_gen({"baz": "baz"}, commit="branch")
930+
931+
assert dvc.push(**{key: True}) == expected
932+
933+
clean(["foo", "bar", "baz"], dvc)
934+
assert dvc.pull(**{key: True})["fetched"] == expected

0 commit comments

Comments
 (0)