I don't know the existing hook, but git already has a hook that checks for the presence of "non-ascii names" as a pre-commit pattern. This will probably already be in existing git repositories like .git/hooks/pre-commit.sample .
Using this hook as a template and considering the answers to How to determine if a git file processes a file as binary or text? , you can do something like this (see "git semi-secret empty tree" , where EMPTY_TREE comes EMPTY_TREE ):
#! /bin/sh stop_binaries=$(git config --get hooks.stop_binaries) exec 1>&2 if [ "$stop_binaries" = true ]; then EMPTY_TREE=$(git hash-object -t tree /dev/null)
This uses git diff --cached to see what would be done by comparing it all with the original empty tree. Note that it will reject commits with already existing (but unchanged) binaries; so that it rejects only new or changed binaries, add the against= logic from the non-ascii name hook. To reject only new binaries, also add the argument --diff-filter=A
Come up with this with additional error message text if you want. You can cancel the test (instead of saying “stop binaries”, make it stop by default, and you must set “allowbinaries” to add binary files), etc. And, of course, you can allow specific directories full of binaries, or something else by doing extra filtering on the output of the diff index.
torek source share