github.com/jasonkeene/cli@v6.14.1-0.20160816203908-ca5715166dfb+incompatible/githooks/pre-commit/non-ascii-filenames (about)

     1  #!/bin/sh
     2  
     3  set -e
     4  
     5  # Redirect output to stderr.
     6  exec 1>&2
     7  ROOT_DIR=$(cd $(dirname $(dirname $0)/)/.. && pwd)
     8  
     9  if git rev-parse --verify HEAD >/dev/null 2>&1
    10  then
    11      against=HEAD
    12  else
    13      # Initial commit: diff against an empty tree object
    14      against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
    15  fi
    16  
    17  set +e
    18  # If you want to allow non-ASCII filenames set this variable to true.
    19  allownonascii=$(git config --bool hooks.allownonascii)
    20  set -e
    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" ] &&
    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
    31  then
    32      cat <<\EOF
    33  Error: Attempt to add a non-ASCII file name.
    34  
    35  This can cause problems if you want to work with people on other platforms.
    36  
    37  To be portable it is advisable to rename the file.
    38  
    39  If you know what you are doing you can disable this check using:
    40  
    41    git config hooks.allownonascii true
    42  EOF
    43      exit 1
    44  fi
    45  
    46  # If there are whitespace errors, print the offending file names and fail.
    47  git diff-index --check --cached $against --