22 lines
484 B
Bash
Executable File
22 lines
484 B
Bash
Executable File
#!/usr/bin/env bash
|
|
set -e
|
|
|
|
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"
|
|
)
|
|
|
|
TARGETS=()
|
|
while IFS= read -r FILENAME
|
|
do
|
|
if [[ "$FILENAME" =~ .*\.c ]] || [[ "$FILENAME" == .*\.h ]]; then
|
|
TARGETS+=("${FILENAME}")
|
|
fi
|
|
done <<< "$STAGED"
|
|
|
|
if (( ${#TARGETS[@]} )); then
|
|
clang-format -i "${TARGETS[@]}"
|
|
git add "${TARGETS[@]}"
|
|
fi
|