run: ask for confirmation when overwriting stage file

Fixes #974

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-08-04 18:44:13 +03:00
parent 48c9916937
commit ef7aa024f9
2 changed files with 11 additions and 2 deletions
+2 -1
View File
@@ -218,7 +218,8 @@ class Project(object):
outs=outs,
outs_no_cache=outs_no_cache,
metrics_no_cache=metrics_no_cache,
deps=deps)
deps=deps,
overwrite=False)
if not no_exec:
stage.run()
stage.dump()
+9 -1
View File
@@ -8,6 +8,7 @@ import posixpath
import dvc.dependency as dependency
import dvc.output as output
from dvc.exceptions import DvcException
from dvc.prompt import prompt
from dvc.logger import Logger
from dvc.utils import dict_md5
@@ -227,7 +228,8 @@ class Stage(object):
fname=None,
cwd=os.curdir,
locked=False,
add=False):
add=False,
overwrite=True):
stage = Stage(project=project,
cwd=cwd,
cmd=cmd,
@@ -244,6 +246,12 @@ class Stage(object):
cwd = os.path.abspath(cwd)
path = os.path.join(cwd, fname)
if os.path.exists(path):
relpath = os.path.relpath(path)
msg = "{} already exists. Do you wish to overwrite it?"
if not overwrite and not prompt(msg.format(relpath), False):
raise DvcException("{} already exists".format(relpath))
stage.cwd = cwd
stage.path = path