forked from istio/istio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·40 lines (33 loc) · 855 Bytes
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
#!/bin/bash
# Run local pre-commit hook
#
# If called directly, installs a pre-commit hook
set -o errexit
WD=$(dirname $0)
WD=$(cd $WD; pwd)
ROOT=$(dirname $WD)
if [[ $ROOT == */.git ]]; then
ROOT=$ROOT/..
fi
export GOPATH=$(cd $ROOT/../..)
export PATH=$GOPATH/bin:$PATH
# Not running under git commit
# install handler
if [[ -z ${GIT_AUTHOR_DATE} ]];then
cd $ROOT/.git/hooks/
if !([[ -e pre-commit ]] || [[ -h pre-commit ]]); then
echo "Installing pre-commit hook"
ln -s $ROOT/bin/pre-commit
else
echo "Hook already installed"
fi
exit 0
fi
# If we don't have a branch then we're in a detached state (e.g. mid
# rebase) and don't want to execute our checks.
BRANCH_NAME=$(git branch | grep '*' | sed 's/* //')
if [ $BRANCH_NAME != '(no branch)' ]; then
cd $ROOT
make precommit
fi