diff options
| author | Riku Isokoski <riksu9000@gmail.com> | 2021-07-25 16:30:27 (GMT) |
|---|---|---|
| committer | Riku Isokoski <riksu9000@gmail.com> | 2021-07-25 16:30:27 (GMT) |
| commit | 2e8bc634dcae6e304b8f94e2633644fd55b64450 (patch) | |
| tree | 7098aaa514c1f7600447235e21721319bcb33ae7 /hooks | |
| parent | 12b14176ec965f2553e4cad16e291d54704128f3 (diff) | |
| parent | 7b75ca591d31ccd8883a1a1ff83cfd271959dbaa (diff) | |
Merge branch 'develop' into fit_more_tasks
Diffstat (limited to 'hooks')
| -rw-r--r-- | hooks/README.md | 5 | ||||
| -rwxr-xr-x | hooks/pre-commit | 25 |
2 files changed, 30 insertions, 0 deletions
diff --git a/hooks/README.md b/hooks/README.md new file mode 100644 index 0000000..de8fc67 --- /dev/null +++ b/hooks/README.md @@ -0,0 +1,5 @@ +# Git hooks + +This directory contains Git hooks that simplify contributing to this repository. + +You can install them by copying the files into `.git/hooks` in the repository folder or by running `git config --local core.hooksPath hooks` diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100755 index 0000000..5e10aa1 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,25 @@ +#!/bin/bash +if clang-format --version | grep -q 'version 11\.'; then + CLANG_FORMAT_EXECUTABLE="clang-format" +else + CLANG_FORMAT_EXECUTABLE="clang-format-11" +fi + +if ! command -v $CLANG_FORMAT_EXECUTABLE &> /dev/null +then + echo $CLANG_FORMAT_EXECUTABLE does not exist, make sure to install it + exit 1 +fi + +for FILE in $(git diff --cached --name-only) +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 +done |
