summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2022-04-02 13:24:35 -0500
committerTuowen Zhao <ztuowen@gmail.com>2022-04-02 13:24:35 -0500
commit2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945 (patch)
tree99add95300f57806b89bd885a5f5322ce9f9ac1a /tools
parentcae9a2b797649379e865e6bd73bc67e294e4ac77 (diff)
parent53863e7b3ff0c2e2816e90dab3d870adebdf49c7 (diff)
downloadzsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.tar.gz
zsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.tar.bz2
zsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'tools')
-rw-r--r--tools/check_for_upgrade.sh29
-rwxr-xr-xtools/install.sh17
-rwxr-xr-xtools/upgrade.sh4
3 files changed, 37 insertions, 13 deletions
diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh
index a36aecb84..d3ad7582c 100644
--- a/tools/check_for_upgrade.sh
+++ b/tools/check_for_upgrade.sh
@@ -36,11 +36,11 @@ function current_epoch() {
function is_update_available() {
local branch
- branch=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master}
+ branch=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master}
local remote remote_url remote_repo
- remote=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
- remote_url=$(cd -q "$ZSH"; git config remote.$remote.url)
+ remote=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
+ remote_url=$(builtin cd -q "$ZSH"; git config remote.$remote.url)
local repo
case "$remote_url" in
@@ -58,25 +58,34 @@ function is_update_available() {
# Get local HEAD. If this fails assume there are updates
local local_head
- local_head=$(cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
+ local_head=$(builtin cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
# 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=$(
if (( ${+commands[curl]} )); then
- curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
+ curl -m 2 -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
+ wget -T 2 -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
+ HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -T 2 -o - $api_url 2>/dev/null
else
exit 0
fi
) || return 1
- # Compare local and remote HEADs
- [[ "$local_head" != "$remote_head" ]]
+ # Compare local and remote HEADs (if they're equal there are no updates)
+ [[ "$local_head" != "$remote_head" ]] || return 1
+
+ # If local and remote HEADs don't match, check if there's a common ancestor
+ # If the merge-base call fails, $remote_head might not be downloaded so assume there are updates
+ local base
+ base=$(builtin cd -q "$ZSH"; git merge-base $local_head $remote_head 2>/dev/null) || return 0
+
+ # If the common ancestor ($base) is not $remote_head,
+ # the local HEAD is older than the remote HEAD
+ [[ $base != $remote_head ]]
}
function update_last_updated_file() {
@@ -161,7 +170,7 @@ function has_typed_input() {
fi
# Test if Oh My Zsh directory is a git repository
- if ! (cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then
+ if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then
echo >&2 "[oh-my-zsh] Can't update: not a git repository."
return
fi
diff --git a/tools/install.sh b/tools/install.sh
index e64e39063..495ad2c11 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -42,13 +42,19 @@ set -e
# $USER is defined by login(1) which is not always executed (e.g. containers)
# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
USER=${USER:-$(id -u -n)}
+# $HOME is defined at the time of login, but it could be unset. If it is unset,
+# a tilde by itself (~) will not be expanded to the current user's home directory.
+# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
+HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
+# macOS does not have getent, but this works even if $HOME is unset
+HOME="${HOME:-$(eval echo ~$USER)}"
# Track if $ZSH was provided
custom_zsh=${ZSH:+yes}
# Default settings
-ZSH=${ZSH:-~/.oh-my-zsh}
+ZSH="${ZSH:-$HOME/.oh-my-zsh}"
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
@@ -268,7 +274,7 @@ setup_ohmyzsh() {
fi
# Manual clone with git config options to support git < v1.7.2
- git init "$ZSH" && cd "$ZSH" \
+ git init --quiet "$ZSH" && cd "$ZSH" \
&& git config core.eol lf \
&& git config core.autocrlf false \
&& git config fsck.zeroPaddedFilemode ignore \
@@ -279,10 +285,15 @@ setup_ohmyzsh() {
&& git remote add origin "$REMOTE" \
&& git fetch --depth=1 origin \
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
- rm -rf "$ZSH"
+ [ ! -d "$ZSH" ] || {
+ cd -
+ rm -rf "$ZSH" 2>/dev/null
+ }
fmt_error "git clone of oh-my-zsh repo failed"
exit 1
}
+ # Exit installation directory
+ cd -
echo
}
diff --git a/tools/upgrade.sh b/tools/upgrade.sh
index b6cb10b5a..afc6a98dd 100755
--- a/tools/upgrade.sh
+++ b/tools/upgrade.sh
@@ -164,6 +164,10 @@ git remote -v | while read remote url extra; do
git@github.com:robbyrussell/oh-my-zsh(|.git))
git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git"
break ;;
+ # Update out-of-date "unauthenticated git protocol on port 9418" to https
+ git://github.com/robbyrussell/oh-my-zsh(|.git))
+ git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
+ break ;;
esac
done