sridhar_gopinath created this revision. sridhar_gopinath added reviewers: curdeius, owenpan. Herald added a project: All. sridhar_gopinath requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
In diff and diffstat modes, the return code is != 0 even when there are no changes between commits. This issue can be fixed by passing `--exit-code` to `git diff` command that returns 0 when there are no changes and using that as the return code for clang-format. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D129311 Files: clang/tools/clang-format/git-clang-format Index: clang/tools/clang-format/git-clang-format =================================================================== --- clang/tools/clang-format/git-clang-format +++ clang/tools/clang-format/git-clang-format @@ -198,9 +198,9 @@ return 0 if opts.diff: - print_diff(old_tree, new_tree) + return print_diff(old_tree, new_tree) elif opts.diffstat: - print_diffstat(old_tree, new_tree) + return print_diffstat(old_tree, new_tree) else: changed_files = apply_changes(old_tree, new_tree, force=opts.force, patch_mode=opts.patch) @@ -209,7 +209,7 @@ for filename in changed_files: print(' %s' % filename) - return 1 + return 1 def load_git_config(non_string_options=None): @@ -536,8 +536,8 @@ # We also only print modified files since `new_tree` only contains the files # that were modified, so unmodified files would show as deleted without the # filter. - subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree, - '--']) + subprocess.check_call(['git', 'diff', '--diff-filter=M', + old_tree, new_tree, '--exit-code', '--']) def print_diffstat(old_tree, new_tree): """Print the diffstat between the two trees to stdout.""" @@ -548,7 +548,13 @@ # We also only print modified files since `new_tree` only contains the files # that were modified, so unmodified files would show as deleted without the # filter. - subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, new_tree, + subprocess.check_call(['git', + 'diff', + '--diff-filter=M', + '--stat', + old_tree, + new_tree, + '--exit-code', '--']) def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
Index: clang/tools/clang-format/git-clang-format =================================================================== --- clang/tools/clang-format/git-clang-format +++ clang/tools/clang-format/git-clang-format @@ -198,9 +198,9 @@ return 0 if opts.diff: - print_diff(old_tree, new_tree) + return print_diff(old_tree, new_tree) elif opts.diffstat: - print_diffstat(old_tree, new_tree) + return print_diffstat(old_tree, new_tree) else: changed_files = apply_changes(old_tree, new_tree, force=opts.force, patch_mode=opts.patch) @@ -209,7 +209,7 @@ for filename in changed_files: print(' %s' % filename) - return 1 + return 1 def load_git_config(non_string_options=None): @@ -536,8 +536,8 @@ # We also only print modified files since `new_tree` only contains the files # that were modified, so unmodified files would show as deleted without the # filter. - subprocess.check_call(['git', 'diff', '--diff-filter=M', old_tree, new_tree, - '--']) + subprocess.check_call(['git', 'diff', '--diff-filter=M', + old_tree, new_tree, '--exit-code', '--']) def print_diffstat(old_tree, new_tree): """Print the diffstat between the two trees to stdout.""" @@ -548,7 +548,13 @@ # We also only print modified files since `new_tree` only contains the files # that were modified, so unmodified files would show as deleted without the # filter. - subprocess.check_call(['git', 'diff', '--diff-filter=M', '--stat', old_tree, new_tree, + subprocess.check_call(['git', + 'diff', + '--diff-filter=M', + '--stat', + old_tree, + new_tree, + '--exit-code', '--']) def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits