various improvements
[distro-setup] / .git_template / hooks / pre-commit
index ad2218a75005212d19a5da44fe034cc6a788f6ea..33a6f8ca3280a918b2e91175818d507771790607 100755 (executable)
@@ -14,9 +14,8 @@
 # limitations under the License.
 
 
-# This is the git upstream example hook, but it's actually useful.
+# ian: This section is the git upstream example hook, but it's actually useful.
 
-#
 # 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
@@ -58,17 +57,18 @@ EOF
     exit 1
 fi
 
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
 
 
-# inspired from:
+# ian: inspired from:
 # https://github.com/ntc2/conf/blob/master/dot.gitconfig
+# last checked for any changes there on 7/2016
 # duplicated at,
 # http://stackoverflow.com/a/15398512/14456
-# last checked for any changes there on 7/2016
 
 
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
+
 if [[ $(git config --bool hooks.allowwhitespace) == true ]] || \
        [[ $GIT_ALLOWWHITESPACE == true ]]; then
     exit 0
@@ -94,8 +94,9 @@ if ! git rev-list HEAD --count &>/dev/null; then
     cat <<'EOF'
 Whitespace issues found. We can't fix in a pre-commit hook for the first commit.
 Either fix on your own. I suggest https://github.com/dlenski/wtf, from git root:
-find . -not -name .git -type f -exec bash -c \
-         'grep -Il "" "$1" &>/dev/null && wtf.py -i -E lf "$1"' _ {} \;
+
+git ls-files --exclude-standard -cmo --no-empty-directory | while read -r f; do if [[ -L $f ]] || ! grep -Iq . "$f"; then continue; fi;  wtf.py -i -E lf "$f"; done
+
 or allow whitespace with:
 git config hooks.allowwhitespace true, or export GIT_ALLOWWHITESPACE=true
 EOF