Guest User

Untitled

a guest
Feb 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #!/bin/sh
  2. #
  3. # This hook corrects any white spacing errors on what is about to be committed.
  4. # Called by git-commit with no arguments. The hook should exit with non-zero
  5. # status after issuing an appropriate message, if it wants to stop the commit.
  6. #
  7. # If a whitespace error is found, it's corrected, it notifies the user that
  8. # whitespace error was found, fixes the errors, removes the original, and
  9. # adds it back to the staginging area.
  10.  
  11. # --- Config
  12. allowwhitespace=$(git config --bool hooks.autowhitespace)
  13. allowwhitespaceremoveoriginal=$(git config --bool hooks.whitespaceremoveoriginal)
  14.  
  15. if [ "$allowwhitespace" != "true" ]; then
  16. # Repository's config prevents us from performming this hook
  17. exit 0
  18. fi
  19.  
  20. if git rev-parse --verify HEAD > /dev/null
  21. then
  22. against=HEAD
  23. else
  24. # Initial commit: diff against an empty tree object
  25. against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
  26. fi
  27.  
  28. old_IFS=$IFS
  29. IFS=$'\n'
  30.  
  31. for FILE in `git diff-index --check --cached $against 2>&1 | sed '/^\+/d' | sed 's/:.*//' | uniq` ; do
  32. echo "WARNING: Trailing whitespaces are being removed for $FILE."
  33. sed -ie 's/[[:space:]]*$//' "$FILE"
  34. git add $FILE
  35. if [ "$allowwhitespaceremoveoriginal" = "true" ]; then
  36. rm $FILE"e"
  37. fi
  38. done
  39.  
  40. IFS=$old_IFS
  41.  
  42. exit 0
Add Comment
Please, Sign In to add comment