Skip to content

Commit c8571ba

Browse files
authored
SWDEV-123456 - add correct line-by-line clang format script (#215)
1 parent 2ec7b7f commit c8571ba

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

.github/hooks/clang-format-check.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,21 @@ if ! command -v "$clang_bin" >/dev/null 2>&1; then
3636
fi
3737
fi
3838

39-
"$clang_bin" -style=file --dry-run -fallback-style=none -n -Werror $files
39+
clang_format_diff="${CLANG_FORMAT_DIFF:-clang-format-diff}"
40+
if ! command -v "$clang_format_diff" >/dev/null 2>&1; then
41+
if [[ -x "/c/Program Files/LLVM/share/clang/clang-format-diff.py" ]]; then
42+
clang_format_diff="/c/Program Files/LLVM/share/clang/clang-format-diff.py"
43+
fi
44+
fi
45+
46+
for file in $files; do
47+
echo "Checking lines of $file"
48+
49+
if [[ -n $RANGE ]]; then
50+
diff_output=$(git diff -U0 "$RANGE" -- "$file")
51+
else
52+
diff_output=$(git diff -U0 --cached -- "$file")
53+
fi
54+
55+
echo "$diff_output" | "$clang_format_diff" -style=file -fallback-style=none -p1
56+
done

0 commit comments

Comments
 (0)