gates / gates (push) Successful in 3m41s
The helper answered any server git asked about. It now reads protocol and host and answers one server. Test: scripts/test_git_credential_sec.py (7 cases; red-proofed, 4 fail against the old helper). Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
39 lines
1.8 KiB
Bash
Executable File
39 lines
1.8 KiB
Bash
Executable File
#!/bin/sh
|
|
# git-credential-sec.sh — git credential helper for CC's clones on DooPlex (Part C, 2026-11-11; R-925).
|
|
#
|
|
# A repository address never holds a credential. Git asks this helper for the password at the moment it needs one,
|
|
# and the helper answers from the environment that the secret store sets for one command:
|
|
#
|
|
# sec run GITEA_GIT_TOKEN -- git push origin main
|
|
#
|
|
# Per clone (no secret in any of the three settings):
|
|
# git config --local credential.helper ""
|
|
# git config --local --add credential.helper /mnt/5_hdd/felhom.eu/git/felhom.eu/scripts/git-credential-sec.sh
|
|
# git config --local credential.username <login>
|
|
#
|
|
# Without `sec run` the helper gives no password and tells git to stop asking (no prompt, no other helper, no
|
|
# clear-text credentials file). A public repository still fetches, because the server asks for nothing.
|
|
# The helper writes the value only to git's pipe: never to a file, the terminal or a log.
|
|
[ "${1:-}" = get ] || exit 0
|
|
# The token goes to ONE server only. Git writes "protocol=" and "host=" lines on the helper's input; for any other
|
|
# server (a submodule, a redirect, a changed address) the helper says nothing and stops git from asking on.
|
|
proto=; host=
|
|
while IFS= read -r line; do
|
|
case "$line" in
|
|
protocol=*) proto=${line#protocol=} ;;
|
|
host=*) host=${line#host=} ;;
|
|
"") break ;;
|
|
esac
|
|
done
|
|
if [ "$proto" != https ] || [ "$host" != gitea.dooplex.hu ]; then
|
|
printf 'git-credential-sec: no credential for this server (only https://gitea.dooplex.hu)\n' >&2
|
|
printf 'quit=true\n'
|
|
exit 0
|
|
fi
|
|
if [ -z "${GITEA_GIT_TOKEN:-}" ]; then
|
|
printf 'git-credential-sec: no token in the environment. Run: sec run GITEA_GIT_TOKEN -- git <command>\n' >&2
|
|
printf 'quit=true\n'
|
|
exit 0
|
|
fi
|
|
printf 'password=%s\n' "$GITEA_GIT_TOKEN"
|