summaryrefslogtreecommitdiff
path: root/tools/check_for_upgrade.sh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2021-12-18 17:46:06 -0600
committerTuowen Zhao <ztuowen@gmail.com>2021-12-18 17:46:06 -0600
commit1bc186dabe12b3d01b2257e82f3a104c48b8b3c7 (patch)
tree54576312318c406b6ce2a35423198fcc92c8bf71 /tools/check_for_upgrade.sh
parent2a977876c6e85847652f097cc128e4ed5bec147a (diff)
parent904f8685f75ff5dd3f544f8c6f2cabb8e5952e9a (diff)
downloadzsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.gz
zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.tar.bz2
zsh-1bc186dabe12b3d01b2257e82f3a104c48b8b3c7.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'tools/check_for_upgrade.sh')
-rw-r--r--tools/check_for_upgrade.sh46
1 files changed, 25 insertions, 21 deletions
diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
index 8264762b6..293f48edf 100644
--- a/tools/check_for_upgrade.sh
+++ b/tools/check_for_upgrade.sh
@@ -34,11 +34,11 @@ function current_epoch() {
function is_update_available() {
local branch
- branch=${"$(git -C "$ZSH" config --local oh-my-zsh.branch)":-master}
+ branch=${"$(cd "$ZSH"; git config --local oh-my-zsh.branch)":-master}
local remote remote_url remote_repo
- remote=${"$(git -C "$ZSH" config --local oh-my-zsh.remote)":-origin}
- remote_url=$(git -C "$ZSH" config remote.$remote.url)
+ remote=${"$(cd "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
+ remote_url=$(cd "$ZSH"; git config remote.$remote.url)
local repo
case "$remote_url" in
@@ -56,25 +56,22 @@ function is_update_available() {
# Get local HEAD. If this fails assume there are updates
local local_head
- local_head=$(git -C "$ZSH" rev-parse $branch 2>/dev/null) || return 0
+ local_head=$(cd "$ZSH"; git 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" ]]
@@ -136,6 +133,12 @@ function update_ohmyzsh() {
return
fi
+ # Test if Oh My Zsh directory is a git repository
+ if ! (cd "$ZSH" && LANG= git rev-parse &>/dev/null); then
+ echo >&2 "[oh-my-zsh] Can't update: not a git repository."
+ return
+ fi
+
# Check if there are updates available before proceeding
if ! is_update_available; then
return
@@ -157,7 +160,8 @@ function update_ohmyzsh() {
[[ "$option" != $'\n' ]] && echo
case "$option" in
[yY$'\n']) update_ohmyzsh ;;
- [nN]) update_last_updated_file ;;
+ [nN]) update_last_updated_file ;&
+ *) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
esac
fi
}