New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: always use ASDF_DEFAULT_TOOL_VERSIONS_FILENAME for filename when present #1238
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,17 @@ version_command() { | |
shift 2 | ||
local versions=("$@") | ||
|
||
local file_name | ||
local file | ||
|
||
file_name="$(version_file_name)" | ||
|
||
if [ "$cmd" = "global" ]; then | ||
file=${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-$HOME/.tool-versions} | ||
file="$HOME/$file_name" | ||
elif [ "$cmd" = "local-tree" ]; then | ||
file=$(find_tool_versions) | ||
else # cmd = local | ||
file="$(pwd)/.tool-versions" | ||
file="$(pwd)/$file_name" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All three of these commands should operate on |
||
fi | ||
|
||
if [ -L "$file" ]; then | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -156,10 +156,12 @@ get_version_in_dir() { | |
local legacy_filenames=$3 | ||
|
||
local asdf_version | ||
asdf_version=$(parse_asdf_version_file "$search_path/.tool-versions" "$plugin_name") | ||
|
||
file_name=$(version_file_name) | ||
asdf_version=$(parse_asdf_version_file "$search_path/$file_name" "$plugin_name") | ||
|
||
if [ -n "$asdf_version" ]; then | ||
printf "%s\\n" "$asdf_version|$search_path/.tool-versions" | ||
printf "%s\\n" "$asdf_version|$search_path/$file_name" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This |
||
return 0 | ||
fi | ||
|
||
|
@@ -174,6 +176,10 @@ get_version_in_dir() { | |
done | ||
} | ||
|
||
version_file_name() { | ||
printf "%s" "${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-.tool-versions}" | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helper function encapsulates the version file logic and prints the correct version file name. Note that this has nothing to do with legacy version files. This is only for asdf version files (default of |
||
|
||
find_versions() { | ||
local plugin_name=$1 | ||
local search_path=$2 | ||
|
@@ -431,7 +437,7 @@ get_plugin_source_url() { | |
} | ||
|
||
find_tool_versions() { | ||
find_file_upwards ".tool-versions" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't necessarily want to just find |
||
find_file_upwards "$(version_file_name)" | ||
} | ||
|
||
find_file_upwards() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,21 +249,41 @@ teardown() { | |
[ "$(cat $HOME/.tool-versions)" = "dummy path:$PROJECT_DIR/local" ] | ||
} | ||
|
||
@test "local should write to ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" { | ||
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="local-tool-versions" | ||
run asdf local "dummy" "1.1.0" | ||
[ "$status" -eq 0 ] | ||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] | ||
[ "$(cat .tool-versions)" = "" ] | ||
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME | ||
} | ||
|
||
@test "local should overwrite contents of ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" { | ||
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="local-tool-versions" | ||
echo 'dummy 1.0.0' >> "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" | ||
run asdf local "dummy" "1.1.0" | ||
[ "$status" -eq 0 ] | ||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] | ||
[ "$(cat .tool-versions)" = "" ] | ||
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME | ||
} | ||
|
||
|
||
@test "global should write to ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" { | ||
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions" | ||
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="global-tool-versions" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests were incorrectly setting
https://asdf-vm.com/manage/configuration.html#environment-variables |
||
run asdf global "dummy" "1.1.0" | ||
[ "$status" -eq 0 ] | ||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] | ||
[ "$(cat $HOME/$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] | ||
[ "$(cat $HOME/.tool-versions)" = "" ] | ||
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME | ||
} | ||
|
||
@test "global should overwrite contents of ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if set" { | ||
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="$PROJECT_DIR/global-tool-versions" | ||
export ASDF_DEFAULT_TOOL_VERSIONS_FILENAME="global-tool-versions" | ||
echo 'dummy 1.0.0' >> "$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME" | ||
run asdf global "dummy" "1.1.0" | ||
[ "$status" -eq 0 ] | ||
[ "$(cat $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] | ||
[ "$(cat $HOME/$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME)" = "dummy 1.1.0" ] | ||
[ "$(cat $HOME/.tool-versions)" = "" ] | ||
unset ASDF_DEFAULT_TOOL_VERSIONS_FILENAME | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than having this "if custom file name use it, else use
.tool-versions
" logic spread around through the code, I have introduced aversion_file_name
helper function.