Avoid rbenv-exec calling out to rbenv-version-name twice

Running any shim (and thus `rbenv-exec`) would always execute
`rbenv-version-name` twice: once in `rbenv-exec` and another time in
`rbenv-which`, even though RBENV_VERSION variable would have already
been populated at this point.

Now RBENV_VERSION is respected within `rbenv-which`.
This commit is contained in:
Mislav Marohnić 2014-10-13 03:11:12 +02:00
parent 51bd975820
commit 6bb7f07d2d
2 changed files with 14 additions and 1 deletions

View file

@ -48,7 +48,6 @@ remove_from_path() {
echo "${result%:}" echo "${result%:}"
} }
RBENV_VERSION="$(rbenv-version-name)"
RBENV_COMMAND="$1" RBENV_COMMAND="$1"
if [ -z "$RBENV_COMMAND" ]; then if [ -z "$RBENV_COMMAND" ]; then
@ -56,6 +55,8 @@ if [ -z "$RBENV_COMMAND" ]; then
exit 1 exit 1
fi fi
RBENV_VERSION="${RBENV_VERSION:-$(rbenv-version-name)}"
if [ "$RBENV_VERSION" = "system" ]; then if [ "$RBENV_VERSION" = "system" ]; then
PATH="$(remove_from_path "${RBENV_ROOT}/shims")" PATH="$(remove_from_path "${RBENV_ROOT}/shims")"
RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)" RBENV_COMMAND_PATH="$(command -v "$RBENV_COMMAND" || true)"
@ -72,6 +73,9 @@ done
if [ -x "$RBENV_COMMAND_PATH" ]; then if [ -x "$RBENV_COMMAND_PATH" ]; then
echo "$RBENV_COMMAND_PATH" echo "$RBENV_COMMAND_PATH"
elif ! [ -d "${RBENV_ROOT}/versions/${RBENV_VERSION}" ]; then
echo "rbenv: version \`$RBENV_VERSION' is not installed" >&2
exit 1
else else
echo "rbenv: $RBENV_COMMAND: command not found" >&2 echo "rbenv: $RBENV_COMMAND: command not found" >&2

View file

@ -72,3 +72,12 @@ SH
assert_success assert_success
assert_output "HELLO=:hello:ugly:world:again" assert_output "HELLO=:hello:ugly:world:again"
} }
@test "discovers version from rbenv-version-name" {
mkdir -p "$RBENV_ROOT"
cat > "${RBENV_ROOT}/version" <<<"1.8"
create_executable "1.8" "ruby"
RBENV_VERSION= run rbenv-which ruby
assert_success "${RBENV_ROOT}/versions/1.8/bin/ruby"
}