# Sourced by Peppa's bin wrappers: exports .env values without overriding variables that # are already set, so tests (and the runner's per-session env) can point at another DB. # PEP-188: like dotenv, a value wrapped in a pair of quotes ("…" or '…') loses them. _peppa_env="${PEPPA_ROOT:?}/.env" # PEP-209: a git worktree of Peppa (an agent's story copy) has no .env of its own — the main # checkout's is used, else `call.ts update_task` from a worktree can't ask Gitea (no GITEA_TOKEN). # Tests turn it off (`PEPPA_ENV_FALLBACK=off`): the live secrets never reach a test run. if [ ! -f "$_peppa_env" ] && [ -f "$PEPPA_ROOT/.git" ] && [ "${PEPPA_ENV_FALLBACK:-}" != "off" ]; then _peppa_common="$(git -C "$PEPPA_ROOT" rev-parse --path-format=absolute --git-common-dir 2>/dev/null)" [ -n "$_peppa_common" ] && [ -f "${_peppa_common%/.git}/.env" ] && _peppa_env="${_peppa_common%/.git}/.env" unset _peppa_common fi if [ -f "$_peppa_env" ]; then while IFS= read -r _line || [ -n "$_line" ]; do case "$_line" in ''|\#*) continue ;; esac _key="${_line%%=*}" if [ "$_key" != "$_line" ]; then _val="${_line#*=}" case "$_val" in \"?*\") _val="${_val#\"}"; _val="${_val%\"}" ;; \'?*\') _val="${_val#\'}"; _val="${_val%\'}" ;; esac [ -z "${!_key+x}" ] && export "$_key=$_val" else [ -z "${!_key+x}" ] && export "$_line" fi done < "$_peppa_env" fi unset _peppa_env _line _key _val