#!/bin/sh # # An example hook script to verify what is about to be committed. # Called by "git commit" with no arguments. The hook should # exit with non-zero status after issuing an appropriate message if # it wants to stop the commit. # # To enable this hook, rename this file to "pre-commit". if git rev-parse --verify HEAD >/dev/null 2>&1 then against=HEAD else # Initial commit: diff against an empty tree object against=$(git hash-object -t tree /dev/null) fi SCRIPT_DIR=$(dirname "$0") SCRIPT_ABS_PATH=`cd "$SCRIPT_DIR"; pwd` ANDROID_DIFF_FILES=`git diff --cached --name-only --diff-filter=ACM -- '*' | grep 'Android'` if [[ "$ANDROID_DIFF_FILES" != "" ]] then cd Android/APIExample echo "precommit >> current paht = $(pwd), diff files = $ANDROID_DIFF_FILES" ./gradlew -Dorg.gradle.project.commit_diff_files="$ANDROID_DIFF_FILES" checkstyle detekt if [ $? -eq 0 ]; then echo "precommit >> checkstyle detekt OK." else echo "precommit >> checkstyle detekt Failed." exit 1 fi else echo "precommit >> No changing android files." fi