#!/bin/bash

SRC="./src"
DEST="./dest"


function fail {
  echo "$1"
  exit 1
}


[ -n "$1" ] || fail "Abort: path to mercurial must be given as first argument"
HG="$1"
echo "Using mercurial $HG"


while :
do
  # Get tip revision from DEST
  DEST_TIP=$($HG -R $DEST tip --template '{rev}')
  let "NEXT = $DEST_TIP + 1"

  # Push one changeset
  echo "Pushing revision $NEXT"
  "$HG" -R "$SRC" push -f -r "$NEXT" "$DEST" > /dev/null

  # quick integrity check
  $HG -R $DEST tip > /dev/null || fail "hg tip failed. Broken repository!?!"

  sleep 0.2
done
  
