run: introduce --no-commit

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2019-02-16 21:18:26 +02:00
parent 0eab7ed29e
commit 3bc0b9728b
4 changed files with 23 additions and 3 deletions
+7
View File
@@ -42,6 +42,7 @@ class CmdRun(CmdBase):
overwrite=overwrite,
ignore_build_cache=self.args.ignore_build_cache,
remove_outs=self.args.remove_outs,
no_commit=self.args.no_commit,
)
except DvcException:
logger.error("failed to run command")
@@ -167,6 +168,12 @@ def add_parser(subparsers, parent_parser):
default=False,
help="Remove outputs before running the command.",
)
run_parser.add_argument(
"--no-commit",
action="store_true",
default=False,
help="Don't put files/directories into cache.",
)
run_parser.add_argument(
"command", nargs=argparse.REMAINDER, help="Command to execute."
)
+2 -1
View File
@@ -15,6 +15,7 @@ def run(
overwrite=False,
ignore_build_cache=False,
remove_outs=False,
no_commit=False,
):
from dvc.stage import Stage
@@ -53,7 +54,7 @@ def run(
self.files_to_git_add = []
with self.state:
if not no_exec:
stage.run()
stage.run(no_commit=no_commit)
stage.dump()
+3 -2
View File
@@ -589,7 +589,7 @@ class Stage(object):
if p.returncode != 0:
raise StageCmdFailedError(self)
def run(self, dry=False, resume=False):
def run(self, dry=False, resume=False, no_commit=False):
if self.locked:
logger.info(
"Verifying outputs in locked stage '{stage}'".format(
@@ -629,7 +629,8 @@ class Stage(object):
if not dry:
self.save()
self.commit()
if not no_commit:
self.commit()
def check_missing_outputs(self):
paths = [
+11
View File
@@ -628,3 +628,14 @@ class TestRunDeterministicChangedCmd(TestRunDeterministicBase):
self.cmd += " arg"
with self.assertRaises(StageFileAlreadyExistsError):
self._run()
class TestRunNoCommit(TestDvc):
def test(self):
fname = "test"
ret = main(
["run", "-o", "foo", "--no-commit", "echo", "test", ">", fname]
)
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(fname))
self.assertEqual(len(os.listdir(self.dvc.cache.local.cache_dir)), 0)