Skip to content

Commit

Permalink
added ruby version to upgrade autodetection, closes #797
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Mar 6, 2012
1 parent 3954a22 commit 4f11162
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 61 deletions.
9 changes: 6 additions & 3 deletions help/upgrade
@@ -1,4 +1,3 @@

Usage: Usage:


rvm upgrade [source ruby] [destination ruby] rvm upgrade [source ruby] [destination ruby]
Expand All @@ -15,7 +14,11 @@ Description:


Examples: Examples:


$ rvm upgrade 1.9.2-p136 1.9.2-p180 $ rvm upgrade 1.9.2-p136 1.9.2-p180

$ rvm upgrade ree-2011.01 ree-2011-02


$ rvm upgrade ree-2011.01 ree-2011-02 Experimental detection:


$ rvm upgrade 1.9.2
Are you sure you wish to upgrade from ruby-1.9.2-p290 to ruby-1.9.2-p318? (Y/n):
131 changes: 73 additions & 58 deletions scripts/upgrade
Expand Up @@ -55,101 +55,116 @@ expand_ruby_name()
| awk -F"${rvm_gemset_separator:-"@"}" '{print $1}' | awk -F"${rvm_gemset_separator:-"@"}" '{print $1}'
} }


expand_existing_ruby() existing_ruby_patch()
{ {
typeset prefix ruby_name (
rvm_ruby_string=$1
__rvm_ruby_string


prefix="$(expand_ruby_name "$1" | awk -F'-' '{print $1"-"$2}')" "$rvm_scripts_path/list" strings | grep "^${rvm_ruby_interpreter}-${rvm_ruby_version}-" | tail -n 1
)
}

highest_ruby_patch()
{
typeset patch_level _version
(
rvm_ruby_string=$1
__rvm_ruby_string

patch_level="$(
__rvm_db "${rvm_ruby_interpreter}_${rvm_ruby_version}_patch_level"
)"


while read -r ruby_name _version="$(
do __rvm_db "${rvm_ruby_interpreter}_version"
if [[ "$ruby_name" != "$expanded_destination"* ]] )"

if [[ -n "${patch_level:-""}" ]]
then
case "$rvm_ruby_interpreter" in
ree|kiji|rbx)
# REE, Kiji & Rubinius use dates for their patch levels.
rvm_ruby_patch_level="${patch_level}"
;;
*)
# MRI uses -pN+ to specify the patch level.
rvm_ruby_patch_level="p${patch_level}"
;;
esac

echo ${rvm_ruby_interpreter}-${rvm_ruby_version}-${rvm_ruby_patch_level}
elif [[ -n "${_version:-""}" ]]
then then
echo "$ruby_name" echo ${rvm_ruby_interpreter}-${_version}
return 0 else
echo ${rvm_ruby_interpreter}
fi fi
done < <("$rvm_scripts_path/list" strings | tr ' ' '\n' \ )
| sort -ur | \grep "^$prefix" | \grep -v '-head$' | head -n1)

return 1
} }


upgrade_ruby() upgrade_ruby()
{ {
[[ -n "$expanded_source" ]] || die_with_error "The source ruby was not a valid ruby string."
[[ -n "$expanded_destination" ]] || die_with_error "The destination ruby was not a valid ruby string."


if [[ -z "$source_ruby" ]] ; then if ! confirm \
die_with_error "Unable to find a source ruby. Please manually provide one." "Are you sure you wish to upgrade from $expanded_source to $expanded_destination?"
fi then

expanded_source="$(expand_ruby_name "$source_ruby")"

if [[ -z "$expanded_source" ]] ; then
die_with_error "The source ruby was not a valid ruby string."
fi

if ! confirm "Are you sure you wish to upgrade from $expanded_source to \
$expanded_destination?" ; then
die_with_error "Cancelling upgrade." die_with_error "Cancelling upgrade."
fi fi


if [[ ! -d "$rvm_rubies_path/$expanded_destination" ]]; then if [[ ! -d "$rvm_rubies_path/$expanded_destination" ]]

then
rvm_log "Installing new ruby $expanded_destination" rvm_log "Installing new ruby $expanded_destination"


"${rvm_bin_path}/rvm" install "$expanded_destination" if "${rvm_bin_path}/rvm" install "$expanded_destination"

then
result="$?" true

else
if [[ "$result" -gt 0 ]] ; then die_with_error "Unable to install ruby $expanded_destination. Please install it manually to continue." $?
die_with_error "Unable to install ruby $expanded_destination. \
Please install it manually to continue." "$result"
fi fi

fi fi


rvm_log "Migrating gems from $expanded_source to $expanded_destination" rvm_log "Migrating gems from $expanded_source to $expanded_destination"


"$rvm_scripts_path/migrate" "$expanded_source" "$expanded_destination" "$rvm_scripts_path/migrate" "$expanded_source" "$expanded_destination" || die_with_error "Error migrating gems." "$result"
result="$?"

[[ "$result" -gt 0 ]] && die_with_error "Error migrating gems." "$result"


rvm_log "Upgrade complete!" rvm_log "Upgrade complete!"
} }


args=($*) args=($*)


source_ruby="${args[$__array_start]:-"$(expand_existing_ruby "$destination_ruby")"}" source_ruby="${args[$__array_start]:-}"
args[$__array_start]="" args[$__array_start]=""
args=(${args[@]}) args=(${args[@]})


destination_ruby="${args[$__array_start]}" destination_ruby="${args[$__array_start]:-}"
args[$__array_start]="" args[$__array_start]=""
args=(${args[@]}) args=(${args[@]})


expanded_source="$(existing_ruby_patch "$source_ruby")"


if [[ -z "${source_ruby:-""}" ]] ; then if [[ -n "$source_ruby" && -z "$destination_ruby" ]]
then
highest_source="$(highest_ruby_patch "$(expand_ruby_name "$source_ruby")")"
if [[ "${expanded_source}" != "${highest_source}" ]]
then
destination_ruby="$(expand_ruby_name "$highest_source")"
fi
fi

if [[ -z "$source_ruby" || -z "$destination_ruby" ]]
then
usage >&2 usage >&2
exit 1 exit 1
fi


if [[ "help" == "$source_ruby" ]] ; then elif [[ "help" == "$source_ruby" ]]
then
usage usage
exit 0
fi


expanded_destination="$(expand_ruby_name "$destination_ruby")" else
expanded_destination="$(expand_ruby_name "$destination_ruby")"
upgrade_ruby


if [[ -z "$source_ruby" ]] ; then
die_with_error \
"Source ruby was either not a recognized ruby string or not installed."
fi fi

if [[ -z "$expanded_destination" ]] ; then
die_with_error \
"Destination ruby is not a known ruby string."
fi

upgrade_ruby

exit $?

0 comments on commit 4f11162

Please sign in to comment.