From f37e7f4633de10e7247404bbb164024852debd70 Mon Sep 17 00:00:00 2001 From: Alex Schulze Date: Mon, 18 Nov 2024 16:24:28 +0000 Subject: [PATCH] [git] Remove tags / branches filter from ls-remote The flag to filter for branches was renamed in git 2.46.0 [1] from `-h` to `-b`. This causes previous versions of git to fail when running ls-remote. To be compatible across a version upgrade, a second git call would be required to retrieve the version and determine the correct flag. However, the filter feature is not used yet and can also be solved by specifying the absolute ref path within the recipe. Therefore, this change removes ls-remote's filter flags. [1] https://git-scm.com/docs/git-ls-remote/2.42.0 R=machenbach@chromium.org, gavinmak@google.com Bug: none Change-Id: I840fb3ac56daf47c798d5c32f00de841b8db2771 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/6028418 Auto-Submit: Alexander Schulze Reviewed-by: Gavin Mak Commit-Queue: Gavin Mak --- recipes/README.recipes.md | 4 +--- recipes/recipe_modules/git/api.py | 12 ++-------- recipes/recipe_modules/git/tests/ls_remote.py | 24 ++++--------------- 3 files changed, 7 insertions(+), 33 deletions(-) diff --git a/recipes/README.recipes.md b/recipes/README.recipes.md index 24d0cdf10b..6fd17a24b0 100644 --- a/recipes/README.recipes.md +++ b/recipes/README.recipes.md @@ -537,7 +537,7 @@ Returns: (str) The URL of the remote Git repository, or None. Find and return the timestamp of the given commit. -— **def [ls\_remote](/recipes/recipe_modules/git/api.py#472)(self, url, ref, name=None, tags=True, branches=True, \*\*kwargs):** +— **def [ls\_remote](/recipes/recipe_modules/git/api.py#472)(self, url, ref, name=None, \*\*kwargs):** Request the head revision for a given ref using ls-remote. Raise a StepFailure if the ref does not exist, or more than one ref was found. @@ -546,8 +546,6 @@ Args: * url (str): url of remote repo to use as upstream. * ref (str): ref to query head revision. * name (str): Name of the infra step. - * tags (bool): Include tags. - * branches (bool): Include branches. Returns: A git revision. diff --git a/recipes/recipe_modules/git/api.py b/recipes/recipe_modules/git/api.py index aeb458eb66..1d4ea0f3c0 100644 --- a/recipes/recipe_modules/git/api.py +++ b/recipes/recipe_modules/git/api.py @@ -469,7 +469,7 @@ class GitApi(recipe_api.RecipeApi): step_test_data=step_test_data) return [l.strip() for l in step_result.stdout.strip().splitlines()] - def ls_remote(self, url, ref, name=None, tags=True, branches=True, **kwargs): + def ls_remote(self, url, ref, name=None, **kwargs): """Request the head revision for a given ref using ls-remote. Raise a StepFailure if the ref does not exist, or more than one ref was found. @@ -477,20 +477,12 @@ class GitApi(recipe_api.RecipeApi): * url (str): url of remote repo to use as upstream. * ref (str): ref to query head revision. * name (str): Name of the infra step. - * tags (bool): Include tags. - * branches (bool): Include branches. Returns: A git revision. """ cwd = self.m.context.cwd or self.m.path.start_dir name = name or f'Retrieve revision for {ref}' - - cmd = ['ls-remote'] - if tags: - cmd.append('-t') - if branches: - cmd.append('-b') - cmd.extend([url, ref]) + cmd = ['ls-remote', url, ref] with self.m.context(cwd): result = self(*cmd, diff --git a/recipes/recipe_modules/git/tests/ls_remote.py b/recipes/recipe_modules/git/tests/ls_remote.py index af6432b165..c26502979f 100644 --- a/recipes/recipe_modules/git/tests/ls_remote.py +++ b/recipes/recipe_modules/git/tests/ls_remote.py @@ -18,10 +18,8 @@ REPO_URL = 'https://chromium.googlesource.com/v8/v8' def RunSteps(api): url = api.properties.get('url', REPO_URL) ref = api.properties.get('ref', 'main') - tags = api.properties.get('tags', True) - branches = api.properties.get('branches', True) - result = api.git.ls_remote(url, ref, tags=tags, branches=branches) + result = api.git.ls_remote(url, ref) api.step.empty('revision', step_text=result) @@ -56,7 +54,7 @@ def GenTests(api): yield test( 'basic', - ['git', 'ls-remote', '-t', '-b', REPO_URL, 'main'], + ['git', 'ls-remote', REPO_URL, 'main'], mock_ls_remote('main', [('badc0ffee0ded', 'refs/heads/main')]), api.post_process( post.StepTextEquals, @@ -65,23 +63,9 @@ def GenTests(api): ), ) - yield test( - 'no-tags', - ['git', 'ls-remote', '-b', REPO_URL, 'main'], - api.properties(tags=False), - mock_ls_remote('main', [('badc0ffee0ded', 'refs/heads/main')]), - ) - - yield test( - 'no-branches', - ['git', 'ls-remote', '-t', REPO_URL, 'main'], - api.properties(branches=False), - mock_ls_remote('main', [('badc0ffee0ded', 'refs/heads/main')]), - ) - yield test( 'multiple-refs', - ['git', 'ls-remote', '-t', '-b', REPO_URL, '13.3.19'], + ['git', 'ls-remote', REPO_URL, '13.3.19'], api.properties(ref='13.3.19'), mock_ls_remote('13.3.19', [ ('badc0ffee0ded', 'refs/heads/13.3.19'), @@ -95,7 +79,7 @@ def GenTests(api): yield test( 'no-refs', - ['git', 'ls-remote', '-t', '-b', REPO_URL, '13.3'], + ['git', 'ls-remote', REPO_URL, '13.3'], api.properties(ref='13.3'), mock_ls_remote('13.3', []), api.post_process(post.StatusFailure),