pre-commit hook: avoid avoid setting GIT_DIR when running go
It seems that `go get` explodes and craps over your git directory if you set GIT_DIR, and some of the go tools run `go get` indirectly, so let's jump through some hoops to fix it.
This commit is contained in:
parent
aa8ec7dd5d
commit
ee67dc1f2e
1 changed files with 10 additions and 3 deletions
|
@ -2,8 +2,12 @@
|
|||
|
||||
set -eu
|
||||
|
||||
# make the GIT_DIR and GIT_INDEX_FILE absolute, before we change dir
|
||||
export GIT_DIR=$(readlink -f `git rev-parse --git-dir`)
|
||||
# make git_dir and GIT_INDEX_FILE absolute, before we change dir
|
||||
#
|
||||
# (don't actually set GIT_DIR, because it messes up `go get`, and several of
|
||||
# the go commands run `go get` indirectly)
|
||||
#
|
||||
git_dir=$(readlink -f `git rev-parse --git-dir`)
|
||||
if [ -n "${GIT_INDEX_FILE:+x}" ]; then
|
||||
export GIT_INDEX_FILE=$(readlink -f "$GIT_INDEX_FILE")
|
||||
fi
|
||||
|
@ -19,7 +23,7 @@ cd "$tmpdir"
|
|||
# get a clean copy of the index (ie, what has been `git add`ed), so that we can
|
||||
# run the checks against what we are about to commit, rather than what is in
|
||||
# the working copy.
|
||||
git checkout-index -a
|
||||
git --git-dir="${git_dir}" checkout-index -a
|
||||
|
||||
# run our checks
|
||||
golint src/...
|
||||
|
@ -28,6 +32,9 @@ go tool vet --shadow ./src
|
|||
gocyclo -over 12 src/
|
||||
gb test
|
||||
|
||||
# we're done with go so can set GIT_DIR
|
||||
export GIT_DIR="$git_dir"
|
||||
|
||||
# if there are no changes from the index, we are done
|
||||
git diff --quiet && exit 0
|
||||
|
||||
|
|
Reference in a new issue