Files

22 lines
551 B
Bash
Executable File

#!/usr/bin/env bash
set -u
cacheFiles=()
while IFS= read -r stagedFile; do
case "$stagedFile" in
__pycache__/* | */__pycache__/* | *.pyc | *.pyo | *.pyd)
cacheFiles+=("$stagedFile")
;;
esac
done < <(git diff --cached --name-only --diff-filter=ACMR)
if [[ ${#cacheFiles[@]} -eq 0 ]]; then
exit 0
fi
printf 'Commit blocked: remove generated Python cache files from the index:\n' >&2
printf ' %s\n' "${cacheFiles[@]}" >&2
printf '\nUse git rm --cached -- <file> to unstage forced additions.\n' >&2
exit 1