Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- #
- # This hook corrects any white spacing errors on what is about to be committed.
- # Called by git-commit with no arguments. The hook should exit with non-zero
- # status after issuing an appropriate message, if it wants to stop the commit.
- #
- # If a whitespace error is found, it's corrected, it notifies the user that
- # whitespace error was found, fixes the errors, removes the original, and
- # adds it back to the staginging area.
- # --- Config
- allowwhitespace=$(git config --bool hooks.autowhitespace)
- allowwhitespaceremoveoriginal=$(git config --bool hooks.whitespaceremoveoriginal)
- if [ "$allowwhitespace" != "true" ]; then
- # Repository's config prevents us from performming this hook
- exit 0
- fi
- if git rev-parse --verify HEAD > /dev/null
- then
- against=HEAD
- else
- # Initial commit: diff against an empty tree object
- against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
- fi
- old_IFS=$IFS
- IFS=$'\n'
- for FILE in `git diff-index --check --cached $against 2>&1 | sed '/^\+/d' | sed 's/:.*//' | uniq` ; do
- echo "WARNING: Trailing whitespaces are being removed for $FILE."
- sed -ie 's/[[:space:]]*$//' "$FILE"
- git add $FILE
- if [ "$allowwhitespaceremoveoriginal" = "true" ]; then
- rm $FILE"e"
- fi
- done
- IFS=$old_IFS
- exit 0
Add Comment
Please, Sign In to add comment