34 lines
711 B
Bash
34 lines
711 B
Bash
#!/usr/bin/env bash
|
|
|
|
shopt -s nullglob
|
|
declare -a FILES
|
|
declare -a HIT
|
|
|
|
echo "Git hook executing: pre-commit..."
|
|
|
|
# dump staged filenames into FILES array
|
|
FILES=(`git diff --cached --name-only --diff-filter=ACM`)
|
|
|
|
n=0
|
|
for i in "${FILES[@]}"; do
|
|
WARN=`file --mime "${i}" | grep -i binary`
|
|
NAME=`file "${i}" | cut -d":" -f1`
|
|
|
|
if [ -n "${WARN}" ]; then
|
|
HIT[$n]="${NAME}"
|
|
WARN=""
|
|
echo "${NAME} appears to be a binary blob."
|
|
exit 1
|
|
elif [[ "${NAME}" == *"blah" ]]; then
|
|
true
|
|
# do some stuff here
|
|
else
|
|
true
|
|
# do some other stuff here
|
|
fi
|
|
let "n++"
|
|
done
|
|
|
|
if [ ${#HIT[@]} -gt 0 ]; then
|
|
echo " WARNING: Binary data found"
|
|
fi |