Skip to content

Instantly share code, notes, and snippets.

@nilnilnil
Created May 29, 2013 14:12
Show Gist options
  • Save nilnilnil/5670554 to your computer and use it in GitHub Desktop.
Save nilnilnil/5670554 to your computer and use it in GitHub Desktop.
#!/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