#!/bin/sh
# Libraryan wrapper: no pushes from a Libraryan run, then chain to pre-existing hooks.
if [ "$LIBRARYAN" = 1 ]; then
  echo "libraryan: pushing is not allowed during a Libraryan run" >&2
  exit 1
fi
here=$(cd "$(dirname "$0")" && pwd)
name=pre-push
input=$(cat)  # each chained hook gets the ref lines
[ -n "$input" ] && input="$input
"
extra=$("$here/../bin/libraryan" chainpath 2>/dev/null)
common=$(git rev-parse --git-common-dir)
for h in "$common/hooks/$name" "${extra:+$extra/$name}"; do
  if [ -n "$h" ] && [ -f "$h" ] && [ -x "$h" ]; then
    printf '%s' "$input" | "$h" "$@" || exit 1
  fi
done
exit 0
