#!/bin/sh

#
# Run the hook command.
# Note: this will be replaced by the real command during copy.
#

# Fetch the GIT diff and format it as command input:
DIFF=$(git -c diff.mnemonicprefix=false -c diff.noprefix=false --no-pager diff -r -p -m -M --full-index --no-color --staged | cat)

# Grumphp env vars
$(ENV)
export GRUMPHP_GIT_WORKING_DIR="$(git rev-parse --show-toplevel)"

DDEV_PREFIX="ddev exec --"
COMMAND_PREFIX=""

if [ -z "${IS_DDEV_PROJECT}" ]; then
  COMMAND_PREFIX="${DDEV_PREFIX}"
fi

# Run GrumPHP
(cd "${HOOK_EXEC_PATH}" && printf "%s\n" "${DIFF}" | $COMMAND_PREFIX $(EXEC_GRUMPHP_COMMAND) $(HOOK_COMMAND) '--skip-success-output')
