feat: distinct git:auth-status exit codes for netrc state

The `git:auth-status` command returned `1` both when a host had no `netrc` entry and when it had one that differed, so tooling wanting to tell a credential that would be created apart from one that would be replaced had to issue a second call with no username purely to find out which of the two it was. A host with no entry now exits `1`, a host whose entry differs from what was passed exits `2`, and invalid arguments exit `3`, leaving `0` to mean the stored state already matches. Called without a username the requested state is that no entry exists, so an existing entry is reported as `2` and `1` is never returned. Callers that only test zero versus non-zero are unaffected.
This commit is contained in:
Jose Diaz-Gonzalez committed 2026-09-02 18:07:19 -04:00
1 parent 37e898be58
commit 96521de322
3 files changed
+86 -15

No files matched your search

+10 -5
View File
@@ -108,25 +108,30 @@ cmd-git-auth-status() {
declare desc="reports whether netrc authentication matches the requested state"
local cmd="git:auth-status"
[[ "$1" == "$cmd" ]] && shift 1
local exit_code_missing_entry=1 exit_code_differing_entry=2 exit_code_invalid_arguments=3
declare HOST="$1" USERNAME="$2" PASSWORD="$3"
[[ -z "$HOST" ]] && dokku_log_fail "Please supply a git host"
[[ -z "$HOST" ]] && DOKKU_FAIL_EXIT_CODE="$exit_code_invalid_arguments" dokku_log_fail "Please supply a git host"
PASSWORD="$(fn-git-auth-read-password "$USERNAME" "$PASSWORD")"
if [[ -n "$USERNAME" ]] && [[ -z "$PASSWORD" ]]; then
dokku_log_fail "Missing password for netrc auth entry"
DOKKU_FAIL_EXIT_CODE="$exit_code_invalid_arguments" dokku_log_fail "Missing password for netrc auth entry"
fi
local current
current="$(netrc get "$HOST" 2>/dev/null)" || current=""
if [[ -z "$current" ]]; then
[[ -z "$USERNAME" ]] && return 0
return "$exit_code_missing_entry"
fi
if [[ -z "$USERNAME" ]]; then
[[ -z "$current" ]] && return 0
return 1
return "$exit_code_differing_entry"
fi
[[ "$current" == "${USERNAME}:${PASSWORD}" ]] && return 0
return 1
return "$exit_code_differing_entry"
}
fn-git-auth-read-password() {