Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Performs verification before code is pushed to git remote repository
- #
- # To skip the verification, run git push with the --no-verify argument
- # i.e. - $ 'git push --no-verify'
- #
- # Verification is performed in separate directory, thus not affecting current project dir
- #
- echoerr() { echo "$@" 1>&2; }
- set -e # fail in case of any error
- CURRENT_REPO_DIR=`pwd`
- OUTPUT_REPO_DIR="$CURRENT_REPO_DIR/.verification"
- CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
- git fetch
- LOCAL_COMMIT=$(git rev-parse @)
- REMOTE_COMMIT=$(git rev-parse @{u})
- BASE_COMMIT=$(git merge-base @ @{u})
- if [ $REMOTE_COMMIT != $BASE_COMMIT ]
- then
- echoerr "Branch not up-to-date. Please invoke: git pull"
- exit 1
- fi
- if [ $LOCAL_COMMIT = $REMOTE_COMMIT ]
- then
- echoerr "Nothing to push. Accepting such push"
- exit 0
- fi
- unset GIT_WORK_TREE
- if [ ! -d "$OUTPUT_REPO_DIR" ]; then
- echo "Cloning current repo $CURRENT_REPO_DIR to $OUTPUT_REPO_DIR"
- git clone $CURRENT_REPO_DIR $OUTPUT_REPO_DIR
- fi
- pushd $OUTPUT_REPO_DIR
- git reset --hard HEAD # reset any changes
- git fetch
- git checkout $CURRENT_BRANCH
- git reset --hard origin/$CURRENT_BRANCH
- # run the tests with the gradle wrapper
- ./gradlew clean check
- # store the last exit code in a variable
- RESULT=$?
- popd
- # return result as exit code
- exit $RESULT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement