#!/bin/sh

# git will redirect hooks output to stderr
# but pre-push output is not redirected to stderr so we need 1>&2
set -u

exit_code=0

HOOKNAME=`basename "$0"`
HOOK="$GKC_HOOKS_REAL_PATH/$HOOKNAME"

if [ -f $HOOK ]; then
  if [ -x $HOOK ]; then
    echo "_GKC_HOOK_BEGIN_${HOOKNAME}_" 1>&2
    "$HOOK" "$@" 1>&2
    exit_code=$?
    echo "_GKC_HOOK_END_${HOOKNAME}_" 1>&2
  else
    # exit_code 644644 (HOOKS_NO_EXEC_PERMISSION) means no executable hook
    exit_code=644644
  fi
  echo "_GKC_HOOKNAME_${HOOKNAME}_EXIT_CODE_${exit_code}_GKC_END_" 1>&2
fi
exit $exit_code
