Surface yapf format errors when written to stderr
When CheckPatchFormatted presubmited canned check is executed, it runs
git cl format with --dry-run. When dry-run is used, exit codes are
ignored and we rely on only on stdout message to detect if formatting is
needed or not. This itself is wrong, but changing this will likely
require significant redesign.
This patch appends stderr output to stdout message on non-zero exit code
and therefore allowing git cl format to actually exit with code 2.
R=gavinmak@google.com
Fixed: 1264111
Change-Id: I5eccf34f533640fd93209c97d1c8d9c85bb94d83
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3249191
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
diff --git a/git_cl.py b/git_cl.py
index 268ff77..8ba9e31 100755
--- a/git_cl.py
+++ b/git_cl.py
@@ -185,7 +185,10 @@
if not error_ok:
message = error_message or e.stdout.decode('utf-8', 'replace') or ''
DieWithError('Command "%s" failed.\n%s' % (' '.join(args), message))
- return e.stdout.decode('utf-8', 'replace')
+ out = e.stdout.decode('utf-8', 'replace')
+ if e.stderr:
+ out += e.stderr.decode('utf-8', 'replace')
+ return out
def RunGit(args, **kwargs):
@@ -5282,6 +5285,7 @@
# Will return non-zero exit code if non-empty diff.
stdout = RunCommand(cmd,
error_ok=True,
+ stderr=subprocess2.PIPE,
cwd=top_dir,
shell=sys.platform.startswith('win32'))
if opts.diff: