aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2022-05-12 22:36:20 -0400
committerMike Frysinger <vapier@google.com>2022-05-12 22:41:33 -0400
commitaa268a770ecb79af209cb4aee29cb699b1abcc94 (patch)
tree8add73d69ef0299c0780c25bd599c225004c8dbe
parent1bada39b16b6b7b404a538d6220dee39de35d0f7 (diff)
downloadrepohooks-aa268a770ecb79af209cb4aee29cb699b1abcc94.tar.gz
clang-format: handle exit(1) from git-clang-format
Newer git-clang-format exits 1 when --diff "works", so we have to check for tool output instead to determine if it worked correctly or if it crashed on us. Bug: 229737306 Test: ran hook with bad commits Change-Id: I1b7abf37f63efa6cb1d5883990474d5e3f0d71a2
-rwxr-xr-xtools/clang-format.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/tools/clang-format.py b/tools/clang-format.py
index c750d57..ebb6abe 100755
--- a/tools/clang-format.py
+++ b/tools/clang-format.py
@@ -79,10 +79,14 @@ def main(argv):
cmd.extend(['--'] + opts.files)
# Fail gracefully if clang-format itself aborts/fails.
- try:
- result = rh.utils.run(cmd, capture_output=True)
- except rh.utils.CalledProcessError as e:
- print(f'clang-format failed:\n{e}', file=sys.stderr)
+ result = rh.utils.run(cmd, capture_output=True, check=False)
+ # Newer versions of git-clang-format will exit 1 when it worked. Assume a
+ # real failure is any exit code above 1, or any time stderr is used, or if
+ # it exited 0/1 but didn't produce anything useful to stdout.
+ if result.returncode > 1 or result.stderr or not result.stdout:
+ print(f'clang-format failed:\ncmd: {result.cmdstr}\n'
+ f'stdout:\n{result.stdout}\nstderr:\n{result.stderr}',
+ file=sys.stderr)
print('\nPlease report this to the clang team.', file=sys.stderr)
return 1