Last active
September 16, 2015 12:57
-
-
Save briansorahan/45f73900c4fa43a964d3 to your computer and use it in GitHub Desktop.
Setup a simple pre-commit hook for go projects
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
#!/bin/bash | |
add_precommit_hook() { | |
local dir=$1 | |
local sample=$dir/pre-commit.sample | |
local file=${sample/%.sample/} | |
rm -f $sample | |
echo '#!/bin/bash' > $file | |
echo 'exec go test -race' >> $file | |
chmod +x $file | |
} | |
main() { | |
local dir=.git/hooks | |
if [[ ! -d $dir ]]; then | |
>&2 echo 'Are you sure this is a git repository?' | |
fi | |
add_precommit_hook $dir | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment