Created
May 29, 2013 14:12
-
-
Save nilnilnil/5670554 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Redirect output to stderr. | |
exec 1>&2 | |
# list staged go files | |
lsgo() { | |
git ls-files|egrep '.*.go$' | |
} | |
# get the contents of $1 from the staging area | |
# (the staging area is the stuff that will be committed) | |
catstaged() { | |
git cat-file -p :$1 | |
} | |
check() { | |
if test -n "`gofmt -d <(catstaged $1)`" | |
then echo error: gofmt $1 && return 1 | |
fi | |
} | |
ok=true | |
for file in `lsgo` | |
do check $file || ok=false | |
done | |
test $ok = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment