From 03af44a5163e9448e375a6bbe7bef1fc0e2bb205 Mon Sep 17 00:00:00 2001 From: Bruce Dawson Date: Tue, 27 Dec 2022 19:37:58 +0000 Subject: [PATCH] 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 Commit-Queue: Bruce Dawson --- gclient_eval.py | 11 ++++++++++- roll_dep.py | 10 +++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gclient_eval.py b/gclient_eval.py index 297ae07d4..5571946c4 100644 --- a/gclient_eval.py +++ b/gclient_eval.py @@ -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) diff --git a/roll_dep.py b/roll_dep.py index 3defd7048..a83497f33 100755 --- a/roll_dep.py +++ b/roll_dep.py @@ -17,6 +17,7 @@ import os import re import subprocess2 import sys +import tempfile NEED_SHELL = sys.platform.startswith('win') GCLIENT_PATH = os.path.join( @@ -187,7 +188,14 @@ def finalize(commit_msg, current_dir, rolls): print('\n'.join(' ' + i for i in commit_msg.splitlines())) check_call(['git', 'add', 'DEPS'], cwd=current_dir) - check_call(['git', 'commit', '--quiet', '-m', commit_msg], cwd=current_dir) + # We have to set delete=False and then let the object go out of scope so + # that the file can be opened by name on Windows. + with tempfile.NamedTemporaryFile('w+', newline='', delete=False) as f: + commit_filename = f.name + f.write(commit_msg) + check_call(['git', 'commit', '--quiet', '--file', commit_filename], + cwd=current_dir) + os.remove(commit_filename) # Pull the dependency to the right revision. This is surprising to users # otherwise.