2022-09-15 11:56:49 -03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
shopt -s nullglob
|
|
|
|
declare -a FILES
|
|
|
|
declare -a HIT
|
|
|
|
echo "Git hook executing: pre-commit..."
|
2022-09-15 12:00:35 -03:00
|
|
|
FILES=($(git diff --cached --name-only --diff-filter=ACM))
|
2022-09-15 11:56:49 -03:00
|
|
|
n=0
|
|
|
|
for i in "${FILES[@]}"; do
|
2022-09-15 12:00:35 -03:00
|
|
|
WARN=$(file --mime "${i}" | grep -i binary)
|
|
|
|
NAME=$(file "${i}" | cut -d":" -f1)
|
2022-09-15 11:56:49 -03:00
|
|
|
if [ -n "${WARN}" ]; then
|
|
|
|
HIT[$n]="${NAME}"
|
|
|
|
WARN=""
|
|
|
|
echo "${NAME} appears to be a binary blob."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
let "n++"
|
|
|
|
done
|
|
|
|
if [ ${#HIT[@]} -gt 0 ]; then
|
2022-09-15 12:00:35 -03:00
|
|
|
echo "WARNING: Binary data found"
|
2022-09-15 11:56:49 -03:00
|
|
|
fi
|