Skip to content

Commit

Permalink
feat: adds pre-commit hook for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tillt committed Jan 8, 2024
1 parent df32ec5 commit 669025e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

STYLE=$(git config --get hooks.clangformat.style)
if [ -n "${STYLE}" ] ; then
STYLEARG="-style=${STYLE}"
else
STYLEARG=""
fi

format_file() {
file="${1}"
if [ -f $file ]; then
clang-format -i ${STYLEARG} ${1}
git add ${1}
fi
}

case "${1}" in
--about )
echo "Runs clang-format on source files"
;;
* )
for file in `git diff-index --cached --name-only HEAD | grep -iE '\.(cpp|cc|m|mm|h|hpp)$' ` ; do
format_file "${file}"
done
;;
esac

0 comments on commit 669025e

Please sign in to comment.