Skip to content

[clang-format] Exit clang-format-diff only after all diffs are printed #86776

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions clang/tools/clang-format/clang-format-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def main():
)

# Reformat files containing changes in place.
has_diff = False
for filename, lines in lines_by_file.items():
if args.i and args.verbose:
print("Formatting {}".format(filename))
Expand Down Expand Up @@ -169,7 +170,7 @@ def main():

stdout, stderr = p.communicate()
if p.returncode != 0:
sys.exit(p.returncode)
return p.returncode

if not args.i:
with open(filename) as f:
Expand All @@ -185,9 +186,12 @@ def main():
)
diff_string = "".join(diff)
if len(diff_string) > 0:
has_diff = True
sys.stdout.write(diff_string)
sys.exit(1)

if has_diff:
return 1


if __name__ == "__main__":
main()
sys.exit(main())