Pick credential protocol from the origin URL
http と https で別の認証情報が登録されている場合、https 決め打ちだと push は通るのに API だけ 401 になる。origin の URL に合わせて選ぶ。
This commit is contained in:
+11
-4
@@ -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 <<EOF
|
||||
ERROR: git credential から認証情報を取得できない(host=$HOST)
|
||||
ERROR: git credential から認証情報を取得できない(protocol=$PROTO host=$HOST)
|
||||
この Mac には保存されていません。次の1行で登録できます(トークンは Gitea の
|
||||
設定 → アプリケーション で発行):
|
||||
|
||||
printf 'protocol=https\\nhost=$HOST\\nusername=<ユーザー名>\\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
|
||||
|
||||
Reference in New Issue
Block a user