Last active
May 18, 2022 14:43
-
-
Save axi92/54af5bb9b26df3d3219f26483a7b74b3 to your computer and use it in GitHub Desktop.
pre-commit git hook prevent binaries from commiting
This file contains hidden or 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 | |
staginlist=(`git diff --name-only --cached`) | |
binarylist=() | |
for filelist in ${staginlist[*]} | |
do | |
grep -Iq . ${filelist} | |
if [ $? -ne 0 ] | |
then | |
binarylist+=(${filelist}) | |
fi | |
done | |
if [ ${#binarylist[@]} -ne 0 ] | |
then | |
echo "# Binary files were found, remove them from the staging before commiting." | |
for filelist in ${binarylist[*]} | |
do | |
echo ${filelist} | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment