#!/bin/sh # # An example hook script to verify 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. # # To enable this hook, rename this file to "pre-commit". basedir=$(dirname $0) . $basedir/../hook-functions if git-rev-parse --verify HEAD > /dev/null then against=HEAD else exit 0 fi old_IFS=$IFS IFS=$'\n' for FILE in $(git-diff-index --name-only $against); do #`git-diff-index --check --cached $against 2>&1 |\ # sed '/^[\*\+]/d' |\ # sed 's/:.*//' | uniq` ; do [ -f "$FILE" ] || continue grep -E -q "[[:space:]]+$" $FILE && { ewarn "\"$FILE\" has whitespace at line $(grep -E -n "[[:space:]]+$" $FILE 2>/dev/null | cut -f1 -d:)" } grep -q " " $FILE && { eerror "\"$FILE\" has forbidden UTF-8 whitespaces at line $(grep " " $FILE 2>/dev/null | cut -f1 -d:)" } # sed -ie 's/[[:space:]]*$//' $FILE # rm $FILE"e" # git add $FILE done IFS=$old_IFS exit 0