Skip to content

Commit

Permalink
Stage: create: reset repo after new stage creation (#3349)
Browse files Browse the repository at this point in the history
  • Loading branch information
pared authored Feb 19, 2020
1 parent a9161af commit 9b2ef00
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
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(),
]

0 comments on commit 9b2ef00

Please sign in to comment.