#!/bin/sh

set -e
set -u

merged="";

repo="$(svn info . | sed -n 's|^Repository Root: ||p')";

for revision; do
    revision="${revision#r}"; # Remove leading 'r'

    if ! test "${revision}" -gt 0 2>&1 >/dev/null; then
        echo "Invalid revision: ${revision}";
        exit 1;
    fi;

    previous=$((${revision} - 1));

    echo "Pulling up r${revision}...";
    svn merge "-r${previous}:${revision}" "${repo}/CalendarServer/trunk";

    merged="${merged} r${revision}";
done;

echo svn commit -m \"Pulled up${merged} from trunk.\";
echo svn commit -m \"Pulled up${merged} from trunk.\" | pbcopy;
