2023-11-26 21:51:41 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
|
|
|
2023-12-03 21:28:55 +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-26 21:51:41 +00:00
|
|
|
)
|
|
|
|
|
2023-12-03 21:28:55 +00:00
|
|
|
TARGETS=()
|
|
|
|
while IFS= read -r FILENAME
|
|
|
|
do
|
2023-12-19 12:48:06 +00:00
|
|
|
if [[ "$FILENAME" =~ .*\.c$ ]] || [[ "$FILENAME" =~ .*\.h$ ]]; then
|
2023-12-03 21:28:55 +00:00
|
|
|
TARGETS+=("${FILENAME}")
|
|
|
|
fi
|
|
|
|
done <<< "$STAGED"
|
|
|
|
|
|
|
|
if (( ${#TARGETS[@]} )); then
|
|
|
|
clang-format -i "${TARGETS[@]}"
|
|
|
|
git add "${TARGETS[@]}"
|
2023-12-03 18:32:45 +00:00
|
|
|
fi
|