Use more robust pre-commit hook.
parent
963283b74e
commit
55e1b42a73
|
@ -1,13 +1,21 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
filesToFormat=$(
|
||||
git --no-pager diff --name-status --no-color --cached | \
|
||||
awk '$1 != "D" && $2 ~ /\.c$|\.h$/ {print $NF}'
|
||||
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"
|
||||
)
|
||||
|
||||
for path in $filesToFormat
|
||||
TARGETS=()
|
||||
while IFS= read -r FILENAME
|
||||
do
|
||||
clang-format -i "$path"
|
||||
git add "$path"
|
||||
done;
|
||||
if [[ "$FILENAME" =~ .*\.c ]] || [[ "$FILENAME" == .*\.h ]]; then
|
||||
TARGETS+=("${FILENAME}")
|
||||
fi
|
||||
done <<< "$STAGED"
|
||||
|
||||
if (( ${#TARGETS[@]} )); then
|
||||
clang-format -i "${TARGETS[@]}"
|
||||
git add "${TARGETS[@]}"
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue