[llvm] c4aa838 - Improve slightly the pre-commit git hook usage of the auto-format helper (#117326)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 22 07:58:15 PST 2024
Author: Mehdi Amini
Date: 2024-11-22T16:58:12+01:00
New Revision: c4aa83840b72b9eb94e6bc2088326fb27c43ada6
URL: https://github.com/llvm/llvm-project/commit/c4aa83840b72b9eb94e6bc2088326fb27c43ada6
DIFF: https://github.com/llvm/llvm-project/commit/c4aa83840b72b9eb94e6bc2088326fb27c43ada6.diff
LOG: Improve slightly the pre-commit git hook usage of the auto-format helper (#117326)
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.
Added:
Modified:
llvm/utils/git/code-format-helper.py
Removed:
################################################################################
diff --git a/llvm/utils/git/code-format-helper.py b/llvm/utils/git/code-format-helper.py
index 26b5ce250bb7ab..76b2a3e26be28a 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)
More information about the llvm-commits
mailing list