Skip to content

Commit

Permalink
state: always use working trees (iterative#3871)
Browse files Browse the repository at this point in the history
* tests: add test case for push/pull with --all-commits

* state: always use working tree
  • Loading branch information
pmrowla authored May 25, 2020
1 parent 9198fa7 commit d53b740
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
12 changes: 6 additions & 6 deletions dvc/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
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

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -364,9 +366,7 @@ def save(self, path_info, checksum):
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)
Expand Down Expand Up @@ -397,7 +397,7 @@ def get(self, path_info):
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)
Expand All @@ -423,7 +423,7 @@ def save_link(self, path_info):
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)

Expand All @@ -450,7 +450,7 @@ def get_unused_links(self, used):
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)
Expand Down
20 changes: 20 additions & 0 deletions tests/func/test_data_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit d53b740

Please sign in to comment.