diff --git a/dvc/state.py b/dvc/state.py index 3ca5091fa..ba22d614e 100644 --- a/dvc/state.py +++ b/dvc/state.py @@ -7,6 +7,7 @@ import sqlite3 from urllib.parse import urlencode, urlunparse from dvc.exceptions import DvcException +from dvc.scm.tree import WorkingTree from dvc.utils import current_timestamp, relpath, to_chunks from dvc.utils.fs import get_inode, get_mtime_and_size, remove @@ -91,6 +92,7 @@ class State: # pylint: disable=too-many-instance-attributes def __init__(self, repo): self.repo = repo self.root_dir = repo.root_dir + self.tree = WorkingTree(self.root_dir) state_config = repo.config.get("state", {}) self.row_limit = state_config.get("row_limit", self.STATE_ROW_LIMIT) @@ -364,9 +366,7 @@ class State: # pylint: disable=too-many-instance-attributes assert checksum is not None assert os.path.exists(path_info) - actual_mtime, actual_size = get_mtime_and_size( - path_info, self.repo.tree - ) + actual_mtime, actual_size = get_mtime_and_size(path_info, self.tree) actual_inode = get_inode(path_info) existing_record = self.get_state_record_for_inode(actual_inode) @@ -397,7 +397,7 @@ class State: # pylint: disable=too-many-instance-attributes if not os.path.exists(path): return None - actual_mtime, actual_size = get_mtime_and_size(path, self.repo.tree) + actual_mtime, actual_size = get_mtime_and_size(path, self.tree) actual_inode = get_inode(path) existing_record = self.get_state_record_for_inode(actual_inode) @@ -423,7 +423,7 @@ class State: # pylint: disable=too-many-instance-attributes if not os.path.exists(path_info): return - mtime, _ = get_mtime_and_size(path_info, self.repo.tree) + mtime, _ = get_mtime_and_size(path_info, self.tree) inode = get_inode(path_info) relative_path = relpath(path_info, self.root_dir) @@ -450,7 +450,7 @@ class State: # pylint: disable=too-many-instance-attributes continue actual_inode = get_inode(path) - actual_mtime, _ = get_mtime_and_size(path, self.repo.tree) + actual_mtime, _ = get_mtime_and_size(path, self.tree) if (inode, mtime) == (actual_inode, actual_mtime): logger.debug("Removing '%s' as unused link.", path) diff --git a/tests/func/test_data_cloud.py b/tests/func/test_data_cloud.py index 9a55eae81..bbb201c29 100644 --- a/tests/func/test_data_cloud.py +++ b/tests/func/test_data_cloud.py @@ -912,3 +912,23 @@ def test_pull_stats(tmp_dir, dvc, caplog, setup_remote): with caplog.at_level(level=logging.INFO, logger="dvc"): main(["pull"]) assert "Everything is up to date." in caplog.text + + +@pytest.mark.parametrize( + "key,expected", [("all_tags", 2), ("all_branches", 3), ("all_commits", 3)] +) +def test_push_pull_all(tmp_dir, scm, dvc, setup_remote, key, expected): + setup_remote(dvc) + tmp_dir.dvc_gen({"foo": "foo"}, commit="first") + scm.tag("v1") + dvc.remove("foo.dvc") + tmp_dir.dvc_gen({"bar": "bar"}, commit="second") + scm.tag("v2") + with tmp_dir.branch("branch", new=True): + dvc.remove("bar.dvc") + tmp_dir.dvc_gen({"baz": "baz"}, commit="branch") + + assert dvc.push(**{key: True}) == expected + + clean(["foo", "bar", "baz"], dvc) + assert dvc.pull(**{key: True})["fetched"] == expected