From 740825ecf2e918c7935d52e5215b04a50aa0b3a0 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Wed, 12 May 2021 18:28:34 +0000 Subject: [PATCH] Detect uploadvalidator error message If git push refs/for/ errors out, inspect stdout message to detect uploadvalidator rejection. If present, present user a solution. R=ajp@google.com Change-Id: I70aee7615f3d905127a31bd5679968ade75c234a Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2888475 Reviewed-by: Andy Perelson Commit-Queue: Josip Sokcevic --- gclient_utils.py | 11 ++++++----- git_cl.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/gclient_utils.py b/gclient_utils.py index 65223a73ae..fb6770870a 100644 --- a/gclient_utils.py +++ b/gclient_utils.py @@ -585,6 +585,10 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None, sleep_interval = RETRY_INITIAL_SLEEP run_cwd = kwargs.get('cwd', os.getcwd()) + + # Store the output of the command regardless of the value of print_stdout or + # filter_fn. + command_output = io.BytesIO() for attempt in range(RETRY_MAX + 1): # If our stdout is a terminal, then pass in a psuedo-tty pipe to our # subprocess when filtering its output. This makes the subproc believe @@ -603,10 +607,6 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None, GClientChildren.add(kid) - # Store the output of the command regardless of the value of print_stdout or - # filter_fn. - command_output = io.BytesIO() - # Passed as a list for "by ref" semantics. needs_header = [show_header] if always_show_header: @@ -667,11 +667,12 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None, print("WARNING: subprocess '%s' in %s failed; will retry after a short " 'nap...' % (' '.join('"%s"' % x for x in args), run_cwd)) + command_output = io.BytesIO() time.sleep(sleep_interval) sleep_interval *= 2 raise subprocess2.CalledProcessError( - rv, args, kwargs.get('cwd', None), None, None) + rv, args, kwargs.get('cwd', None), command_output.getvalue(), None) class GitFilter(object): diff --git a/git_cl.py b/git_cl.py index 55ff1e09b7..0ae2cd37c2 100755 --- a/git_cl.py +++ b/git_cl.py @@ -2232,6 +2232,17 @@ class Changelist(object): push_stdout = push_stdout.decode('utf-8', 'replace') except subprocess2.CalledProcessError as e: push_returncode = e.returncode + if 'blocked keyword' in str(e.stdout): + raise GitPushError( + 'Failed to create a change, very likely due to blocked keyword. ' + 'Please examine output above for the reason of the failure.\n' + 'If this is a false positive, you can try to bypass blocked ' + 'keyword by using push option ' + '-o uploadvalidator~skip, e.g.:\n' + 'git cl upload -o uploadvalidator~skip\n\n' + 'If git-cl is not working correctly, file a bug under the ' + 'Infra>SDK component.') + raise GitPushError( 'Failed to create a change. Please examine output above for the ' 'reason of the failure.\n'