checkout: add --with-deps support

Fixes #1296

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-11-06 14:19:38 +02:00
parent f00d08d46d
commit 7720c35544
4 changed files with 28 additions and 4 deletions
+7
View File
@@ -184,6 +184,13 @@ def parse_args(argv=None):
parents=[parent_parser],
description=CHECKOUT_HELP,
help=CHECKOUT_HELP)
checkout_parser.add_argument(
'-d',
'--with-deps',
action='store_true',
default=False,
help='Checkout all dependencies of the '
'specified target.')
checkout_parser.add_argument(
'targets',
nargs='*',
+2 -1
View File
@@ -7,5 +7,6 @@ class CmdCheckout(CmdBase):
self.project.checkout()
else:
for target in self.args.targets:
self.project.checkout(target=target)
self.project.checkout(target=target,
with_deps=self.args.with_deps)
return 0
+4 -3
View File
@@ -449,11 +449,12 @@ class Project(object):
used.append(out.path)
self.state.remove_unused_links(used)
def checkout(self, target=None):
def checkout(self, target=None, with_deps=False):
all_stages = self.active_stages()
if target:
stages = [Stage.load(self, target)]
stages = self._collect(target,
with_deps=with_deps)
else:
stages = all_stages
@@ -701,7 +702,7 @@ class Project(object):
all_tags=all_tags,
show_checksums=show_checksums,
with_deps=with_deps)
self.checkout(target=target)
self.checkout(target=target, with_deps=with_deps)
def _local_status(self, target=None):
status = {}
+15
View File
@@ -246,3 +246,18 @@ class TestCheckoutNotCachedFile(TestDvc):
outs_no_cache=['out'])
self.dvc.checkout()
class TestCheckoutWithDeps(TestRepro):
def test(self):
os.unlink(self.FOO)
os.unlink(self.file1)
self.assertFalse(os.path.exists(self.FOO))
self.assertFalse(os.path.exists(self.file1))
ret = main(['checkout', self.file1_stage, '--with-deps'])
self.assertEqual(ret, 0)
self.assertTrue(os.path.exists(self.FOO))
self.assertTrue(os.path.exists(self.file1))