Guest User

Untitled

a guest
Feb 19th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  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.  
  10. exec < /dev/tty
  11.  
  12. if git rev-parse --verify HEAD >/dev/null 2>&1
  13. then
  14. against=HEAD
  15. else
  16. # Initial commit: diff against an empty tree object
  17. against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
  18. fi
  19.  
  20.  
  21. read -p 'Run PhpCs? [y/n](n):' proceed
  22.  
  23. if [ "$proceed" = 'y' ]; then
  24. phpfiles=$(git diff --name-only --diff-filter=d $against | grep \.php)
  25.  
  26. if [ "$phpfiles" != "" ]; then
  27. test=$(phpcs -q --report=diff $phpfiles)
  28.  
  29. if [ "$test" = "" ]; then
  30. echo 'passed'
  31. else
  32. echo "$test"
  33. exit 1;
  34. fi
  35. fi
  36. fi
  37.  
  38. read -p 'Run PhpStan? [y/n](n):' proceed
  39.  
  40. if [ "$proceed" = 'y' ]; then
  41. phpfiles=$(git diff --name-only --diff-filter=d $against | grep \.php)
  42.  
  43. if [ "$phpfiles" != "" ]; then
  44. test=$(phpstan analyze --errorFormat=raw -a autoload.php $phpfiles)
  45.  
  46. if [ "$test" = "" ]; then
  47. echo 'passed'
  48. else
  49. echo "$test"
  50. exit 1;
  51. fi
  52. fi
  53. fi
  54.  
  55.  
  56. # If you want to allow non-ASCII filenames set this variable to true.
  57. allownonascii=$(git config --bool hooks.allownonascii)
  58.  
  59. # Redirect output to stderr.
  60. exec 1>&2
  61.  
  62. # Cross platform projects tend to avoid non-ASCII filenames; prevent
  63. # them from being added to the repository. We exploit the fact that the
  64. # printable range starts at the space character and ends with tilde.
  65. if [ "$allownonascii" != "true" ] &&
  66. # Note that the use of brackets around a tr range is ok here, (it's
  67. # even required, for portability to Solaris 10's /usr/bin/tr), since
  68. # the square bracket bytes happen to fall in the designated range.
  69. test $(git diff --cached --name-only --diff-filter=A -z $against |
  70. LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
  71. then
  72. cat <<\EOF
  73. Error: Attempt to add a non-ASCII file name.
  74.  
  75. This can cause problems if you want to work with people on other platforms.
  76.  
  77. To be portable it is advisable to rename the file.
  78.  
  79. If you know what you are doing you can disable this check using:
  80.  
  81. git config hooks.allownonascii true
  82. EOF
  83. exit 1
  84. fi
  85.  
  86. # If there are whitespace errors, print the offending file names and fail.
  87. exec git diff-index --check --cached $against --
Add Comment
Please, Sign In to add comment