#!/bin/sh

REPO=$1

cd ~/repos/$REPO.git

REVS=`git show-branch | perl -nle 'm/^\[([^\]]*)\]/; print $1'`

TAGS=`git tag --sort=-taggerdate | head -n 5 | head -c -1 | tr '\n' ','`
if [ -n "$TAGS" ]; then
  REVS=$REVS,$TAGS
fi

if [ -n "$2" ]; then
  REVS=$REVS,$2
fi

echo $REVS

pgit \
  -repo . \
  -clone-url https://serve.example.com/$REPO.git \
  -root-relative /$REPO/ \
  -revs $REVS \
  -out /var/lib/wwwroot/$REPO