mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-13 17:30:08 +00:00
refactor(updater): simplify check for available updates
This commit is contained in:
parent
5c2440cb0c
commit
db19589fcf
1 changed files with 13 additions and 16 deletions
|
@ -58,23 +58,20 @@ function is_update_available() {
|
||||||
local local_head
|
local local_head
|
||||||
local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0
|
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:
|
# Get remote HEAD. If no suitable command is found assume there are updates
|
||||||
# - curl: 6 (could not resolve) or 7 (could not connect)
|
# On any other error, skip the update (connection may be down)
|
||||||
# - wget: 4 (network unreachable)
|
local remote_head
|
||||||
# - fetch: 1 (no route to host)
|
|
||||||
local remote_head ret
|
|
||||||
remote_head=$(
|
remote_head=$(
|
||||||
curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
|
if (( ${+commands[curl]} )); then
|
||||||
[[ $? -eq 6 || $? -eq 7 ]] && exit 1
|
curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
|
||||||
} || wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null || {
|
elif (( ${+commands[wget]} )); then
|
||||||
[[ $? -eq 4 ]] && exit 1
|
wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
|
||||||
} || HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null || {
|
elif (( ${+commands[fetch]} )); then
|
||||||
[[ $? -eq 1 ]] && exit 1
|
HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null
|
||||||
} || exit 0
|
else
|
||||||
)
|
exit 0
|
||||||
|
fi
|
||||||
# If can't fetch remote HEAD, return exit code
|
) || return 1
|
||||||
ret=$?; [[ -n "$remote_head" ]] || return $ret
|
|
||||||
|
|
||||||
# Compare local and remote HEADs
|
# Compare local and remote HEADs
|
||||||
[[ "$local_head" != "$remote_head" ]]
|
[[ "$local_head" != "$remote_head" ]]
|
||||||
|
|
Loading…
Reference in a new issue