diff --git a/.git-hooks/init b/.git-hooks/init new file mode 100755 index 0000000..5b6e8ab --- /dev/null +++ b/.git-hooks/init @@ -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" diff --git a/.git-hooks/pre-push b/.git-hooks/pre-push new file mode 100755 index 0000000..9383afa --- /dev/null +++ b/.git-hooks/pre-push @@ -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