#!/usr/bin/env bash
# Git credential helper: answers for the Peppa Gitea host with peppa-bot's token.
# Enabled per repo (never globally): git config credential.helper peppa
# Logical root (PEP-18): only the bin's own symlink (~/.local/bin) is followed, so a launch
# through ~/peppa/current keeps that path in hooks and git config instead of the release dir.
_b="$0"; [ -L "$_b" ] && { _l="$(readlink "$_b")"; if [ "${_l#/}" != "$_l" ]; then _b="$_l"; else _b="$(dirname "$_b")/$_l"; fi; }
PEPPA_ROOT="$(cd "$(dirname "$_b")/../../.." && pwd)"; unset _b _l
[ "$1" = "get" ] || exit 0
. "$PEPPA_ROOT/scripts/lib/load-env.sh"
want="${GITEA_URL#*://}"; host=""
while IFS='=' read -r k v; do [ -z "$k" ] && break; [ "$k" = host ] && host="$v"; done
[ "$host" = "$want" ] && [ -n "$GITEA_TOKEN" ] || exit 0
echo "username=peppa-bot"
echo "password=$GITEA_TOKEN"
