Skip to content

Commit 0f0bbef

Browse files
committed
Fix select version when multiple versions available
With the previous version, the following case would fail. It would use python 2.7.15 when running pip instead of version 3.7.2. Shim for `pip` ```bash exec /home/daniel/.asdf/bin/asdf exec "pip" "$@" ``` `.tool-versions`: ``` python 3.7.2 2.7.15 system ```
1 parent 365a294 commit 0f0bbef

2 files changed

Lines changed: 23 additions & 10 deletions

File tree

lib/utils.sh

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -603,24 +603,30 @@ with_shim_executable() {
603603
}
604604

605605
select_version() {
606-
# First, we get the all the plugin/version pairs where the
606+
# First, we get the all the plugins where the
607607
# current shim is available.
608-
# Then, we iterate on these and check if the version of the current
609-
# plugin is the one currently set.
608+
# Then, we iterate on all versions set for each plugin
610609
# Note that multiple plugin versions can be set for a single plugin.
611610
# These are separated by a space. e.g. python 3.7.2 2.7.15
612-
# Therefore, we iterate on all the versions set for the plugin
613-
# and return if we find a version which matches the shim plugin/version pair
611+
# For each plugin/version pair, we check if it is present in the shim
614612
local search_path
615613
search_path=$(pwd)
616614
local shim_versions
617615
IFS=$'\n' read -rd '' -a shim_versions <<< "$(get_shim_versions)"
618616

617+
local plugins
618+
plugins=()
619+
619620
for plugin_and_version in "${shim_versions[@]}"; do
620621
local plugin_name
621622
local plugin_shim_version
622-
IFS=' ' read -r plugin_name plugin_shim_version <<< "$plugin_and_version"
623+
IFS=' ' read -r plugin_name _plugin_shim_version <<< "$plugin_and_version"
624+
if ! [[ " ${plugins[*]} " == *" $plugin_name "* ]]; then
625+
plugins+=("$plugin_name")
626+
fi
627+
done
623628

629+
for plugin_name in "${plugins[@]}"; do
624630
local version_and_path
625631
local version_string
626632
local usable_plugin_versions
@@ -629,10 +635,16 @@ with_shim_executable() {
629635
IFS='|' read -r version_string _path <<< "$version_and_path"
630636
IFS=' ' read -r -a usable_plugin_versions <<< "$version_string"
631637
for plugin_version in "${usable_plugin_versions[@]}"; do
632-
if [ "$plugin_version" = "$plugin_shim_version" ]; then
633-
echo "$plugin_name $plugin_version"
634-
return
635-
fi
638+
for plugin_and_version in "${shim_versions[@]}"; do
639+
local plugin_shim_name
640+
local plugin_shim_version
641+
IFS=' ' read -r plugin_shim_name plugin_shim_version <<< "$plugin_and_version"
642+
if [[ "$plugin_name" = "$plugin_shim_name" ]] &&
643+
[[ "$plugin_version" = "$plugin_shim_version" ]]; then
644+
echo "$plugin_name $plugin_version"
645+
return
646+
fi
647+
done
636648
done
637649
done
638650
}

test/shim_exec.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ teardown() {
114114
}
115115

116116
@test "shim exec should execute first plugin that is installed and set" {
117+
run asdf install dummy 2.0
117118
run asdf install dummy 3.0
118119

119120
echo "dummy 1.0 3.0 2.0" > $PROJECT_DIR/.tool-versions

0 commit comments

Comments
 (0)