Skip to content

Commit

Permalink
Added a pre-commit hook that should simplify commiting pre-formatted …
Browse files Browse the repository at this point in the history
…code
  • Loading branch information
Avamander authored and JF002 committed Jul 24, 2021
1 parent bb26c68 commit a1a6eae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions hooks/README.md
Original file line number Diff line number Diff line change
@@ -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`
13 changes: 13 additions & 0 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit a1a6eae

Please sign in to comment.