From e24027ea572adc7797e6456b7e11df4ecb8c4bde Mon Sep 17 00:00:00 2001 From: Sharon Azriel <150116802+sazriel26@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:20:54 +0200 Subject: [PATCH] Release Candidate 1 --- Library/Homebrew/cmd/update.sh | 32 +++++--------------- Library/Homebrew/utils/url.sh | 53 ++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 25 deletions(-) create mode 100755 Library/Homebrew/utils/url.sh diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 193e59247c..234445adee 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -18,6 +18,7 @@ # HOMEBREW_USER_AGENT_CURL are set by brew.sh # shellcheck disable=SC2154 source "${HOMEBREW_LIBRARY}/Homebrew/utils/lock.sh" +source "${HOMEBREW_LIBRARY}/Homebrew/utils/url.sh" # Replaces the function in Library/Homebrew/brew.sh to cache the Curl/Git executable to # provide speedup when using Curl/Git repeatedly (as update.sh does). @@ -511,15 +512,6 @@ EOS CURL_DISABLE_CURLRC_ARGS=() fi - # HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment. - # shellcheck disable=SC2153 - #if [[ -n "${HOMEBREW_GITHUB_API_TOKEN}" ]] - #then - # CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${HOMEBREW_GITHUB_API_TOKEN}") - #else - # CURL_GITHUB_API_ARGS=() - #fi - # only allow one instance of brew update lock update @@ -637,22 +629,14 @@ EOS # the refspec ensures that the default upstream branch gets updated ( UPSTREAM_REPOSITORY_URL="$(git config remote.origin.url)" - UPSTREAM_REPOSITORY_TOPARSE="${UPSTREAM_REPOSITORY_URL#*://}" - UPSTREAM_REPOSITORY_L1="${UPSTREAM_REPOSITORY_TOPARSE%%/*}" - UPSTREAM_REPOSITORY_DOMAIN="${UPSTREAM_REPOSITORY_L1#*@}" - [[ "${UPSTREAM_REPOSITORY_L1}" == "${UPSTREAM_REPOSITORY_DOMAIN}" ]] \ - && UPSTREAM_REPOSITORY_USERPASS="" \ - || UPSTREAM_REPOSITORY_USERPASS="${UPSTREAM_REPOSITORY_L1%@*}" - [[ -z "${UPSTREAM_REPOSITORY_USERPASS%:*}" ]] || [[ "${UPSTREAM_REPOSITORY_USERPASS%:*}" == "git" ]] \ - && UPSTREAM_REPOSITORY_TOKEN="" \ - || UPSTREAM_REPOSITORY_TOKEN="${UPSTREAM_REPOSITORY_USERPASS#*:}" + UPSTREAM_REPOSITORY_URL_PARSED=( $(url_get "${UPSTREAM_REPOSITORY_URL}" user pass host path) ) # HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment. - # UPSTREAM_REPOSITORY_TOKEN is optionally defined in the git configuration and will try to supersede + # can be supersede by local repository URL # shellcheck disable=SC2153 - if [[ -n "${UPSTREAM_REPOSITORY_TOKEN}" ]] + if [[ -n "${UPSTREAM_REPOSITORY_URL_PARSED[1]}" ]] then - CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${UPSTREAM_REPOSITORY_TOKEN}") + CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${UPSTREAM_REPOSITORY_URL_PARSED[1]}") elif [[ -n "${HOMEBREW_GITHUB_API_TOKEN}" ]] then CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${HOMEBREW_GITHUB_API_TOKEN}") @@ -663,11 +647,9 @@ EOS # HOMEBREW_UPDATE_FORCE and HOMEBREW_UPDATE_AUTO aren't modified here so ignore subshell warning. # shellcheck disable=SC2030 if [[ "${UPSTREAM_REPOSITORY_URL}" == "https://github.com/"* ]] \ - || [[ "${UPSTREAM_REPOSITORY_DOMAIN%:*}" == "github.com" ]] + || [[ "${UPSTREAM_REPOSITORY_URL_PARSED[2]}" == "github.com" ]] then - #UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL#https://github.com/}" - UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_TOPARSE#*/}" - UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY%.git}" + UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL_PARSED[3]%.git}" if [[ "${DIR}" == "${HOMEBREW_REPOSITORY}" && -n "${HOMEBREW_UPDATE_TO_TAG}" ]] then diff --git a/Library/Homebrew/utils/url.sh b/Library/Homebrew/utils/url.sh new file mode 100755 index 0000000000..b794e4ae14 --- /dev/null +++ b/Library/Homebrew/utils/url.sh @@ -0,0 +1,53 @@ +# url_get [key] [key] ... +# where: +# URL ~ [scheme://][user[:pass]@]host[:port][path] +# key is one of the element composing the URL +url_get() { + [[ ${#} -gt 0 ]] || return + + local url="${1}" + [[ -z "${url}" ]] && return + shift + + local _uphpp="${url#*://}" + local _scheme="${url%%://*}" + if [[ "${url}" == "${_uphpp}" ]]; then + _scheme="" + fi + + local _hpp="${_uphpp#*@}" + local _up="${_uphpp%%@*}" + if [[ "${_uphpp}" == "${_hpp}" ]]; then + local _user="" + local _pass="" + else + local _user="${_up%:*}" + local _pass="${_up#*:}" + if [[ "${_user}" == "${_up}" ]]; then + _pass="" + fi + fi + + local _hp="${_hpp%%/*}" + # TODO: split path from arguments (path?arg=...&....) + local _path="${_hpp#*/}" + if [[ "${_hp}" == "${_hpp}" ]]; then + _path="" + elif [[ -z "${_path}" ]]; then + _path="/" + fi + + local _host="${_hp%:*}" + local _port="${_hp#*:}" + if [[ "${_hp}" == "${_host}" ]]; then + _port="" + fi + + while [[ ${#} -gt 0 ]]; do + echo -n "$(eval echo -n "\${_${1}}")" + [[ ${#} -gt 1 ]] && echo -n ${IFS} + shift + done +} + +# EoF