From 88d883443557aaf717b09f7c8a0bb0b4522766e1 Mon Sep 17 00:00:00 2001 From: yoshikazu Date: Mon, 27 Jul 2026 22:54:13 +0000 Subject: [PATCH] Pick credential protocol from the origin URL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit http と https で別の認証情報が登録されている場合、https 決め打ちだと push は通るのに API だけ 401 になる。origin の URL に合わせて選ぶ。 --- tools/release-update.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tools/release-update.sh b/tools/release-update.sh index f91cf20..d42266d 100644 --- a/tools/release-update.sh +++ b/tools/release-update.sh @@ -42,17 +42,24 @@ echo "asset: $ASSET_REL ($(stat -f %z "$ASSET") bytes)" # 0) 先に認証情報を取り出す。ここで落ちるなら push もアップロードもできないので、 # タグを動かす前に止めたほうが状態がきれいなまま済む。 # 認証情報は argv に載せず環境変数で渡す(プロセス一覧への漏洩回避)。 -creds=$(printf 'protocol=https\nhost=%s\n\n' "$HOST" | git credential fill 2>/dev/null || true) -[ -n "$creds" ] || creds=$(printf 'protocol=http\nhost=%s\n\n' "$HOST" | git credential fill 2>/dev/null || true) +# +# プロトコルは origin の URL から決める。http と https で別のエントリが登録されて +# いることがあり、決め打ちすると push は通るのに API だけ 401 になる。 +case "$(git remote get-url origin 2>/dev/null)" in + https://*) PROTO="https" ;; + http://*) PROTO="http" ;; + *) PROTO="https" ;; +esac +creds=$(printf 'protocol=%s\nhost=%s\n\n' "$PROTO" "$HOST" | git credential fill 2>/dev/null || true) GITEA_USER=$(printf '%s\n' "$creds" | sed -n 's/^username=//p') GITEA_PASS=$(printf '%s\n' "$creds" | sed -n 's/^password=//p') [ -n "$GITEA_USER" ] && [ -n "$GITEA_PASS" ] || { cat >&2 <\\npassword=<トークン>\\n\\n' | git credential approve + printf 'protocol=$PROTO\\nhost=$HOST\\nusername=<ユーザー名>\\npassword=<トークン>\\n\\n' | git credential approve osxkeychain ヘルパが未設定なら先に: git config --global credential.helper osxkeychain EOF