|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# checks for filenames with non-ASCII characters |
| 4 | +if git rev-parse --verify HEAD >/dev/null 2>&1 |
| 5 | +then |
| 6 | + against=HEAD |
| 7 | +else |
| 8 | + # Initial commit: diff against an empty tree object |
| 9 | + against=$(git hash-object -t tree /dev/null) |
| 10 | +fi |
| 11 | + |
| 12 | +# If you want to allow non-ASCII filenames set this variable to true. |
| 13 | +allownonascii=$(git config --type=bool hooks.allownonascii) |
| 14 | + |
| 15 | +# Redirect output to stderr. |
| 16 | +exec 1>&2 |
| 17 | + |
| 18 | +# Cross platform projects tend to avoid non-ASCII filenames; prevent |
| 19 | +# them from being added to the repository. We exploit the fact that the |
| 20 | +# printable range starts at the space character and ends with tilde. |
| 21 | +if [ "$allownonascii" != "true" ] && |
| 22 | + # Note that the use of brackets around a tr range is ok here, (it's |
| 23 | + # even required, for portability to Solaris 10's /usr/bin/tr), since |
| 24 | + # the square bracket bytes happen to fall in the designated range. |
| 25 | + test $(git diff-index --cached --name-only --diff-filter=A -z $against | |
| 26 | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 |
| 27 | +then |
| 28 | + cat <<\EOF |
| 29 | +Error: Attempt to add a non-ASCII file name. |
| 30 | +
|
| 31 | +This can cause problems if you want to work with people on other platforms. |
| 32 | +
|
| 33 | +To be portable it is advisable to rename the file. |
| 34 | +
|
| 35 | +If you know what you are doing you can disable this check using: |
| 36 | +
|
| 37 | + git config hooks.allownonascii true |
| 38 | +EOF |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +# runs pseudo-lint on staged files |
| 43 | +git diff --name-only --cached | grep -E ".*\.(ex|exs)$" | xargs mix format --check-formatted |
| 44 | + |
| 45 | +PSEUDOLINT_STATUS=$? |
| 46 | +if [ "$PSEUDOLINT_STATUS" != "0" ]; then |
| 47 | + echo 'run `mix format` then use `git add` to restage the formatted file' |
| 48 | + exit $PSEUDOLINT_STATUS |
| 49 | +fi |
0 commit comments