Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Performs verification before code is pushed to git remote repository
  4. #
  5. # To skip the verification, run git push with the --no-verify argument
  6. # i.e. - $ 'git push --no-verify'
  7. #
  8. # Verification is performed in separate directory, thus not affecting current project dir
  9. #
  10.  
  11. echoerr() { echo "$@" 1>&2; }
  12.  
  13. set -e # fail in case of any error
  14.  
  15. CURRENT_REPO_DIR=`pwd`
  16. OUTPUT_REPO_DIR="$CURRENT_REPO_DIR/.verification"
  17. CURRENT_BRANCH=`git rev-parse --abbrev-ref HEAD`
  18.  
  19. git fetch
  20. LOCAL_COMMIT=$(git rev-parse @)
  21. REMOTE_COMMIT=$(git rev-parse @{u})
  22. BASE_COMMIT=$(git merge-base @ @{u})
  23.  
  24. if [ $REMOTE_COMMIT != $BASE_COMMIT ]
  25. then
  26. echoerr "Branch not up-to-date. Please invoke: git pull"
  27. exit 1
  28. fi
  29.  
  30. if [ $LOCAL_COMMIT = $REMOTE_COMMIT ]
  31. then
  32. echoerr "Nothing to push. Accepting such push"
  33. exit 0
  34. fi
  35.  
  36. unset GIT_WORK_TREE
  37.  
  38. if [ ! -d "$OUTPUT_REPO_DIR" ]; then
  39. echo "Cloning current repo $CURRENT_REPO_DIR to $OUTPUT_REPO_DIR"
  40. git clone $CURRENT_REPO_DIR $OUTPUT_REPO_DIR
  41. fi
  42.  
  43. pushd $OUTPUT_REPO_DIR
  44. git reset --hard HEAD # reset any changes
  45. git fetch
  46. git checkout $CURRENT_BRANCH
  47. git reset --hard origin/$CURRENT_BRANCH
  48.  
  49. # run the tests with the gradle wrapper
  50. ./gradlew clean check
  51.  
  52. # store the last exit code in a variable
  53. RESULT=$?
  54.  
  55. popd
  56.  
  57. # return result as exit code
  58. exit $RESULT
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement