Commit ae2b962c authored by Sylvain Defresne's avatar Sylvain Defresne Committed by LUCI CQ

Tentative fix for roll-dep.py failing in generate commit message

Some bots run roll-dep.py and fail while generating the commit message
with the following error:

  src/ios/third_party/material_components_ios/src: Rolling from 54fd1dac39 to 5aaf54801f
  fatal: ambiguous argument '54fd1dac3..5aaf54801': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

As "Rolling from 54fd1dac39 to 5aaf54801f" is printed, this mean that
the bot was able to resolve both HEAD and roll_to before invoking this
function, thus the corresponding hashes exists in the repository.

It is unlikely that shortening the hash to just the first nine chars
results in a collision, but there is no reason to use a short hash
when invoking git anyway, so use a separate variable to construct the
header of the commit with short hashes while invoking git with the
full hashes.

Also pass '--' after all the parameters to force git to interpret the
hash range as a range and not as a path.

This is a speculative fix.

Change-Id: Iaa2888610dcf8e20f9edc115a719791d573b83ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2031104Reviewed-by: 's avatarAaron Gable <agable@chromium.org>
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
parent ae510e8f
......@@ -99,13 +99,15 @@ def gclient(args):
def generate_commit_message(
full_dir, dependency, head, roll_to, no_log, log_limit):
"""Creates the commit message for this specific roll."""
commit_range = '%s..%s' % (head[:9], roll_to[:9])
commit_range = '%s..%s' % (head, roll_to)
commit_range_for_header = '%s..%s' % (head[:9], roll_to[:9])
upstream_url = check_output(
['git', 'config', 'remote.origin.url'], cwd=full_dir).strip()
log_url = get_log_url(upstream_url, head, roll_to)
cmd = ['git', 'log', commit_range, '--date=short', '--no-merges']
logs = check_output(
cmd + ['--format=%ad %ae %s'], # Args with '=' are automatically quoted.
# Args with '=' are automatically quoted.
cmd + ['--format=%ad %ae %s', '--'],
cwd=full_dir).rstrip()
logs = re.sub(r'(?m)^(\d\d\d\d-\d\d-\d\d [^@]+)@[^ ]+( .*)$', r'\1\2', logs)
lines = logs.splitlines()
......@@ -116,7 +118,7 @@ def generate_commit_message(
rolls = nb_commits - len(cleaned_lines)
header = 'Roll %s/ %s (%d commit%s%s)\n\n' % (
dependency,
commit_range,
commit_range_for_header,
nb_commits,
's' if nb_commits > 1 else '',
('; %s trivial rolls' % rolls) if rolls else '')
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment