#! /bin/bash -x

# Run Sphinx to update HTML pages when updates are pushed
# When run, CWD is always $GIT_DIR

umask 0027

if [ "$GIT_DIR" = "." ]; then
	# running as Git hook
	unset GIT_DIR
	cd ..
else
	# running manually
	cd $(git rev-parse --show-toplevel)
fi
git reset --hard $1

REPO_PATH="${PWD#$HOME/}"
TARGET_DIR="/srv/www/gasp/$REPO_PATH"
mkdir -p "$TARGET_DIR"
sphinx-build -b html -d /tmp/gasp/$REPO_PATH . "$TARGET_DIR"
