You can see a good example of pre-commit hook in this gist, in reference to this answer about valid Windows names
# A hook script to check that the to-be-commited files are valid
# filenames on a windows platform.
# Sources:
# - https://stackoverflow.com/a/62888
# - http://msdn.microsoft.com/en-us/library/aa365247.aspx
#
# To enable this hook, rename this file to "pre-commit", move it to ".git/hook" and make it executable
It uses git diff
:
git diff --cached --name-only --diff-filter=A -z $against
Note that a pre-commit
hook is a client-side hook, meaning it has to be deployed in all repos for all users.
And it can be bypassed (with git commit --no-verify
).
Another approach is to set a pre-receive
hook (server-side hook) which will block any push including invalid filenames.