[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 <alexschulze@chromium.org>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
changes/18/6028418/2
Alex Schulze 8 months ago committed by LUCI CQ
parent b5eb54d5c1
commit f37e7f4633

@ -537,7 +537,7 @@ Returns: (str) The URL of the remote Git repository, or None.
Find and return the timestamp of the given commit.
&mdash; **def [ls\_remote](/recipes/recipe_modules/git/api.py#472)(self, url, ref, name=None, tags=True, branches=True, \*\*kwargs):**
&mdash; **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.

@ -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,

@ -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),

Loading…
Cancel
Save