Skip to content

Commit

Permalink
add pre-commit hook file
Browse files Browse the repository at this point in the history
  • Loading branch information
dlenski committed Jun 11, 2016
1 parent 9b693e2 commit b2b01f9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pre-commit.careful
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

wtf_options='-q'
tmp=$(mktemp)

# Run Whitespace Total Fixer on index contents WITHOUT modifying working directory
git diff-index --cached HEAD --diff-filter=ACMRTU |
while read _ MODE _ SHA1 _ FILE
do
if ! ( git cat-file blob $SHA1 | wtf $wtf_options > $tmp ); then
git update-index --cacheinfo $MODE $(git hash-object -w $tmp) "$FILE"
echo "Fixed whitespace in $FILE" >&2
fi
done
rm -f $tmp 2> /dev/null

0 comments on commit b2b01f9

Please sign in to comment.