diff --git a/CHANGELOG.md b/CHANGELOG.md index 7331868d..f7699fc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,12 @@ Features * Add documentation about using multiple versions of the same plugin +* Remove post_COMMAND hooks Fixed Bugs * Restore support for legacy file version +* Run executable using `exec` ## 0.7.0 diff --git a/lib/commands/shim-exec.sh b/lib/commands/shim-exec.sh index c646e5ee..9095dc31 100644 --- a/lib/commands/shim-exec.sh +++ b/lib/commands/shim-exec.sh @@ -20,15 +20,10 @@ shim_exec_command() { asdf_run_hook "pre_${plugin_name}_${shim_name}" "${shim_args[@]}" pre_status=$? - if [ "$pre_status" -eq 0 ]; then - "$executable_path" "${shim_args[@]}" - exit_status=$? + if [ "$pre_status" -ne 0 ]; then + return "$pre_status" fi - if [ "${exit_status:-${pre_status}}" -eq 0 ]; then - asdf_run_hook "post_${plugin_name}_${shim_name}" "${shim_args[@]}" - post_status=$? - fi - exit "${post_status:-${exit_status:-${pre_status}}}" + exec "$executable_path" "${shim_args[@]}" } with_shim_executable "$shim_name" exec_shim || exit $? diff --git a/lib/utils.sh b/lib/utils.sh index eea40822..1a42fd38 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -489,49 +489,36 @@ with_plugin_env() { local version="${version_info[0]}" fi - # create a new subshell to keep env - ( + if [ "$version" = "system" ]; then + # execute as is for system + "$callback" + return $? + fi - if [ "$version" = "system" ]; then - # execute as is for system - "$callback" - exit $? - fi + local plugin_path + plugin_path=$(get_plugin_path "$plugin_name") - local plugin_path - plugin_path=$(get_plugin_path "$plugin_name") + # add the plugin listed exec paths to PATH + local path + path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH" - # add the plugin listed exec paths to PATH - local path - path="$(list_plugin_exec_paths "$plugin_name" "$full_version" | tr '\n' ':'):$PATH" + # If no custom exec-env transform, just execute callback + if [ ! -f "${plugin_path}/bin/exec-env" ]; then + PATH=$path "$callback" + return $? + fi - # If no custom exec-env transform, just execute callback - if [ ! -f "${plugin_path}/bin/exec-env" ]; then - PATH=$path "$callback" - exit $? - fi + # Load the plugin custom environment + local install_path + install_path=$(find_install_path "$plugin_name" "$full_version") - # Load the plugin custom environment - local install_path - install_path=$(find_install_path "$plugin_name" "$full_version") - - ASDF_INSTALL_TYPE=$install_type - ASDF_INSTALL_VERSION=$version - ASDF_INSTALL_PATH=$install_path - export ASDF_INSTALL_TYPE - export ASDF_INSTALL_VERSION - export ASDF_INSTALL_PATH - - # shellcheck source=/dev/null + # shellcheck source=/dev/null + ASDF_INSTALL_TYPE=$install_type \ + ASDF_INSTALL_VERSION=$version \ + ASDF_INSTALL_PATH=$install_path \ source "${plugin_path}/bin/exec-env" - unset ASDF_INSTALL_TYPE - unset ASDF_INSTALL_VERSION - unset ASDF_INSTALL_PATH - - PATH=$path "$callback" - exit $? - ) + PATH=$path "$callback" } plugin_executables() { diff --git a/test/shim_exec.bats b/test/shim_exec.bats index 0cfd45c9..a4aa8e9c 100644 --- a/test/shim_exec.bats +++ b/test/shim_exec.bats @@ -406,32 +406,3 @@ EOM [ "$status" -eq 1 ] } -@test "shim exec executes configured post-hook if command was successful" { - run asdf install dummy 1.0 - echo dummy 1.0 > $PROJECT_DIR/.tool-versions - - cat > $HOME/.asdfrc <<-'EOM' -post_dummy_dummy = echo POST $version $1 $2 -EOM - - run $ASDF_DIR/shims/dummy hello world - [ "$status" -eq 0 ] - echo "$output" | grep "This is Dummy 1.0! world hello" - echo "$output" | grep "POST 1.0 hello world" -} - -@test "shim exec does not executes configured post-hook if command failed" { - run asdf install dummy 1.0 - echo dummy 1.0 > $PROJECT_DIR/.tool-versions - - cat > $HOME/.asdfrc <<-'EOM' -post_dummy_dummy = echo POST -EOM - - echo "false" > $ASDF_DIR/installs/dummy/1.0/bin/dummy - chmod +x $ASDF_DIR/installs/dummy/1.0/bin/dummy - - run $ASDF_DIR/shims/dummy hello world - [ "$status" -eq 1 ] - [ "$output" == "" ] -}