#!/bin/sh
# gitgud-prereceive — invoked by pre-receive in each bare repo.
#
# Reads `<old> <new> <ref>` lines from stdin and POSTs them to the
# Phoenix node for branch-protection evaluation. If Phoenix says DENY,
# we print the reason on stderr (visible to the pushing client) and
# exit non-zero so git aborts the push.
set -eu
GITGUD_PREHOOK_URL="${GITGUD_PREHOOK_URL:-http://127.0.0.1:4000/_hooks/pre-receive}"
REPO_PATH="${GIT_DIR:-$(pwd)}"
REPO_PATH="$(cd "$REPO_PATH" && pwd)"
STDIN_PAYLOAD="$(cat)"
RESP=$(curl -sf -X POST \
-H "content-type: text/plain" \
-H "x-repo-path: ${REPO_PATH}" \
--data-binary "${STDIN_PAYLOAD}" \
"${GITGUD_PREHOOK_URL}" 2>/dev/null) || {
echo "gitgud: protection backend unreachable; allowing push" >&2
exit 0
}
STATUS=$(printf '%s' "$RESP" | head -n1 | awk '{print $1}')
REASON=$(printf '%s' "$RESP" | tail -n +2)
if [ "$STATUS" = "OK" ]; then
exit 0
fi
echo "gitgud: push denied" >&2
printf '%s\n' "$REASON" >&2
exit 1
neiam /gitgud
Git Gud
public · Issues · Pulls · Labels · Forks · Compare · Actions success · Packages
⭐
Log in to mark this repository.
987 B · text
History
cfa4a8b