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

MATCH_PATH='chaoscenter/web/'

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 expr "$BRANCH" : 'release\/.*' >/dev/null; then
  echo "\033[0;31;1mYou cannot commit directly to release branch\033[0m"
  exit 1
fi

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