30 lines
555 B
Bash
Executable File
30 lines
555 B
Bash
Executable File
#!/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
|
|
if [ "${file##*.}" = "cpp" ] || [ "${file##*.}" = "h" ] || [ "${file##*.}" = "hpp" ]; then
|
|
clang-format -i ${STYLEARG} ${1}
|
|
git add ${1}
|
|
fi
|
|
fi
|
|
}
|
|
|
|
case "${1}" in
|
|
--about )
|
|
echo "Runs clang-format on source files"
|
|
;;
|
|
* )
|
|
for file in `git diff-index --cached --name-only HEAD` ; do
|
|
format_file "${file}"
|
|
done
|
|
;;
|
|
esac
|