Skip to content

Commit

Permalink
[clang-format] Add return code to git-clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca committed Jan 16, 2022
1 parent 6273920 commit edbb8a8
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions clang/tools/clang-format/git-clang-format
Expand Up @@ -161,10 +161,12 @@ def main():
print('Running clang-format on the following files:')
for filename in changed_lines:
print(' %s' % filename)

if not changed_lines:
if opts.verbose >= 0:
print('no modified files to format')
return
return 0

if len(commits) > 1:
old_tree = commits[1]
new_tree = run_clang_format_and_save_to_tree(changed_lines,
Expand All @@ -179,10 +181,13 @@ def main():
if opts.verbose >= 1:
print('old tree: %s' % old_tree)
print('new tree: %s' % new_tree)

if old_tree == new_tree:
if opts.verbose >= 0:
print('clang-format did not modify any files')
elif opts.diff:
return 0

if opts.diff:
print_diff(old_tree, new_tree)
elif opts.diffstat:
print_diffstat(old_tree, new_tree)
Expand All @@ -194,6 +199,8 @@ def main():
for filename in changed_files:
print(' %s' % filename)

return 1


def load_git_config(non_string_options=None):
"""Return the git configuration as a dictionary.
Expand Down

0 comments on commit edbb8a8

Please sign in to comment.