Donald Meyers / Mbed OS evan
Committer:
djmeyers
Date:
Sat Mar 18 22:37:16 2017 +0000
Revision:
0:06ee5f8a484a
Initial commit

Who changed what in which revision?

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