Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify git clone options like --depth for Zephyr repo clone via init #744

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/west/app/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
''')

Expand All @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, I tested this PR and compared:

1. west init -o=--depth=1
2. west init -o=--filter=tree:0

The latter took 30% longer and 10% more disk but has a complete git log and does not break git describe. We've been using it in CI for a couple years now and it's a much better choice there.

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''')
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -1647,6 +1647,25 @@ def test_init_local_with_empty_path(repos_tmpdir):
assert (repos_tmpdir / 'workspace' / 'subdir' / 'Kconfiglib').check(dir=1)


def test_init_local_with_clone_option_failure(repos_tmpdir):
# Test that 'west init -l -o' errors out

west_tmpdir = repos_tmpdir / 'workspace'

with pytest.raises(subprocess.CalledProcessError):
cmd(['init', '-l', '-o=--depth=1', west_tmpdir])


def test_init_with_clone_option_depth_one(repos_tmpdir):
# Test that 'west init -o=--depth=1' only clones depth 1

west_tmpdir = repos_tmpdir / 'workspace'

cmd(['init', '-o=--depth=1', west_tmpdir])
assert 1 == int(subprocess.check_output([GIT, 'rev-list', '--count', '--max-count=5', 'HEAD'],
cwd=west_tmpdir / 'zephyr').decode().strip())


def test_update_with_groups_enabled(west_init_tmpdir):
# Test "west update" with increasing numbers of groups enabled.

Expand Down
Loading