adding git hooks

This commit is contained in:
Jorge Morante 2016-07-14 22:48:11 +02:00
parent bfbc8001ee
commit 0ecb515b1f
2 changed files with 37 additions and 0 deletions

8
.git-hooks/init Executable file
View File

@ -0,0 +1,8 @@
#!/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
GIT_DIR=$CURRENT_DIR/../.git
GIT_HOOKS_DIR=$GIT_DIR/hooks
rm -rf "$GIT_HOOKS_DIR"
ln -s "$CURRENT_DIR" "$GIT_HOOKS_DIR"

29
.git-hooks/pre-push Executable file
View File

@ -0,0 +1,29 @@
#!/bin/env bash
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ ${current_branch} != "master" ]]; then
exit 0
fi
echo "Pushing to master? Let me run some pre-push hooks ..."
grep_debug='git grep -n "debug.sh" -- *.sh'
grep_log_calls='git grep -n "log " -- *.sh'
WHITE_LIST_SCRIPTS="^(\\.git-hooks)"
include_debug_count=$(eval "$grep_debug" | grep -v $WHITE_LIST_SCRIPTS | wc -l)
log_calls_count=$(eval "$grep_log_calls" | grep -v $WHITE_LIST_SCRIPTS | wc -l)
if [[ $((include_debug_count + log_calls_count)) -gt 1 ]]; then
echo "Remove debug traces!"
echo ""
eval "$grep_debug" > /dev/stdout
eval "$grep_log_calls" > /dev/stdout
exit 1
fi
# TODO for some reason, tests fail when ran from pre-push hook ( WTF? )
if [[ -z $I_ASSURE_YOU_TESTS_ARE_PASSING ]]; then
echo ""
echo "Run ./test/run.sh before pushing to master. Then set I_ASSURE_YOU_TESTS_ARE_PASSING variable to bypass this" | fold -sw 80
exit 1
fi