1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-12-18 10:22:00 +00:00

refactor(updater): simplify check for available updates

This commit is contained in:
Marc Cornellà 2021-11-09 19:27:43 +01:00
parent 5c2440cb0c
commit db19589fcf
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -58,23 +58,20 @@ function is_update_available() {
local local_head
local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0
# Get remote HEAD. If we can't get it assume there are updates unless there is no connection:
# - curl: 6 (could not resolve) or 7 (could not connect)
# - wget: 4 (network unreachable)
# - fetch: 1 (no route to host)
local remote_head ret
# Get remote HEAD. If no suitable command is found assume there are updates
# On any other error, skip the update (connection may be down)
local remote_head
remote_head=$(
curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
[[ $? -eq 6 || $? -eq 7 ]] && exit 1
} || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
[[ $? -eq 4 ]] && exit 1
} || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || {
[[ $? -eq 1 ]] && exit 1
} || exit 0
)
# If can't fetch remote HEAD, return exit code
ret=$?; [[ -n "$remote_head" ]] || return $ret
if (( ${+commands[curl]} )); then
curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
elif (( ${+commands[wget]} )); then
wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
elif (( ${+commands[fetch]} )); then
HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null
else
exit 0
fi
) || return 1
# Compare local and remote HEADs
[[ "$local_head" != "$remote_head" ]]