Update install.sh

Clean up origin nvm directory before cloning nvm repository, fix #1212
This commit is contained in:
Peter Dave Hello 2016-08-24 23:09:20 +08:00 committed by Peter Dave Hello
parent 31c68adbcf
commit 2b0188582e

View File

@ -75,14 +75,20 @@ install_nvm_from_git() {
exit 1 exit 1
} }
else else
echo "=> Cleanup old nvm dir '$INSTALL_DIR'"
command rm -rf "$INSTALL_DIR/nvm-exec" "$INSTALL_DIR/nvm.sh"
# Cloning to $INSTALL_DIR # Cloning to $INSTALL_DIR
echo "=> Downloading nvm from git to '$INSTALL_DIR'" echo "=> Downloading nvm from git to '$INSTALL_DIR'"
command printf "\r=> " command printf "\r=> "
mkdir -p "$INSTALL_DIR" mkdir -p "$INSTALL_DIR"
command git clone "$(nvm_source)" "$INSTALL_DIR" || { command git init "$INSTALL_DIR"
command git --git-dir="$INSTALL_DIR"/.git remote add origin "$(nvm_source)"
command git --git-dir="$INSTALL_DIR"/.git fetch origin --tags
command git --git-dir="$INSTALL_DIR"/.git pull origin master || {
echo >&2 "Failed to clone nvm repo. Please report this!" echo >&2 "Failed to clone nvm repo. Please report this!"
exit 1 exit 1
} }
command git --git-dir="$INSTALL_DIR"/.git branch --set-upstream-to=origin/master master
fi fi
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout --quiet "$(nvm_latest_version)" command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" checkout --quiet "$(nvm_latest_version)"
if [ ! -z "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then if [ ! -z "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then