1.1 KiB · text History cfa4a8b
#!/bin/sh
# gitgud-hook — invoked by post-receive in each bare repo.
#
# Reads `<old> <new> <ref>` lines from stdin and POSTs them to the
# Phoenix node along with the repo path so it can identify which
# Repository row to enqueue cache + workflow jobs against.

set -eu

GITGUD_HOOK_URL="${GITGUD_HOOK_URL:-http://127.0.0.1:4000/_hooks/post-receive}"
REPO_PATH="${GIT_DIR:-$(pwd)}"

# `$(pwd)` resolves to the repo's worktree-less directory in a bare
# repo when the hook runs; we send its absolute path so Phoenix can
# look up the matching repository row.
REPO_PATH="$(cd "$REPO_PATH" && pwd)"

STDIN_PAYLOAD="$(cat)"

# Use --data-binary so we preserve exact bytes (newlines etc).
curl -sf -X POST \
  -H "content-type: text/plain" \
  -H "x-repo-path: ${REPO_PATH}" \
  --data-binary "${STDIN_PAYLOAD}" \
  "${GITGUD_HOOK_URL}" >/dev/null || {
    echo "gitgud-hook: failed to notify ${GITGUD_HOOK_URL}" >&2
    # Don't fail the push if the bridge is briefly unavailable;
    # the user already pushed successfully, we just lost the
    # notification. Server-side reconciliation will catch up.
  }