#!/usr/bin/env bash
set -e

BRANCH=rstudio/v1.5
#
# RStudio fork of GWT started with BRANCH off of GWT 2.8.2 plus our changes.
# That is, started life with:
#
#   git branch rstudio/v1.3 tags/2.8.2
#   git checkout rstudio/v1.3
#   git push --set-upstream origin rstudio/v1.3
#
# RStudio 1.4's GWT source is in rstudio/v1.4 branch.
#
# To take a new release of GWT, merge new tag (e.g. tags/2.9.0) into our branch and rebuild with
# build-gwt (after resolving any merge conflicts). Once successful, be sure to make PR of changes
# to rstudio/gwt as well as to rstudio itself.
#
# To start work on a new release of RStudio, manually create a new branch, e.g. rstudio/v1.6,
# from the desired starting commit (most likely the head of the prior rstudio/v1.x branch),
# and update the BRANCH constant in this script. For example:
#
#   git branch rstudio/v1.6 rstudio/v1.5
#   git checkout rstudio/v1.6
#   git push --set-upstream origin rstudio/1.6
#

# check out our copy of gwt and build tools
if [ ! -d gwt ]; then
    mkdir gwt
fi
cd gwt
if [ ! -d gwt ]; then
    git clone git@github.com:rstudio/gwt.git
    cd gwt
    git remote add upstream https://github.com/gwtproject/gwt
    cd ..
fi
if [ ! -d tools ]; then
    git clone git@github.com:gwtproject/tools.git
fi

cd gwt

if [ "`git status --porcelain`" != "" ]; then
    echo "ERROR: Can't merge, working tree is dirty"
    exit 1
fi

# get latest master from upstream
git fetch upstream
git checkout master
git merge upstream/master

git checkout "${BRANCH}"
git reset --hard "${BRANCH}"
git status
cd ../..

echo Reminder, if you are making changes to GWT sources, use the build-gwt script to rebuild 
echo the GWT jars into the rstudio source tree, and commit those files AND the gwt-source files
echo when done.
