mirror of
https://github.com/asdf-vm/asdf.git
synced 2024-11-15 01:28:17 -07:00
Determine version from global setting when project is outside home.
Without this patch, asft was not able to determine the tool version for a project located outside the user's HOME directory. ``` /work/project/ /home/me/.tool-versions ``` This changeset lets asdf find the global version stored at $HOME/.tool-versions when the directory traversal from the project dir was not able to find a suitable version.
This commit is contained in:
parent
c96fae79a4
commit
42f57d0074
41
lib/utils.sh
41
lib/utils.sh
@ -56,6 +56,28 @@ display_error() {
|
|||||||
echo >&2 $1
|
echo >&2 $1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_version_in_dir() {
|
||||||
|
local plugin_name=$1
|
||||||
|
local search_path=$2
|
||||||
|
local legacy_filenames=$3
|
||||||
|
|
||||||
|
local asdf_version=$(parse_asdf_version_file "$search_path/.tool-versions" $plugin_name)
|
||||||
|
|
||||||
|
if [ -n "$asdf_version" ]; then
|
||||||
|
echo "$asdf_version:$search_path/.tool-versions"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
for filename in $legacy_filenames; do
|
||||||
|
local legacy_version=$(parse_legacy_version_file "$search_path/$filename" $plugin_name)
|
||||||
|
|
||||||
|
if [ -n "$legacy_version" ]; then
|
||||||
|
echo "$legacy_version:$search_path/$filename"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
find_version() {
|
find_version() {
|
||||||
local plugin_name=$1
|
local plugin_name=$1
|
||||||
local search_path=$2
|
local search_path=$2
|
||||||
@ -70,24 +92,15 @@ find_version() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
while [ "$search_path" != "/" ]; do
|
while [ "$search_path" != "/" ]; do
|
||||||
local asdf_version=$(parse_asdf_version_file "$search_path/.tool-versions" $plugin_name)
|
local version=$(get_version_in_dir "$plugin_name" "$search_path" "$legacy_filenames")
|
||||||
|
if [ -n "$version" ]; then
|
||||||
if [ -n "$asdf_version" ]; then
|
echo "$version"
|
||||||
echo "$asdf_version:$search_path/.tool-versions"
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for filename in $legacy_filenames; do
|
|
||||||
local legacy_version=$(parse_legacy_version_file "$search_path/$filename" $plugin_name)
|
|
||||||
|
|
||||||
if [ -n "$legacy_version" ]; then
|
|
||||||
echo "$legacy_version:$search_path/$filename"
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
search_path=$(dirname "$search_path")
|
search_path=$(dirname "$search_path")
|
||||||
done
|
done
|
||||||
|
|
||||||
|
get_version_in_dir "$plugin_name" "$HOME" "$legacy_filenames"
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_asdf_version_file() {
|
parse_asdf_version_file() {
|
||||||
|
@ -92,3 +92,12 @@ teardown() {
|
|||||||
[ "$status" -eq 0 ]
|
[ "$status" -eq 0 ]
|
||||||
[ "$output" = "0.2.0" ]
|
[ "$output" = "0.2.0" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "get_preset_version_for returns the global version from home when project is outside of home" {
|
||||||
|
echo "dummy 0.1.0" > $HOME/.tool-versions
|
||||||
|
PROJECT_DIR=$BASE_DIR/project
|
||||||
|
mkdir -p $PROJECT_DIR
|
||||||
|
run get_preset_version_for "dummy"
|
||||||
|
[ "$status" -eq 0 ]
|
||||||
|
[ "$output" = "0.1.0" ]
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user