Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: open: handle dirty state in RepoTree #4548

Merged
merged 1 commit into from
Sep 9, 2020
Merged

Conversation

efiop
Copy link
Member

@efiop efiop commented Sep 9, 2020

We used to use that logic in DvcTree back before we had proper trees.
Now we have a RepoTree, that combines git/workspace tree with the
DvcTree and dirty state clearly belongs to the git/workspace and not
the dvc itself, as dvc state only depends on dvc-files and lock-files.

Prerequisite for #4523

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™

@efiop efiop requested a review from pmrowla September 9, 2020 02:07
We used to use that logic in DvcTree back before we had proper trees.
Now we have a RepoTree, that combines git/workspace tree with the
DvcTree and dirty state clearly belongs to the git/workspace and not
the dvc itself, as dvc state only depends on dvc-files and lock-files.

Prerequisite for iterative#4523
@pmrowla
Copy link
Contributor

pmrowla commented Sep 9, 2020

This looks good for dirty state w/open(), but we still don't handle dirty dirs in RepoTree.walk().

If I add the following test to tests/unit/tree/test_repo.py:

def test_walk_dirty(tmp_dir, dvc, scm):
    from dvc.utils.fs import remove

    tmp_dir.dvc_gen(
        {"dir": {"foo": "foo1", "bar": "bar1"}},
        commit="init",
    )
    tmp_dir.gen({"dir": {"bar": "bar2", "baz": "baz1"}})
    remove(str(tmp_dir / "foo"))
    tree = RepoTree(dvc)

    expected = [
        PathInfo("dir") / "bar",
        PathInfo("dir") / "baz",
    ]

    actual = []
    for root, dirs, files in tree.walk("dir"):
        for entry in dirs + files:
            actual.append(os.path.join(root, entry))

    assert (tmp_dir /"dir" / "bar").read_text() == "bar2"
    expected = [str(path) for path in expected]
    assert set(actual) == set(expected)
    assert len(actual) == len(expected)

We get

E       AssertionError: assert {'dir/baz', 'dir/foo', 'dir/bar'} == {'dir/baz', 'dir/bar'}
E         Extra items in the left set:
E         'dir/foo'
E         Full diff:
E         - {'dir/baz', 'dir/bar'}
E         + {'dir/baz', 'dir/foo', 'dir/bar'}
E         ?             +++++++++++

/Users/pmrowla/git/dvc/tests/unit/tree/test_repo.py:524: AssertionError

So for a dirty directory and RepoTree.walk() we handle modified and added files, but not removed files. DvcTree.walk() yields every expected file in the directory (as it probably should), but RepoTree.walk() does not check to make sure the dvctree files still exist in the dirty local workspace.

@efiop
Copy link
Member Author

efiop commented Sep 9, 2020

@pmrowla Correct, this is me just starting out migrating the existing dirty functionality from DvcTree to RepoTree. Walk, get_hash and other calls will need to be fixed. So we are on the same page here.

@efiop efiop merged commit 1ca2dc1 into iterative:master Sep 9, 2020
@efiop efiop deleted the fix-4523 branch September 9, 2020 16:21
@efiop efiop restored the fix-4523 branch September 9, 2020 16:21
@efiop
Copy link
Member Author

efiop commented Sep 10, 2020

@pmrowla btw, your test seems incorrect. You delete tmp_dir / "foo", but you probably meant tmp_dir / "dir" / "foo", right?

@pmrowla
Copy link
Contributor

pmrowla commented Sep 10, 2020

@pmrowla btw, your test seems incorrect. You delete tmp_dir / "foo", but you probably meant tmp_dir / "dir" / "foo", right?

Good catch, that was my mistake, I tried it again with the fixed test and it passes πŸ‘

@efiop efiop added the bugfix fixes bug label Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix fixes bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants