blob: 84684d1f39e0fbba342b9579cd87d47789872858 [file] [log] [blame]
LOCAL_BRANCH=$1
BUILD_FROM_TAG=$2
REMOTE_BRANCH=$3
FALLBACK_BRANCH=$4
ROOT_PATH=$5
SCOUT_SUBMODULE=0
CHECKOUT_SUCCESSFUL=0
isScoutSubmodule(){
SCOUT_SUBMODULE=0
if [ ! -z $(pwd | grep $ROOT_PATH/org.eclipse.scout) ]; then
SCOUT_SUBMODULE=1
fi
}
buildFromTag(){
local tag=$1
local localbranch=$1
local remotebranch=$2
git fetch --tags
git show-ref --tags --verify --quiet refs/tags/$tag
if [ $? -eq 0 ]; then
git checkout $tag
else
checkoutLocalOrRemoteBranch $localbranch $remotebranch
fi
}
checkoutLocalBranch(){
local localbranch=$1
local remotebranch=$2
CHECKOUT_SUCCESSFUL=0
if [ ! -z "$(git branch | grep $localbranch)" ]; then
git checkout $localbranch
git pull origin $remotebranch
CHECKOUT_SUCCESSFUL=1
fi
}
checkoutRemoteBranch(){
local localbranch=$1
local remotebranch=$2
CHECKOUT_SUCCESSFUL=0
if [ ! -z "$(git branch -r | grep origin/$remotebranch)" ]; then
git checkout -b $localbranch origin/$remotebranch
git pull origin $remotebranch
CHECKOUT_SUCCESSFUL=1
fi
}
checkoutLocalOrRemoteBranch(){
local localbranch=$1
local remotebranch=$2
CHECKOUT_SUCCESSFUL=0
checkoutLocalBranch $localbranch $remotebranch
if [ $CHECKOUT_SUCCESSFUL -eq 0 ]; then
checkoutRemoteBranch $localbranch $remotebranch
fi
}
git rm --cached -r . > /dev/null
git reset --hard > /dev/null
isScoutSubmodule
if [ $SCOUT_SUBMODULE -eq 1 ]; then
if echo $BUILD_FROM_TAG | grep -q -w "true"; then
buildFromTag $LOCAL_BRANCH $REMOTE_BRANCH
else
checkoutLocalOrRemoteBranch $LOCAL_BRANCH $REMOTE_BRANCH
fi
else
checkoutLocalOrRemoteBranch $FALLBACK_BRANCH $FALLBACK_BRANCH
fi