#!/bin/bash
REPO_NAME=$(basename `git rev-parse --show-toplevel`)
DEFAULT_BRANCH='latest'

if [[ $(pwd) =~ .+$REPO_NAME ]]; then
  # cd to application route directory this allows the commiting/pushing from any part of the application
  cd ${BASH_REMATCH}

  CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)

  # if the current branch is latest
  if [[ $CURRENT_BRANCH == $DEFAULT_BRANCH ]]; then
    # set the console output to red
    tput setaf 1
    echo "Stop trying to push to $DEFAULT_BRANCH"
    echo "If a push to $DEFAULT_BRANCH is essential add the flag '--no-verify'. EG: 'git push --no-verify'"
    # reset the console output colour
    tput sgr0
    exit 1
  fi
fi
