Permalink
Browse files

Feature: 'rvm gems copy X Y', thanks to my UnderpantsGnome.

  • Loading branch information...
1 parent 4dbf339 commit e010ad685a8ad4b7afa2cb7fee0d79192b5c6d06 @wayneeseguin wayneeseguin committed Feb 17, 2010
Showing with 36 additions and 2 deletions.
  1. +1 −1 scripts/cli
  2. +30 −1 scripts/gems
  3. +5 −0 scripts/utility
View
@@ -50,7 +50,7 @@ __rvm_parse_args() {
gems|gemset)
rvm_action="gems"
- if [[ "name" = "$1" ]] || [[ "dir" = "$1" ]] || [[ "list" = "$1" ]] || [[ "empty" = "$1" ]] || [[ "dump" = "$1" ]] || [[ "load" = "$1" ]] || [[ "nuke" = "$1" ]] ; then
+ if [[ "name" = "$1" ]] || [[ "dir" = "$1" ]] || [[ "list" = "$1" ]] || [[ "empty" = "$1" ]] || [[ "dump" = "$1" ]] || [[ "load" = "$1" ]] || [[ "nuke" = "$1" ]] || [[ "copy" = "$1" ]] ; then
export rvm_ruby_args="$*" ; export rvm_${1}_flag=1 ; shift
elif [[ "clear" = "$1" ]] ; then
unset rvm_gem_set_name ; shift
View
@@ -86,6 +86,33 @@ __rvm_gems_nuke() {
fi
}
+# Migrate gemsets from ruby X to ruby Y
+__rvm_gems_copy() {
+ source_ruby="$(echo $gem_args | awk '{print $1}')"
+ destination_ruby="$(echo $gem_args | awk '{print $2}')"
+ if [[ -z "$source_ruby" ]] ; then
+ $rvm_scripts_path/log "error" "Source and destination must be specified: 'rvm gems copy X Y'"
+ fi
+ if [[ -z "$destination_ruby" ]] ; then
+ $rvm_scripts_path/log "error" "Source and destination must be specified: 'rvm gems copy X Y'"
+ fi
+ source_path="$($rvm_bin_path/rvm $source_ruby gem env gemdir | tail -n 1)"
+ destination_path="$($rvm_bin_path/rvm $destination_ruby gem env gemdir | tail -n 1)"
+
+ if [[ -d "$source_path" ]] ; then
+ if [[ ! -d "$destination_path" ]] ; then mkdir -p $destination_path ; fi
+ $rvm_scripts_path/log "info" "Copying gemset from $source_ruby to $destination_ruby" ;
+ for dir in bin doc gems specifications ; do
+ cp -Rf $source_path/$dir $destination_path/
+ done
+ else
+ $rvm_scripts_path/log "error" "Gems directory does not exist for $source_path ($source_path)"
+ return 1
+ fi
+
+ unset source_ruby destination_ruby source_path destination_path
+}
+
__rvm_gems_dump() {
rvm_file_name="${rvm_file_name:-$gems_args}"
@@ -285,12 +312,14 @@ if [[ -z "$(which gem 2>/dev/null)" ]] ; then
fi
action="$(echo $* | awk '{print $1}')"
-gems_args="$(echo $* | awk '{$1="" ; print}' | sed 's/^\s*//')"
+gem_args=$(echo "$*" | awk '{$1="" ; print}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [[ "load" = "$action" ]] ; then
__rvm_gems_load
elif [[ "dump" = "$action" ]] ; then
__rvm_gems_dump
+elif [[ "copy" = "$action" ]] ; then
+ __rvm_gems_copy
elif [[ "nuke" = "$action" ]] ; then
__rvm_gems_nuke
elif [[ "delete" = "$action" ]] ; then
View
@@ -469,8 +469,13 @@ __rvm_reboot() {
__rvm_ruby_do() {
__rvm_select
__rvm_use
+
binary="$(echo $rvm_action | sed 's#do$##')"
+
if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then
+ rm -f "$rvm_path/gems/cache"
+ ln -nfs "$HOME/.gem/cache" "$rvm_path/gems/cache"
+
binary="$rvm_ruby_home/bin/$binary"
elif [[ -x "$rvm_ruby_gem_home/bin/$binary" ]] ; then
binary="$rvm_ruby_gem_home/bin/$binary"

0 comments on commit e010ad6

Please sign in to comment.