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>
diff --git a/gclient_eval.py b/gclient_eval.py
index 297ae07..5571946 100644
--- a/gclient_eval.py
+++ b/gclient_eval.py
@@ -42,7 +42,7 @@
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 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)