From 7026e529c726648a30af0666088da541245d6422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 27 Oct 2015 20:50:14 +0100 Subject: [PATCH] Fix `realpath` fallback in `rbenv hooks` The symlinks weren't correctly resolved if they were pointing to a single path component, such as `ln -s foo bar`. --- libexec/rbenv-hooks | 9 +++++---- test/hooks.bats | 8 +++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 201c91da..6291e78a 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -35,16 +35,17 @@ resolve_link() { } realpath() { - local cwd="$(pwd)" + local cwd="$PWD" local path="$1" + local name while [ -n "$path" ]; do - cd "${path%/*}" - local name="${path##*/}" + name="${path##*/}" + [ "$name" = "$path" ] || cd "${path%/*}" path="$(resolve_link "$name" || true)" done - echo "$(pwd)/$name" + echo "${PWD}/$name" cd "$cwd" } fi diff --git a/test/hooks.bats b/test/hooks.bats index 0b53d430..99dc4bf0 100644 --- a/test/hooks.bats +++ b/test/hooks.bats @@ -59,7 +59,13 @@ OUT mkdir -p "$HOME" touch "${HOME}/hola.bash" ln -s "../../home/hola.bash" "${path}/exec/hello.bash" + touch "${path}/exec/bright.sh" + ln -s "bright.sh" "${path}/exec/world.bash" RBENV_HOOK_PATH="$path" run rbenv-hooks exec - assert_success "${HOME}/hola.bash" + assert_success + assert_output <