rlm@11: #!/bin/sh rlm@11: # rlm@11: # An example hook script to verify what is about to be committed. rlm@11: # Called by git-commit with no arguments. The hook should rlm@11: # exit with non-zero status after issuing an appropriate message if rlm@11: # it wants to stop the commit. rlm@11: # rlm@11: # To enable this hook, rename this file to "pre-commit". rlm@11: rlm@11: if git-rev-parse --verify HEAD >/dev/null 2>&1 rlm@11: then rlm@11: against=HEAD rlm@11: else rlm@11: # Initial commit: diff against an empty tree object rlm@11: against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 rlm@11: fi rlm@11: rlm@11: # If you want to allow non-ascii filenames set this variable to true. rlm@11: allownonascii=$(git config hooks.allownonascii) rlm@11: rlm@11: # Cross platform projects tend to avoid non-ascii filenames; prevent rlm@11: # them from being added to the repository. We exploit the fact that the rlm@11: # printable range starts at the space character and ends with tilde. rlm@11: if [ "$allownonascii" != "true" ] && rlm@11: # Note that the use of brackets around a tr range is ok here, (it's rlm@11: # even required, for portability to Solaris 10's /usr/bin/tr), since rlm@11: # the square bracket bytes happen to fall in the designated range. rlm@11: test "$(git diff --cached --name-only --diff-filter=A -z $against | rlm@11: LC_ALL=C tr -d '[ -~]\0')" rlm@11: then rlm@11: echo "Error: Attempt to add a non-ascii file name." rlm@11: echo rlm@11: echo "This can cause problems if you want to work" rlm@11: echo "with people on other platforms." rlm@11: echo rlm@11: echo "To be portable it is advisable to rename the file ..." rlm@11: echo rlm@11: echo "If you know what you are doing you can disable this" rlm@11: echo "check using:" rlm@11: echo rlm@11: echo " git config hooks.allownonascii true" rlm@11: echo rlm@11: exit 1 rlm@11: fi rlm@11: rlm@11: exec git diff-index --check --cached $against --