From 7cfe2b90d5077b58d6d4e7abeb030e44afa89c4d Mon Sep 17 00:00:00 2001 From: Finlay Davidson Date: Tue, 3 Jan 2023 16:25:55 +0000 Subject: [PATCH] Update pre-commit hook --- hooks/pre-commit | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 5e10aa19a1..7c6067626e 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -1,25 +1,8 @@ -#!/bin/bash -if clang-format --version | grep -q 'version 11\.'; then - CLANG_FORMAT_EXECUTABLE="clang-format" -else - CLANG_FORMAT_EXECUTABLE="clang-format-11" -fi +#!/bin/sh -if ! command -v $CLANG_FORMAT_EXECUTABLE &> /dev/null -then - echo $CLANG_FORMAT_EXECUTABLE does not exist, make sure to install it - exit 1 -fi +git clang-format --extensions cpp,h --style file --staged -- ':!src/FreeRTOS' ':!src/libs' -for FILE in $(git diff --cached --name-only) +git diff --name-only --diff-filter=ACMR | while read -r file do - if [[ "$FILE" =~ src/[A-Za-z0-9\ \-]+*\.(c|h|cpp|cc)$ ]]; then - echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE - $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE - git add -- $FILE - elif [[ "$FILE" =~ src/(components|displayapp|drivers|heartratetask|logging|systemtask)/.*\.(c|h|cpp|cc)$ ]]; then - echo Autoformatting $FILE with $CLANG_FORMAT_EXECUTABLE - $CLANG_FORMAT_EXECUTABLE -style=file -i -- $FILE - git add -- $FILE - fi + git add -- "$file" done