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