update: add update.narrow configuration option

If true, 'west update' is always '--narrow'.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2021-04-07 12:45:49 -07:00 committed by Marti Bolivar
parent d937dedc8b
commit 34b33ff6cb
2 changed files with 23 additions and 8 deletions

View File

@ -804,6 +804,11 @@ class Update(_ProjectCommand):
self.group_filter: List[str] = [] self.group_filter: List[str] = []
if args.narrow:
self.narrow = True
else:
self.narrow = config.getboolean('update', 'narrow', fallback=False)
def handle(group_filter_item): def handle(group_filter_item):
item = group_filter_item.strip() item = group_filter_item.strip()
if not item.startswith(('-', '+')): if not item.startswith(('-', '+')):
@ -1201,7 +1206,7 @@ class Update(_ProjectCommand):
# non-commit object" error when the revision is an annotated # non-commit object" error when the revision is an annotated
# tag. ^{commit} type peeling isn't supported for the <src> in a # tag. ^{commit} type peeling isn't supported for the <src> in a
# <src>:<dst> refspec, so we have to do it separately. # <src>:<dst> refspec, so we have to do it separately.
if _maybe_sha(rev) and not self.args.narrow: if _maybe_sha(rev) and not self.narrow:
# We can't in general fetch a SHA from a remote, as some hosts # We can't in general fetch a SHA from a remote, as some hosts
# forbid it for security reasons. Let's hope it's reachable # forbid it for security reasons. Let's hope it's reachable
# from some branch. # from some branch.
@ -1222,7 +1227,7 @@ class Update(_ProjectCommand):
log.small_banner(f'{project.name}: fetching, need revision {rev}') log.small_banner(f'{project.name}: fetching, need revision {rev}')
# --tags is required to get tags if we're not run as 'west # --tags is required to get tags if we're not run as 'west
# update --narrow', since the remote is specified as a URL. # update --narrow', since the remote is specified as a URL.
tags = (['--tags'] if not self.args.narrow else []) tags = (['--tags'] if not self.narrow else [])
clone_depth = (['--depth', str(project.clone_depth)] if clone_depth = (['--depth', str(project.clone_depth)] if
project.clone_depth else []) project.clone_depth else [])
# -f is needed to avoid errors in case multiple remotes are # -f is needed to avoid errors in case multiple remotes are

View File

@ -1040,17 +1040,27 @@ def setup_narrow(tmpdir):
def test_update_narrow(tmpdir): def test_update_narrow(tmpdir):
# Test that 'west update --narrow' doesn't fetch tags. # Test that 'west update --narrow' doesn't fetch tags, and that
# 'west update' respects the 'update.narrow' config option.
remote, workspace = setup_narrow(tmpdir) remote, workspace = setup_narrow(tmpdir)
workspace.chdir()
cmd('update --narrow', cwd=workspace) def project_tags():
return subprocess.check_output(
[GIT, 'tag', '--list'], cwd=workspace / 'project'
).decode().splitlines()
tags = subprocess.check_output( cmd('update --narrow')
[GIT, 'tag', '--list'], cwd=workspace / 'project' assert project_tags() == []
).decode().splitlines()
assert tags == [] cmd('config update.narrow true')
cmd('update')
assert project_tags() == []
cmd('config update.narrow false')
cmd('update')
assert project_tags() != []
def test_update_narrow_depth1(tmpdir): def test_update_narrow_depth1(tmpdir):