[clang] 68d618f - [clang-format] Add ability for clang-format-diff to exit with non-0 status (#70883)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 8 18:13:07 PST 2023


Author: Conrad Donahue
Date: 2023-11-08T18:13:03-08:00
New Revision: 68d618f908458e7513e2a56be292216ea0e4ef3f

URL: https://github.com/llvm/llvm-project/commit/68d618f908458e7513e2a56be292216ea0e4ef3f
DIFF: https://github.com/llvm/llvm-project/commit/68d618f908458e7513e2a56be292216ea0e4ef3f.diff

LOG: [clang-format] Add ability for clang-format-diff to exit with non-0 status (#70883)

This patch adds the ability for the clang-format-diff script to exit
with a non-zero status if it detects that formatting changes are
necessary. This makes it easier to use clang-format-diff as part of a
DevOps pipeline, since you could add a stage to run clang-format-diff
and fail if the formatting needs to be fixed.

Added: 
    

Modified: 
    clang/tools/clang-format/clang-format-diff.py

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-format/clang-format-
diff .py b/clang/tools/clang-format/clang-format-
diff .py
index 324ef5b7f6b35f6..892c1e38a462ff4 100755
--- a/clang/tools/clang-format/clang-format-
diff .py
+++ b/clang/tools/clang-format/clang-format-
diff .py
@@ -185,6 +185,7 @@ def main():
             
diff _string = "".join(
diff )
             if len(
diff _string) > 0:
                 sys.stdout.write(
diff _string)
+                sys.exit(1)
 
 
 if __name__ == "__main__":


        


More information about the cfe-commits mailing list