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