#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

declare MATCH_PATH='chaoscenter/web/'

declare BRANCH=$(git rev-parse --abbrev-ref HEAD)

if [[ "$BRANCH" == "main" ]]; then
  echo "\033[0;31;1mYou can't commit directly to main branch\033[0m"
  exit 1
fi

if [[ "$BRANCH" =~ ^release\/.* ]]; then
  echo "\033[0;31;1mYou cannot commit directly to release branch\033[0m"
    exit 1
fi

declare LITMUS_UI_FILE_CHANGES=$(git diff --name-only --cached | grep $MATCH_PATH -c)

echo "\033[0;93mLITMUS_UI_FILE_CHANGES\033[0m ⟶ $LITMUS_UI_FILE_CHANGES"

if [[ $LITMUS_UI_FILE_CHANGES -gt 0 ]]
  then 
    cd ./chaoscenter/web && yarn lint-staged
  else
    echo "\033[0;93mSkipping husky pre-commit hook in $MATCH_PATH folder\033[0m"
fi