Skip to content

Instantly share code, notes, and snippets.

@axi92
Last active May 18, 2022 14:43
Show Gist options
  • Save axi92/54af5bb9b26df3d3219f26483a7b74b3 to your computer and use it in GitHub Desktop.
Save axi92/54af5bb9b26df3d3219f26483a7b74b3 to your computer and use it in GitHub Desktop.
pre-commit git hook prevent binaries from commiting
#!/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