forked from extern/ohmyzsh
refactor(updater): simplify check for available updates
This commit is contained in:
parent
5c2440cb0c
commit
db19589fcf
@ -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" ]]
|
||||
|
Loading…
Reference in New Issue
Block a user