Created
August 7, 2014 18:38
-
-
Save Pezmc/0b99040930b5e2a009f8 to your computer and use it in GitHub Desktop.
Git pre-commit prevent commit of certain files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
error_found=false | |
declare -a BANNED_PATTERNS=("app/config/database.php") | |
# Terminal | |
if [ -t 1 ]; then | |
ncolors=$(tput colors) | |
if test -n "$ncolors" && test $ncolors -ge 8; then | |
normal="$(tput sgr0)" | |
red="$(tput setaf 1)" | |
fi | |
fi | |
# Check banned files | |
for FILE in `git diff --cached --name-only` ; do | |
for PATTERN in $BANNED_PATTERNS; do | |
if [[ $FILE == $PATTERN ]] | |
then | |
echo "Banned file ${red}$FILE${normal} cannot be committed" | |
error_found=true | |
fi | |
done | |
done | |
# Report errors | |
if [ "$error_found" = true ] | |
then | |
echo "To commit anyway, use --no-verify" | |
exit 1 | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment