Last active
November 29, 2017 17:25
-
-
Save OndraZizka/99ecd8dbf7d8390de67d5487d833e312 to your computer and use it in GitHub Desktop.
Git + Maven fetch, clean, pull, build, rebase, build and push script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REBASE_ONTO_BRANCH="develop" | |
REBASE_ONTO_REMOTE="upstream" | |
STARTING_COMMIT=$(git rev-parse HEAD) | |
STARTING_BRANCH=(git rev-parse --abbrev-ref HEAD) | |
GO_INTO_CONFLICT=""; | |
if [ "$1" == "force" ] ; then | |
GO_INTO_CONFLICT="true"; | |
fi | |
PUSH_AFTER=""; | |
if [ "$2" == "push" || "$3" == "push" ] ; then | |
PUSH_AFTER="true"; | |
fi | |
TEST_BEFORE_PUSH="-DskipTests"; | |
if [ "$2" == "test" || "$3" == "test" ] ; then | |
TEST_BEFORE_PUSH=""; | |
fi | |
set -e | |
mvn clean; | |
if [ ! `git diff HEAD --exit-code` ] ; then git status; echo -e "\n\n Unclean Git working space. Commit or stash your changes first.\n\n"; fi; | |
git fetch upstream; | |
git checkout $REBASE_ONTO_BRANCH; | |
ORIGINAL_ONTO_BRANCH=$(git rev-parse HEAD) | |
git branch --set-upstream-to=$REBASE_ONTO_REMOTE/$REBASE_ONTO_BRANCH; | |
git pull; | |
mvn install -DskipTests=true; | |
echo -e "\n\n\n\n\n\n\n"; | |
if [ $! != 0 ] ; then echo -e "\n\n The remote updated branch failed to build.\n Originally was at: $ORIGINAL_ONTO_BRANCH\n\n"; exit; fi; | |
git co -; | |
if [ "$GO_INTO_CONFLICT" == "" ] ; then | |
git rebase $REBASE_ONTO_BRANCH || { git rebase --abort && echo -e "\n\n Rebase conflicted, aborted.\n\n" && exit}; | |
else | |
git rebase $REBASE_ONTO_BRANCH || { echo -e "\n\n Rebase caused conflicts. Resolve conflicts and then 'git rebase --continue' ." && exit}; | |
fi | |
mvn clean install $TEST_BEFORE_PUSH || { echo -e "\n\n Maven build after rebase." && exit }; | |
if [ "" != "$PUSH_AFTER" ]; then | |
git push -f '$REBASE_ONTO_REMOTE' '$STARTING_BRANCH' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment