Bladeren bron

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 <ajp@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@google.com>
Josip Sokcevic 4 jaren geleden
bovenliggende
commit
740825ecf2
2 gewijzigde bestanden met toevoegingen van 17 en 5 verwijderingen
  1. 6 5
      gclient_utils.py
  2. 11 0
      git_cl.py

+ 6 - 5
gclient_utils.py

@@ -585,6 +585,10 @@ def CheckCallAndFilter(args, print_stdout=False, filter_fn=None,
 
 
   sleep_interval = RETRY_INITIAL_SLEEP
   sleep_interval = RETRY_INITIAL_SLEEP
   run_cwd = kwargs.get('cwd', os.getcwd())
   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):
   for attempt in range(RETRY_MAX + 1):
     # If our stdout is a terminal, then pass in a psuedo-tty pipe to our
     # 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
     # 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)
     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.
     # Passed as a list for "by ref" semantics.
     needs_header = [show_header]
     needs_header = [show_header]
     if always_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 "
     print("WARNING: subprocess '%s' in %s failed; will retry after a short "
           'nap...' % (' '.join('"%s"' % x for x in args), run_cwd))
           'nap...' % (' '.join('"%s"' % x for x in args), run_cwd))
+    command_output = io.BytesIO()
     time.sleep(sleep_interval)
     time.sleep(sleep_interval)
     sleep_interval *= 2
     sleep_interval *= 2
 
 
   raise subprocess2.CalledProcessError(
   raise subprocess2.CalledProcessError(
-      rv, args, kwargs.get('cwd', None), None, None)
+      rv, args, kwargs.get('cwd', None), command_output.getvalue(), None)
 
 
 
 
 class GitFilter(object):
 class GitFilter(object):

+ 11 - 0
git_cl.py

@@ -2232,6 +2232,17 @@ class Changelist(object):
       push_stdout = push_stdout.decode('utf-8', 'replace')
       push_stdout = push_stdout.decode('utf-8', 'replace')
     except subprocess2.CalledProcessError as e:
     except subprocess2.CalledProcessError as e:
       push_returncode = e.returncode
       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(
       raise GitPushError(
           'Failed to create a change. Please examine output above for the '
           'Failed to create a change. Please examine output above for the '
           'reason of the failure.\n'
           'reason of the failure.\n'