#!/bin/bash

set -e

if [ -z "$1" ]; then
  BRANCH="master"
else
  BRANCH=$1
fi

echo "Using $BRANCH..."

echo "Checking out mtex2MML"
echo "---------------------"
cd ext/mathematical/mtex2MML
git fetch origin
git checkout $BRANCH && git pull
sha=`git rev-parse HEAD`
cd ../../..
git add ext/mathematical/mtex2MML
if [ -n "$(git status --porcelain)" ]; then
  git commit -m "Update mtex2MML to ${sha}"
fi

echo "Checking out Lasem"
echo "------------------"
cd ext/mathematical/lasem
git fetch origin
git checkout master && git reset --hard origin/master
sha=`git rev-parse HEAD`
cd ../../..
git add ext/mathematical/lasem
git commit -m "Update Lasem to ${sha}"
