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

Stage: create: reset repo when removing existing stage #3349

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def locked(f):
@wraps(f)
def wrapper(repo, *args, **kwargs):
with repo.lock, repo.state:
repo._reset()
ret = f(repo, *args, **kwargs)
# Our graph cache is no longer valid after we release the repo.lock
repo._reset()
Expand Down
1 change: 1 addition & 0 deletions dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def _create_stages(repo, targets, fname, pbar=None):
stage = Stage.create(
repo, outs=[out], accompany_outs=True, fname=fname
)
repo._reset()

if not stage:
if pbar is not None:
Expand Down
7 changes: 7 additions & 0 deletions tests/func/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,3 +655,10 @@ def test_add_from_data_dir(tmp_dir, scm, dvc):
"tracked output: 'dir'.\n"
"To include '{out}' in 'dir', run 'dvc commit dir.dvc'"
).format(out=os.path.join("dir", "file2"))


def test_not_raises_on_re_add(tmp_dir, dvc):
tmp_dir.dvc_gen("file", "file content")

tmp_dir.gen({"file2": "file2 content", "file": "modified file"})
dvc.add(["file2", "file"])
17 changes: 17 additions & 0 deletions tests/unit/repo/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import pytest

from dvc.repo import locked


def test_is_dvc_internal(dvc):
assert dvc.is_dvc_internal(os.path.join("path", "to", ".dvc", "file"))
Expand Down Expand Up @@ -49,3 +51,18 @@ def test_used_cache(tmp_dir, dvc, path):
used_cache._items == expected._items
and used_cache.external == expected.external
)


def test_locked(mocker):
repo = mocker.MagicMock()
repo.method = locked(repo.method)

args = {}
kwargs = {}
repo.method(repo, args, kwargs)

assert repo.method_calls == [
mocker.call._reset(),
mocker.call.method(repo, args, kwargs),
mocker.call._reset(),
]