From 0eb5ceaca02fa8605f64c1089b46f7d5f8bf03db Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Fri, 22 Nov 2024 15:01:32 +0100 Subject: [PATCH] Improve slightly the pre-commit git hook usage of the auto-format helper The default mode does not provide a way to see the actual failure of the formatters without modifying the code. Instead offer the user the option to rerun with a `FORMAT_HOOK_VERBOSE=1` environment variable to print the actual formatting diff. --- llvm/utils/git/code-format-helper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py index 26b5ce250bb7a..76b2a3e26be28 100755 --- a/llvm/utils/git/code-format-helper.py +++ b/llvm/utils/git/code-format-helper.py @@ -318,7 +318,7 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str def hook_main(): # fill out args args = FormatArgs() - args.verbose = False + args.verbose = os.getenv("FORMAT_HOOK_VERBOSE", False) # find the changed files cmd = ["git", "diff", "--cached", "--name-only", "--diff-filter=d"] @@ -338,6 +338,9 @@ def hook_main(): print(f"Couldn't find {fmt.name}, can't check " + fmt.friendly_name.lower()) if len(failed_fmts) > 0: + print( + "Pre-commit format hook failed, rerun with FORMAT_HOOK_VERBOSE=1 environment for verbose output" + ) sys.exit(1) sys.exit(0)