add: introduce --no-commit

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2019-02-16 21:18:54 +02:00
parent 3bc0b9728b
commit 99f4107d58
3 changed files with 22 additions and 3 deletions
+11 -1
View File
@@ -9,7 +9,11 @@ class CmdAdd(CmdBase):
def run(self):
for target in self.args.targets:
try:
self.repo.add(target, recursive=self.args.recursive)
self.repo.add(
target,
recursive=self.args.recursive,
no_commit=self.args.no_commit,
)
except DvcException:
logger.error("failed to add file")
return 1
@@ -28,6 +32,12 @@ def add_parser(subparsers, parent_parser):
default=False,
help="Recursively add each file under the directory.",
)
add_parser.add_argument(
"--no-commit",
action="store_true",
default=False,
help="Don't put files/directories into cache.",
)
add_parser.add_argument(
"targets", nargs="+", help="Input files/directories."
)
+3 -2
View File
@@ -1,7 +1,7 @@
import os
def add(self, fname, recursive=False):
def add(self, fname, recursive=False, no_commit=False):
from dvc.stage import Stage
fnames = []
@@ -30,7 +30,8 @@ def add(self, fname, recursive=False):
continue
stage.save()
stage.commit()
if not no_commit:
stage.commit()
stages.append(stage)
self.check_dag(self.stages() + stages)
+8
View File
@@ -264,3 +264,11 @@ class TestShouldUpdateStateEntryForDirectoryAfterAdd(TestDvc):
)
self.assertEqual(ret, 0)
self.assertEqual(file_md5_counter.mock.call_count, 3)
class TestAddNoCommit(TestDvc):
def test(self):
ret = main(["add", self.FOO, "--no-commit"])
self.assertEqual(ret, 0)
self.assertTrue(os.path.isfile(self.FOO))
self.assertEqual(len(os.listdir(self.dvc.cache.local.cache_dir)), 0)