|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# To activate this git hook on your local dev environment: |
| 4 | +# copy or symlink this file to .git/hooks/pre-commit, and chmod +x to make executable |
| 5 | + |
| 6 | +if git rev-parse --verify HEAD >/dev/null 2>&1 |
| 7 | +then |
| 8 | + against=HEAD |
| 9 | +else |
| 10 | + # Initial commit: diff against an empty tree object |
| 11 | + against=$(git hash-object -t tree /dev/null) |
| 12 | +fi |
| 13 | + |
| 14 | +# If you want to allow non-ASCII filenames set this variable to true. |
| 15 | +allownonascii=$(git config --bool hooks.allownonascii) |
| 16 | + |
| 17 | +# Redirect output to stderr. |
| 18 | +exec 1>&2 |
| 19 | + |
| 20 | +# Cross platform projects tend to avoid non-ASCII filenames; prevent |
| 21 | +# them from being added to the repository. We exploit the fact that the |
| 22 | +# printable range starts at the space character and ends with tilde. |
| 23 | +if [ "$allownonascii" != "true" ] && |
| 24 | + # Note that the use of brackets around a tr range is ok here, (it's |
| 25 | + # even required, for portability to Solaris 10's /usr/bin/tr), since |
| 26 | + # the square bracket bytes happen to fall in the designated range. |
| 27 | + test $(git diff --cached --name-only --diff-filter=A -z $against | |
| 28 | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 |
| 29 | +then |
| 30 | + cat <<\EOF |
| 31 | +Error: Attempt to add a non-ASCII file name. |
| 32 | +
|
| 33 | +This can cause problems if you want to work with people on other platforms. |
| 34 | +
|
| 35 | +To be portable it is advisable to rename the file. |
| 36 | +
|
| 37 | +If you know what you are doing you can disable this check using: |
| 38 | +
|
| 39 | + git config hooks.allownonascii true |
| 40 | +EOF |
| 41 | + exit 1 |
| 42 | +fi |
| 43 | + |
| 44 | +if [ -n "$VIRTUAL_ENV" ]; then |
| 45 | + echo "Trying to avtivate venv at $VIRTUAL_ENV" |
| 46 | + . "$VIRTUAL_ENV"/bin/activate |
| 47 | +else |
| 48 | + echo "Trying to avtivate venv at ./.venv" |
| 49 | + . ./.venv/bin/activate |
| 50 | +fi |
| 51 | + |
| 52 | +OUT1=`make dev-test 1>&2` |
| 53 | +if [ $? -eq 0 ]; then |
| 54 | + echo "Tests passed\n" |
| 55 | +else |
| 56 | + echo "Tests failed! Cannot commit changes.\n" |
| 57 | + exit 1 |
| 58 | +fi |
| 59 | +OUT2=`make lint 1>&2` |
| 60 | +if [ $? -eq 0 ]; then |
| 61 | + echo "Lints passed\n" |
| 62 | +else |
| 63 | + echo "Lints failed! Cannot commit changes.\n" |
| 64 | + exit 1 |
| 65 | +fi |
| 66 | +OUT3=`make type-check 1>&2` |
| 67 | +if [ $? -eq 0 ]; then |
| 68 | + echo "Type Checking passed\n" |
| 69 | +else |
| 70 | + echo "Type Checking failed! Cannot commit changes.\n" |
| 71 | + exit 1 |
| 72 | +fi |
| 73 | + |
| 74 | + |
| 75 | +# If there are whitespace errors, print the offending file names and fail. |
| 76 | +exec git diff-index --check --cached $against -- |
0 commit comments