Skip to content

Commit 00a28af

Browse files
authored
[clang-format] Exit clang-format-diff only after all diffs are printed (#86776)
See llvm/llvm-project#70883 (comment).
1 parent 1567784 commit 00a28af

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

clang-format-diff.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ def main():
138138
)
139139

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

170171
stdout, stderr = p.communicate()
171172
if p.returncode != 0:
172-
sys.exit(p.returncode)
173+
return p.returncode
173174

174175
if not args.i:
175176
with open(filename) as f:
@@ -185,9 +186,12 @@ def main():
185186
)
186187
diff_string = "".join(diff)
187188
if len(diff_string) > 0:
189+
has_diff = True
188190
sys.stdout.write(diff_string)
189-
sys.exit(1)
191+
192+
if has_diff:
193+
return 1
190194

191195

192196
if __name__ == "__main__":
193-
main()
197+
sys.exit(main())

0 commit comments

Comments
 (0)