From 34b33ff6cb7ea4d7ff9527025e3543f0e21a1ee6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=AD=20Bol=C3=ADvar?= Date: Wed, 7 Apr 2021 12:45:49 -0700 Subject: [PATCH] update: add update.narrow configuration option MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If true, 'west update' is always '--narrow'. Signed-off-by: Martí Bolívar --- src/west/app/project.py | 9 +++++++-- tests/test_project.py | 22 ++++++++++++++++------ 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/west/app/project.py b/src/west/app/project.py index 289e924..a1d28e9 100644 --- a/src/west/app/project.py +++ b/src/west/app/project.py @@ -804,6 +804,11 @@ class Update(_ProjectCommand): 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): item = group_filter_item.strip() if not item.startswith(('-', '+')): @@ -1201,7 +1206,7 @@ class Update(_ProjectCommand): # non-commit object" error when the revision is an annotated # tag. ^{commit} type peeling isn't supported for the in a # : 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 # forbid it for security reasons. Let's hope it's reachable # from some branch. @@ -1222,7 +1227,7 @@ class Update(_ProjectCommand): log.small_banner(f'{project.name}: fetching, need revision {rev}') # --tags is required to get tags if we're not run as 'west # 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 project.clone_depth else []) # -f is needed to avoid errors in case multiple remotes are diff --git a/tests/test_project.py b/tests/test_project.py index 7b37cd3..3160ac6 100644 --- a/tests/test_project.py +++ b/tests/test_project.py @@ -1040,17 +1040,27 @@ def setup_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) + 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( - [GIT, 'tag', '--list'], cwd=workspace / 'project' - ).decode().splitlines() + cmd('update --narrow') + assert project_tags() == [] - 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):