From 5d857d04f9fd0d53b4bdbc170a64339a2f9b8686 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lu=C3=ADs=20Fonseca?= Date: Thu, 28 Sep 2023 15:25:15 +0100 Subject: [PATCH] fix(meta): fix formatter --- .githooks/pre-commit | 10 ++++++++-- .github/workflows/clang-format-check.yml | 5 +---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.githooks/pre-commit b/.githooks/pre-commit index 98d2cee03..b432f7e5b 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -1,6 +1,12 @@ #!/bin/sh -for file in $(git diff --cached --name-only | grep -E '.*\.(c|cpp|h|hpp)$') +for file in $(git diff --cached --name-only --diff-filter=ACMR | grep -E '.*\.(c|cpp|h|hpp)$') do + PARTIAL_STAGED=$(git diff --name-only $file | wc -l) + clang-format -i $file - git add $file + + # Add unless the file was partially staged + if [ $PARTIAL_STAGED -eq 0 ]; then + git add $file + fi done diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml index ffd26c4b3..7295b8fdd 100644 --- a/.github/workflows/clang-format-check.yml +++ b/.github/workflows/clang-format-check.yml @@ -21,9 +21,6 @@ jobs: - name: Check run: | - for file in $(git diff -U0 --name-only HEAD^ | grep -E '.*\.(c|cpp|h|hpp)$'); do - if [ ! -f $file ]; then - continue - fi + for file in $(git diff -U0 --name-only --diff-filter=ACMR HEAD^ | grep -E '.*\.(c|cpp|h|hpp)$'); do clang-format --dry-run -Werror $file || exit 1 done