Skip to content

Commit

Permalink
libexec/rbenv: do not cd for path without dir
Browse files Browse the repository at this point in the history
Without this patch you would see the following error for a symlink like
"/usr/bin/asciidoc -> asciidoc.py":

> …/libexec/{py,rb}env: line 43: cd: asciidoc.py: Not a directory

Ref: sstephenson/bats#224
Ref: pyenv/pyenv#689
Closes: rbenv#868
  • Loading branch information
blueyed committed Jun 24, 2017
1 parent 6cd487d commit 8d1bca0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
20 changes: 13 additions & 7 deletions libexec/rbenv
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,23 @@ else
}

abs_dirname() {
local cwd="$PWD"
local path="$1"

while [ -n "$path" ]; do
cd "${path%/*}"
local name="${path##*/}"
local save_cwd="$PWD"
local dir name

while [[ -n "$path" ]]; do
dir="${path%/*}"
if [[ "$dir" != "$path" ]]; then
cd "$dir"
name="${path##*/}"
else
name="$path"
fi
path="$(resolve_link "$name" || true)"
done

pwd
cd "$cwd"
echo "$PWD"
cd "$save_cwd"
}
fi

Expand Down
9 changes: 9 additions & 0 deletions test/rbenv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,12 @@ load test_helper
run rbenv echo "RBENV_HOOK_PATH"
assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks"
}

@test "abs_dirname with symlink in same dir" {
mkdir -p "$RBENV_TEST_DIR"
cd "$RBENV_TEST_DIR"
ln -s $(which rbenv) rbenv-wrapper
ln -s rbenv-wrapper rbenv-wrapper-link
run ./rbenv-wrapper-link echo "PATH"
assert_success "${BATS_TEST_DIRNAME%/*}/libexec:$PATH"
}

0 comments on commit 8d1bca0

Please sign in to comment.