# shellcheck shell=bash # shellcheck disable=SC2004,SC2034,SC2154 # shared state and arrays are declared in constants.sh # git.sh - Running git for the new project: no prompts, no token on a command line. # # Part of create-project.sh: sourced by it, never run on its own. # # Provides: git_project, fetch_origin # git_project DIR ARGS...: run git in DIR. Prompts are switched off and stdin # is closed (git must not eat the answers meant for later prompts), so a # missing credential or SSH key fails at once instead of waiting for input. git_project() { local dir="$1" shift GIT_TERMINAL_PROMPT=0 GIT_SSH_COMMAND="${GIT_SSH_COMMAND:-ssh} -o BatchMode=yes" \ git -C "$dir" "$@" "$askpass" chmod 700 "$askpass" # Not "cmd; rm": a failed fetch must still be reported to the caller. if ! GIT_ASKPASS="$askpass" REPOFOUNDRY_ASKPASS_USER="${STATE[gitea_login]}" \ REPOFOUNDRY_ASKPASS_TOKEN="${CREDENTIALS[GITEA_TOKEN]}" \ git_project "$dir" fetch -q origin; then rm -f -- "$askpass" return 1 fi rm -f -- "$askpass" }