Skip to content

Commit c4aa838

Browse files
authored
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.
1 parent 20cb4ec commit c4aa838

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/utils/git/code-format-helper.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ def format_run(self, changed_files: List[str], args: FormatArgs) -> Optional[str
318318
def hook_main():
319319
# fill out args
320320
args = FormatArgs()
321-
args.verbose = False
321+
args.verbose = os.getenv("FORMAT_HOOK_VERBOSE", False)
322322

323323
# find the changed files
324324
cmd = ["git", "diff", "--cached", "--name-only", "--diff-filter=d"]
@@ -338,6 +338,9 @@ def hook_main():
338338
print(f"Couldn't find {fmt.name}, can't check " + fmt.friendly_name.lower())
339339

340340
if len(failed_fmts) > 0:
341+
print(
342+
"Pre-commit format hook failed, rerun with FORMAT_HOOK_VERBOSE=1 environment for verbose output"
343+
)
341344
sys.exit(1)
342345

343346
sys.exit(0)

0 commit comments

Comments
 (0)