#!/bin/bash

commit=$1

if [ -z "$commit" ]; then
    echo -n "Promote the current commit to live? [y/N] "
else
    echo -n "Promote commit $commit to live? [y/N] "
fi
read -n 1 answer
echo

if [ "$answer" == "y" -o "$answer" == "Y" ]; then
    echo "Promoting"
    prev=PrevLive;
    live=Live; 

    # Tag the previous live
    git tag -d $prev; 
    git push origin :refs/tags/$prev; 
    git tag $prev $live; 
    git push --tags

    # Tag the new live
    git tag -d $live; 
    git push origin :refs/tags/$live; 
    git tag $live $commit; 
    git push --tags

    # Notes to user
    echo
    echo "Check the above for errors.  If all went well Live is now updated and PrevLive holds the previous Live commit"
else
    echo "Promotion aborted"
fi

