From 6c1fb9ffd062ff04607d2e0f486067eaf6e48d1e Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 27 Dec 2012 13:39:36 -0600 Subject: [PATCH 1/3] Fall back to $PWD if a local version file can't be found in $RBENV_DIR --- libexec/rbenv-version-file | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 9b678769..e9451f42 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -2,14 +2,19 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -root="$RBENV_DIR" -while [ -n "$root" ]; do - if [ -e "${root}/.rbenv-version" ]; then - echo "${root}/.rbenv-version" - exit - fi - root="${root%/*}" -done +find_local_version_file() { + local root="$1" + while [ -n "$root" ]; do + if [ -e "${root}/.rbenv-version" ]; then + echo "${root}/.rbenv-version" + exit + fi + root="${root%/*}" + done +} + +find_local_version_file "$RBENV_DIR" +[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD" global_version_file="${RBENV_ROOT}/version" From 283e67b57e8ab0bbbe504aab6866729b0035186a Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Thu, 27 Dec 2012 13:41:55 -0600 Subject: [PATCH 2/3] When the ruby shim is invoked with a script, set RBENV_DIR to the script's dirname --- libexec/rbenv-rehash | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index eebc4d3c..2b5ffecc 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -37,8 +37,25 @@ create_prototype_shim() { cat > "$PROTOTYPE_SHIM_PATH" < Date: Thu, 27 Dec 2012 13:42:25 -0600 Subject: [PATCH 3/3] Ensure outdated shims are removed first when rehashing --- libexec/rbenv-rehash | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-rehash b/libexec/rbenv-rehash index 2b5ffecc..a5c45756 100755 --- a/libexec/rbenv-rehash +++ b/libexec/rbenv-rehash @@ -60,6 +60,18 @@ SH chmod +x "$PROTOTYPE_SHIM_PATH" } +# If the contents of the prototype shim file differ from the contents +# of the first shim in the shims directory, assume rbenv has been +# upgraded and the existing shims need to be removed. +remove_outdated_shims() { + for shim in *; do + if ! diff "$PROTOTYPE_SHIM_PATH" "$shim" >/dev/null 2>&1; then + for shim in *; do rm -f "$shim"; done + fi + break + done +} + # The basename of each argument passed to `make_shims` will be # registered for installation as a shim. In this way, plugins may call # `make_shims` with a glob to register many shims at once. @@ -146,10 +158,11 @@ remove_stale_shims() { # Change to the shims directory. cd "$SHIM_PATH" +shopt -s nullglob # Create the prototype shim, then register shims for all known binaries. create_prototype_shim -shopt -s nullglob +remove_outdated_shims make_shims ../versions/*/bin/* # Restore the previous working directory.