diff --git a/Library/Homebrew/cmd/update.sh b/Library/Homebrew/cmd/update.sh index 7630507e81..a83206aa66 100644 --- a/Library/Homebrew/cmd/update.sh +++ b/Library/Homebrew/cmd/update.sh @@ -18,7 +18,6 @@ # 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). @@ -629,32 +628,25 @@ EOS # the refspec ensures that the default upstream branch gets updated ( UPSTREAM_REPOSITORY_URL="$(git config remote.origin.url)" - eval UPSTREAM_REPOSITORY_URL_PARSED=( $(url_get "${UPSTREAM_REPOSITORY_URL}" user pass host path) ) - if [[ ${#UPSTREAM_REPOSITORY_URL_PARSED[@]} -ne 4 ]]; then - echo "Failed to parse repository URL=${UPSTREAM_REPOSITORY_URL} \!" >&2 - exit - fi - - - # HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment. - # can be superseded a token from the local repository URL - # shellcheck disable=SC2153 - if [[ -n "${UPSTREAM_REPOSITORY_URL_PARSED[1]}" ]] - then - 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}") - else - CURL_GITHUB_API_ARGS=() - fi # 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_URL_PARSED[2]}" == "github.com" ]] + if [[ "${UPSTREAM_REPOSITORY_URL}" =~ https://(([^:@]+)(:([^@]+))?@)?github.com/(.*)$ ]] \ then - UPSTREAM_REPOSITORY="${UPSTREAM_REPOSITORY_URL_PARSED[3]%.git}" + UPSTREAM_REPOSITORY="${BASH_REMATCH[5]%.git}" + # HOMEBREW_GITHUB_API_TOKEN is optionally defined in the user environment. + # can be superseded a token from the local repository URL + # shellcheck disable=SC2153 + if [[ -n "${BASH_REMATCH[4]}" ]] + then + CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${BASH_REMATCH[4]}") + elif [[ -n "${HOMEBREW_GITHUB_API_TOKEN}" ]] + then + CURL_GITHUB_API_ARGS=("--header" "Authorization: token ${HOMEBREW_GITHUB_API_TOKEN}") + else + CURL_GITHUB_API_ARGS=() + fi + if [[ "${DIR}" == "${HOMEBREW_REPOSITORY}" && -n "${HOMEBREW_UPDATE_TO_TAG}" ]] then diff --git a/Library/Homebrew/utils/url.sh b/Library/Homebrew/utils/url.sh deleted file mode 100755 index a877449110..0000000000 --- a/Library/Homebrew/utils/url.sh +++ /dev/null @@ -1,53 +0,0 @@ -# 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