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