From a1a6eae43f5995e21ff3d535094a6350e1031804 Mon Sep 17 00:00:00 2001 From: Avamander Date: Sun, 18 Apr 2021 19:20:16 +0300 Subject: [PATCH] Added a pre-commit hook that should simplify commiting pre-formatted code --- hooks/README.md | 5 +++++ hooks/pre-commit | 13 +++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 hooks/README.md create mode 100755 hooks/pre-commit diff --git a/hooks/README.md b/hooks/README.md new file mode 100644 index 00000000..de8fc67b --- /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 00000000..2e918a17 --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,13 @@ +#!/bin/bash +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 + clang-format-11 -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 + clang-format-11 -style=file -i -- $FILE + git add -- $FILE + fi +done