#!/bin/sh

branch_checkout="$3"

if [ $branch_checkout -eq 0 ]; then
  # this is a file checkout
  exit 0
fi

oldrev="$1"
newrev="$2"

if [ $oldrev == $newrev ]; then
  # branch didn't change
  exit 0
fi

current_branch=`git symbolic-ref --short HEAD`
issueno=`echo $current_branch | cut -d- -f2`
number_re='^[0-9]+$'
if [[ $issueno =~ $number_re ]]; then
  exec < /dev/tty
  while true; do
    echo "\nLooks like you're on a branch tracking issue #$issueno."
    read -p "Do you want to start tracking time for this issue? (y/n) " yn
    case $yn in
        [Yy] ) hophop toggl start; break;;
        [Nn] ) exit;;
        * ) echo "Please answer y or n for yes or no.";;
    esac
  done
fi
