You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.6 KiB

2 years ago
  1. #!/bin/sh
  2. #
  3. # An example hook script to verify what is about to be committed.
  4. # Called by "git commit" with no arguments. The hook should
  5. # exit with non-zero status after issuing an appropriate message if
  6. # it wants to stop the commit.
  7. #
  8. # To enable this hook, rename this file to "pre-commit".
  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=$(git hash-object -t tree /dev/null)
  15. fi
  16. # If you want to allow non-ASCII filenames set this variable to true.
  17. allownonascii=$(git config --type=bool hooks.allownonascii)
  18. # Redirect output to stderr.
  19. exec 1>&2
  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. This can cause problems if you want to work with people on other platforms.
  33. To be portable it is advisable to rename the file.
  34. If you know what you are doing you can disable this check using:
  35. git config hooks.allownonascii true
  36. EOF
  37. exit 1
  38. fi
  39. # If there are whitespace errors, print the offending file names and fail.
  40. exec git diff-index --check --cached $against --