[clang] f9a2f6b - [clang-format] Fix the return code of git-clang-format
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 27 21:01:31 PDT 2022
Author: Sridhar Gopinath
Date: 2022-07-27T21:01:24-07:00
New Revision: f9a2f6b6aecf0dd2b484d99458c99f799caee584
URL: https://github.com/llvm/llvm-project/commit/f9a2f6b6aecf0dd2b484d99458c99f799caee584
DIFF: https://github.com/llvm/llvm-project/commit/f9a2f6b6aecf0dd2b484d99458c99f799caee584.diff
LOG: [clang-format] Fix the return code of git-clang-format
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 git-clang-format.
Fixes #56736.
Differential Revision: https://reviews.llvm.org/D129311
Added:
Modified:
clang/tools/clang-format/git-clang-format
Removed:
################################################################################
diff --git a/clang/tools/clang-format/git-clang-format b/clang/tools/clang-format/git-clang-format
index 96f415e8e561a..6a1172e0bf17b 100755
--- a/clang/tools/clang-format/git-clang-format
+++ b/clang/tools/clang-format/git-clang-format
@@ -198,16 +198,16 @@ def main():
return 0
if opts.
diff :
- print_
diff (old_tree, new_tree)
- elif opts.
diff stat:
- print_
diff stat(old_tree, new_tree)
- else:
- changed_files = apply_changes(old_tree, new_tree, force=opts.force,
- patch_mode=opts.patch)
- if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
- print('changed files:')
- for filename in changed_files:
- print(' %s' % filename)
+ return print_
diff (old_tree, new_tree)
+ if opts.
diff stat:
+ return print_
diff stat(old_tree, new_tree)
+
+ changed_files = apply_changes(old_tree, new_tree, force=opts.force,
+ patch_mode=opts.patch)
+ if (opts.verbose >= 0 and not opts.patch) or opts.verbose >= 1:
+ print('changed files:')
+ for filename in changed_files:
+ print(' %s' % filename)
return 1
@@ -536,8 +536,8 @@ def print_
diff (old_tree, new_tree):
# 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,
- '--'])
+ return subprocess.run(['git', '
diff ', '--
diff -filter=M',
+ '--exit-code', old_tree, new_tree]).returncode
def print_
diff stat(old_tree, new_tree):
"""Print the
diff stat between the two trees to stdout."""
@@ -548,8 +548,8 @@ def print_
diff stat(old_tree, new_tree):
# 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,
- '--'])
+ return subprocess.run(['git', '
diff ', '--
diff -filter=M', '--exit-code',
+ '--stat', old_tree, new_tree]).returncode
def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
"""Apply the changes in `new_tree` to the working directory.
@@ -575,7 +575,7 @@ def apply_changes(old_tree, new_tree, force=False, patch_mode=False):
# better message, "Apply ... to index and worktree". This is not quite
# right, since it won't be applied to the user's index, but oh well.
with temporary_index_file(old_tree):
- subprocess.check_call(['git', 'checkout', '--patch', new_tree])
+ subprocess.run(['git', 'checkout', '--patch', new_tree], check=True)
index_tree = old_tree
else:
with temporary_index_file(new_tree):
More information about the cfe-commits
mailing list