From e515deb99ed520823e290f470d87336a6a360940 Mon Sep 17 00:00:00 2001 From: "Lytovchenko, Danylo" Date: Fri, 27 Jun 2025 17:47:21 +0200 Subject: [PATCH] SWDEV-123456 - add correct line-by-line clang format script (#360) [ROCm/hip-tests commit: 1f14151706011f81001c14db7f714ba109d1f4fe] --- .../.github/hooks/clang-format-check.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/projects/hip-tests/.github/hooks/clang-format-check.sh b/projects/hip-tests/.github/hooks/clang-format-check.sh index a9f4f25f79..e417133217 100644 --- a/projects/hip-tests/.github/hooks/clang-format-check.sh +++ b/projects/hip-tests/.github/hooks/clang-format-check.sh @@ -36,4 +36,21 @@ if ! command -v "$clang_bin" >/dev/null 2>&1; then fi fi -"$clang_bin" -style=file --dry-run -fallback-style=none -n -Werror $files +clang_format_diff="${CLANG_FORMAT_DIFF:-clang-format-diff}" +if ! command -v "$clang_format_diff" >/dev/null 2>&1; then + if [[ -x "/c/Program Files/LLVM/share/clang/clang-format-diff.py" ]]; then + clang_format_diff="/c/Program Files/LLVM/share/clang/clang-format-diff.py" + fi +fi + +for file in $files; do + echo "Checking lines of $file" + + if [[ -n $RANGE ]]; then + diff_output=$(git diff -U0 "$RANGE" -- "$file") + else + diff_output=$(git diff -U0 --cached -- "$file") + fi + + echo "$diff_output" | "$clang_format_diff" -style=file -fallback-style=none -p1 +done