From 69da5d1e872c739b429a5599705dae952250cf5e Mon Sep 17 00:00:00 2001 From: Muhammad Usman Date: Fri, 4 Oct 2024 20:55:48 +0500 Subject: [PATCH] Add option to specify git clone options like --depth for Zephyr repo clone via init --- src/west/app/project.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/west/app/project.py b/src/west/app/project.py index 54c35493..c6c59794 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -177,7 +177,7 @@ def do_add_parser(self, parser_adder): parser_adder, usage=''' - %(prog)s [-m URL] [--mr REVISION] [--mf FILE] [directory] + %(prog)s [-m URL] [--mr REVISION] [--mf FILE] [-o=GIT_CLONE_OPTION] [directory] %(prog)s -l [--mf FILE] directory ''') @@ -186,6 +186,10 @@ def do_add_parser(self, parser_adder): parser.add_argument('-m', '--manifest-url', help='''manifest repository URL to clone; cannot be combined with -l''') + parser.add_argument('-o', '--clone-opt', action='append', default=[], + help='''additional option to pass to 'git clone' + (e.g. '-o=--depth=1'); may be given more than once; + cannot be combined with -l''') parser.add_argument('--mr', '--manifest-rev', dest='manifest_rev', help='''manifest repository branch or tag name to check out first; cannot be combined with -l''') @@ -225,8 +229,8 @@ def do_run(self, args, _): self.die_already(self.topdir, msg) - if args.local and (args.manifest_url or args.manifest_rev): - self.die('-l cannot be combined with -m or --mr') + if args.local and (args.manifest_url or args.manifest_rev or args.clone_opt): + self.die('-l cannot be combined with -m, -o or --mr') self.die_if_no_git() @@ -302,7 +306,7 @@ def bootstrap(self, args) -> Path: f'Cloning manifest repository from {manifest_url}' + (f', rev. {args.manifest_rev}' if args.manifest_rev else '')) - self.check_call(['git', 'clone'] + branch_opt + + self.check_call(['git', 'clone'] + branch_opt + args.clone_opt + [manifest_url, os.fspath(tempdir)]) except subprocess.CalledProcessError: shutil.rmtree(tempdir, ignore_errors=True)