Fix roll-dep commit message on Windows and add suggestions

roll-dep would confidently print "Commit message:" but then on Windows
would only actually give the first line of the message to git. This is
because multi-line command-lines don't actually work on all shells. This
change passes the commit message using a temporary file so that the full
message is retained on all operating systems.

This change also teaches roll-dep to give suggestions when a specified
dependency is not quite correct. This is particularly helpful if a
leading or trailing directory name is used. For instance, this command
seems plausible:

  roll-dep third_party/openh264

But in fact it is wrong and a new user has to realize that a src prefix
is needed (in general) and in this specific case a src suffix is needed
as well. Prior to this change the error message would be:

    KeyError: 'Could not find any dependency called third_party/openh264.'

But after this message it will instead say:

    KeyError: 'Could not find any dependency called third_party/openh264. Did you mean src/third_party/openh264/src'

Past me wishes I'd done this years ago.

Change-Id: I6e0d6c703906b1c1ec947788fa259bae7b7520cf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4120534
Reviewed-by: Joanna Wang <jojwang@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
This commit is contained in:
Bruce Dawson
2022-12-27 19:37:58 +00:00
committed by LUCI CQ
parent 0b96058844
commit 03af44a516
2 changed files with 19 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ class ConstantString(object):
return self.value == other
def __hash__(self):
return self.value.__hash__()
return self.value.__hash__()
class _NodeDict(collections_abc.MutableMapping):
@@ -893,6 +893,15 @@ def GetCIPD(gclient_dict, dep_name, package_name):
def GetRevision(gclient_dict, dep_name):
if 'deps' not in gclient_dict or dep_name not in gclient_dict['deps']:
suggestions = []
if 'deps' in gclient_dict:
for key in gclient_dict['deps']:
if dep_name in key:
suggestions.append(key)
if suggestions:
raise KeyError(
"Could not find any dependency called %s. Did you mean %s" %
(dep_name, ' or '.join(suggestions)))
raise KeyError(
"Could not find any dependency called %s." % dep_name)