Merge "clang-format: handle exit(1) from git-clang-format"
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 @@
     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