Skip to content

Commit

Permalink
[Fix] when originally installed without git, ensure it can be upgrade…
Browse files Browse the repository at this point in the history
…d to use git.

Fixes #1212. Closes #1213.
  • Loading branch information
ljharb committed Aug 25, 2016
1 parent 7e18328 commit 68bf935
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,29 @@ install_nvm_from_git() {
# Cloning to $INSTALL_DIR
echo "=> Downloading nvm from git to '$INSTALL_DIR'"
command printf "\r=> "
mkdir -p "$INSTALL_DIR"
command git clone "$(nvm_source)" "$INSTALL_DIR" || {
echo >&2 "Failed to clone nvm repo. Please report this!"
exit 1
}
mkdir -p "${INSTALL_DIR}"
if [ "$(ls -A "${INSTALL_DIR}")" ]; then
command git init "${INSTALL_DIR}" || {
echo >&2 'Failed to initialize nvm repo. Please report this!'
exit 2
}
command git --git-dir="${INSTALL_DIR}/.git" remote add origin "$(nvm_source)" 2> /dev/null \
|| command git --git-dir="${INSTALL_DIR}/.git" remote set-url origin "$(nvm_source)" || {
echo >&2 'Failed to add remote "origin" (or set the URL). Please report this!'
exit 2
}
command git --git-dir="${INSTALL_DIR}/.git" fetch origin --tags || {
echo >&2 'Failed to fetch origin with tags. Please report this!'
exit 2
}
else
command git clone "$(nvm_source)" "${INSTALL_DIR}" || {
echo >&2 'Failed to clone nvm repo. Please report this!'
exit 2
}
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 -f --quiet "$(nvm_latest_version)"
if [ ! -z "$(command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" show-ref refs/heads/master)" ]; then
if command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet 2>/dev/null; then
command git --git-dir="$INSTALL_DIR"/.git --work-tree="$INSTALL_DIR" branch --quiet -D master >/dev/null 2>&1
Expand Down

0 comments on commit 68bf935

Please sign in to comment.