mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-02 07:18:25 +01:00
add: introduce --no-commit
Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
+11
-1
@@ -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
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user