Skip to content

Instantly share code, notes, and snippets.

@briansorahan
Last active September 16, 2015 12:57
Show Gist options
  • Save briansorahan/45f73900c4fa43a964d3 to your computer and use it in GitHub Desktop.
Save briansorahan/45f73900c4fa43a964d3 to your computer and use it in GitHub Desktop.
Setup a simple pre-commit hook for go projects
#!/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