From 45bfed3b4233a7190f295b7efb2073bd0eb17440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=B6eh=20Matt?= <3397065-ZehMatt@users.noreply.gitlab.com> Date: Thu, 22 Sep 2022 21:45:47 +0300 Subject: [PATCH] Use clang-format --dry-run instead of relying on git diff --- CI/check_clang_format.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/CI/check_clang_format.sh b/CI/check_clang_format.sh index 9ae45d48af..a4aafb3837 100755 --- a/CI/check_clang_format.sh +++ b/CI/check_clang_format.sh @@ -5,19 +5,23 @@ HAS_DIFFS=0 check_format() { local path=$1 - local tempfile=$(mktemp) for item in $(find $path -type f -name "*"); do if [[ "$item" =~ .*\.(cpp|hpp|h) ]]; then echo "Checking code formatting on $item" - $CLANG_FORMAT $item > $tempfile - git diff --color=always --no-index $item $tempfile + $CLANG_FORMAT --dry-run -Werror "$item" if [[ $? = 1 ]]; then + local tempfile=$(mktemp) + # Avoid having different modes in the diff. + chmod --reference="$item" "$tempfile" + # Generate diff + $CLANG_FORMAT "$item" > "$tempfile" + git diff --color=always --no-index $item $tempfile + rm -f "$tempfile" HAS_DIFFS=1 fi fi; done; - rm -f $tempfile } check_format "./apps"