Guest User

Untitled

a guest
May 26th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #!/bin/sh
  2. # mostly default pre-commit hook
  3.  
  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=4b825dc642cb6eb9a060e54bf8d69288fbee4904
  10. fi
  11.  
  12. # If you want to allow non-ascii filenames set this variable to true.
  13. allownonascii=$(git config hooks.allownonascii)
  14.  
  15. # Cross platform projects tend to avoid non-ascii filenames; prevent
  16. # them from being added to the repository. We exploit the fact that the
  17. # printable range starts at the space character and ends with tilde.
  18. if [ "$allownonascii" != "true" ] &&
  19. # Note that the use of brackets around a tr range is ok here, (it's
  20. # even required, for portability to Solaris 10's /usr/bin/tr), since
  21. # the square bracket bytes happen to fall in the designated range.
  22. test "$(git diff --cached --name-only --diff-filter=A -z $against |
  23. LC_ALL=C tr -d '[ -~]\0')"
  24. then
  25. echo "Error: Attempt to add a non-ascii file name."
  26. echo
  27. echo "This can cause problems if you want to work"
  28. echo "with people on other platforms."
  29. echo
  30. echo "To be portable it is advisable to rename the file ..."
  31. echo
  32. echo "If you know what you are doing you can disable this"
  33. echo "check using:"
  34. echo
  35. echo " git config hooks.allownonascii true"
  36. echo
  37. exit 1
  38. fi
  39.  
  40. # console.log is useful when testing, but it should not be commited
  41. if [ "$allowjsconsole" != "true" ]; then
  42. jsfiles=$(git diff --cached --name-only --relative $against | sed -n '/\.js$/p');
  43. if [ -n "$jsfiles" ] &&
  44. [ -n "$( git diff --cached -Sconsole. $jsfiles | sed -n 's/console\.\(\w\+\)(.*\?)/&/p')" ];
  45. then
  46. echo "Error: Attempt to commit javascript with js console usage."
  47. echo
  48. echo "This might upset the master people..."
  49. echo
  50. echo "if you don't care about their wishes, you can disable"
  51. echo "this check by using:"
  52. echo
  53. echo " git config hooks.allowjsconsole true"
  54. echo
  55. exit 1
  56. fi
  57. fi
  58.  
  59. exec git diff-index --check --cached $against --
Add Comment
Please, Sign In to add comment