Hans-Christoph Steiner | 0761ec3 | 2019-01-09 13:00:45 +0100 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # An hook script to verify what is about to be committed. |
| 4 | # Called by "git commit" with no arguments. The hook will |
| 5 | # exit with non-zero status after issuing an appropriate message if |
| 6 | # it wants to stop the commit. |
| 7 | |
| 8 | if git rev-parse --verify HEAD >/dev/null 2>&1 |
| 9 | then |
Hans-Christoph Steiner | a0b7f61 | 2019-01-09 14:28:35 +0100 | [diff] [blame] | 10 | against=HEAD |
Hans-Christoph Steiner | 0761ec3 | 2019-01-09 13:00:45 +0100 | [diff] [blame] | 11 | else |
Hans-Christoph Steiner | a0b7f61 | 2019-01-09 14:28:35 +0100 | [diff] [blame] | 12 | # Initial commit: diff against an empty tree object |
| 13 | against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
Hans-Christoph Steiner | 0761ec3 | 2019-01-09 13:00:45 +0100 | [diff] [blame] | 14 | fi |
| 15 | |
| 16 | # If you want to allow non-ascii filenames set this variable to true. |
| 17 | allownonascii=$(git config hooks.allownonascii) |
| 18 | |
| 19 | # Redirect output to stderr. |
| 20 | exec 1>&2 |
| 21 | |
| 22 | # Cross platform projects tend to avoid non-ascii filenames; prevent |
| 23 | # them from being added to the repository. We exploit the fact that the |
| 24 | # printable range starts at the space character and ends with tilde. |
| 25 | if [ "$allownonascii" != "true" ] && |
Hans-Christoph Steiner | a0b7f61 | 2019-01-09 14:28:35 +0100 | [diff] [blame] | 26 | # Note that the use of brackets around a tr range is ok here, (it's |
| 27 | # even required, for portability to Solaris 10's /usr/bin/tr), since |
| 28 | # the square bracket bytes happen to fall in the designated range. |
| 29 | test $(git diff --cached --name-only --diff-filter=A -z $against | |
| 30 | LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 |
Hans-Christoph Steiner | 0761ec3 | 2019-01-09 13:00:45 +0100 | [diff] [blame] | 31 | then |
Hans-Christoph Steiner | a0b7f61 | 2019-01-09 14:28:35 +0100 | [diff] [blame] | 32 | echo "Error: Attempt to add a non-ascii file name." |
| 33 | echo |
| 34 | echo "This can cause problems if you want to work" |
| 35 | echo "with people on other platforms." |
| 36 | echo |
| 37 | echo "To be portable it is advisable to rename the file ..." |
| 38 | echo |
| 39 | echo "If you know what you are doing you can disable this" |
| 40 | echo "check using:" |
| 41 | echo |
| 42 | echo " git config hooks.allownonascii true" |
| 43 | echo |
| 44 | exit 1 |
Hans-Christoph Steiner | 0761ec3 | 2019-01-09 13:00:45 +0100 | [diff] [blame] | 45 | fi |
| 46 | |
| 47 | # If there are whitespace errors, print the offending file names and fail. |
| 48 | exec git diff-index --check --cached $against -- |