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