Skip to content

Instantly share code, notes, and snippets.

@rpq
Created May 2, 2012 13:48
Show Gist options
  • Save rpq/2576630 to your computer and use it in GitHub Desktop.
Save rpq/2576630 to your computer and use it in GitHub Desktop.
git pre-commit hook: white space check
52 WHITESPACE_CHECK=`git status | grep modified | awk -F" " '{print $3}' | xargs -I '{}' grep -nPH "^[ ]+$" '{}'`
53 WHITESPACE_CHECK_COUNT=`echo "$WHITESPACE_CHECK" | wc -w`
54 if [ "$WHITESPACE_CHECK_COUNT" != "0" ]; then
55 echo "$WHITESPACE_CHECK" | xargs -I '{}' echo ">> git pre-commit hook: white space in {}"
56 exit 1
57 fi
@rpq
Copy link
Author

rpq commented Aug 15, 2014

  1 #!/bin/sh
  2 
  3 WHITESPACE_CHECK=`git status | grep modified | awk -F" " '{print $3}' | xargs -I '{}' grep -nEH "[ ]+$" '{}'`
  4 WHITESPACE_CHECK_COUNT=`echo "$WHITESPACE_CHECK" | wc -w | tr -d ' '`
  5 
  6 if [ "$WHITESPACE_CHECK_COUNT" != "0" ]; then
  7     echo "$WHITESPACE_CHECK" | xargs -I '{}' echo ">> git pre-commit hook: white space in {}"
  8     exit 1
  9 fi
 10 echo 'done'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment