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

add: do not delete stage files before add #6239

Merged
merged 3 commits into from
Jul 3, 2021
Merged
Changes from 1 commit
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
9 changes: 4 additions & 5 deletions dvc/repo/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,11 @@ def add( # noqa: C901
**kwargs,
)

# remove existing stages that are to-be replaced with these
# new stages for the graph checks.
old_stages = set(repo.stages) - set(stages)
try:
repo.check_modified_graph(stages)
repo.check_modified_graph(stages, list(old_stages))
Comment on lines +101 to +105
Copy link
Member Author

@skshetry skshetry Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be better reflected by Index here, as we are creating a new index. Index is a collection of stages, so if some stages underneath are changed, is it the same index? So, immutability is at the heart of the index and would have been better reflected here.

new_index = repo.index.update(stages)
try:
    new_index.check_graph()

except OverlappingOutputPathsError as exc:
msg = (
"Cannot add '{out}', because it is overlapping with other "
Expand Down Expand Up @@ -233,7 +236,6 @@ def _create_stages(
transfer=False,
**kwargs,
):
from dvc.dvcfile import Dvcfile
from dvc.stage import Stage, create_stage, restore_meta

expanded_targets = glob_targets(targets, glob=glob)
Expand All @@ -259,12 +261,9 @@ def _create_stages(
external=external,
)
restore_meta(stage)
Dvcfile(repo, stage.path).remove()
if desc:
stage.outs[0].desc = desc

repo._reset() # pylint: disable=protected-access

if not stage:
if pbar is not None:
pbar.total -= 1
Expand Down