bootstrap/.githooks/pre-commit

22 lines
496 B
Plaintext
Raw Normal View History

2023-11-23 15:21:50 +00:00
#!/usr/bin/env bash
set -e
2023-12-03 21:32:16 +00:00
STAGED=$(
git --no-pager diff --name-only --no-color --cached --diff-filter=d |
# Remove quotations used to surrounding filenames with special characters.
sed -e "s/^\"//" -e "s/\"$//g"
2023-11-23 15:21:50 +00:00
)
2023-12-03 21:32:16 +00:00
TARGETS=()
while IFS= read -r FILENAME
2023-11-23 15:21:50 +00:00
do
2023-12-19 23:58:19 +00:00
if [[ "$FILENAME" =~ .*\.c(pp)?$ ]] || [[ "$FILENAME" =~ .*\.h(pp)?$ ]]; then
2023-12-03 21:32:16 +00:00
TARGETS+=("${FILENAME}")
fi
done <<< "$STAGED"
if (( ${#TARGETS[@]} )); then
clang-format -i "${TARGETS[@]}"
git add "${TARGETS[@]}"
fi