#!/bin/sh
#husky 0.13.3

command_exists () {
  command -v "$1" >/dev/null 2>&1
}

load_nvm () {
  export $1=$2
  [ -s "$2/nvm.sh" ] && . $2/nvm.sh
  command_exists nvm && [ -f .nvmrc ] && nvm use
}

has_hook_script () {
  [ -f package.json ] && cat package.json | grep -q "\"$1\"[[:space:]]*:"
}

cd .

has_hook_script postreceive || exit 0

export PATH="$PATH:/c/Program Files/nodejs"
command_exists npm || {
  echo >&2 "> husky - Can't find npm in PATH. Skipping postreceive script in package.json"
  exit 0
}

echo
echo "> husky - npm run -s postreceive"
echo

export GIT_PARAMS="$*"
npm run -s postreceive || {
  echo
  echo "> husky - post-receive hook failed (add --no-verify to bypass)"
  echo "> husky - to debug, use 'npm run postreceive'"
  exit 1
}
