Skip to content
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

Merged
merged 2 commits into from May 27, 2022

Conversation

Stratus3D
Copy link
Member

Fixes #1082

Tests are failing for some reason locally and I'm not sure why.

@Stratus3D Stratus3D requested a review from a team as a code owner May 25, 2022 21:02
@Stratus3D Stratus3D requested review from jthegedus and vic May 26, 2022 13:01
if [ "$cmd" = "global" ]; then
file=${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-$HOME/.tool-versions}
Copy link
Member Author

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 a version_file_name helper function.

@@ -174,6 +176,10 @@ get_version_in_dir() {
done
}

version_file_name() {
printf "%s" "${ASDF_DEFAULT_TOOL_VERSIONS_FILENAME:-.tool-versions}"
}
Copy link
Member Author

Choose a reason for hiding this comment

The 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 .tool-versions of course).

@@ -431,7 +437,7 @@ get_plugin_source_url() {
}

find_tool_versions() {
find_file_upwards ".tool-versions"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't necessarily want to just find .tool-versions files, so we use the helper here.

elif [ "$cmd" = "local-tree" ]; then
file=$(find_tool_versions)
else # cmd = local
file="$(pwd)/.tool-versions"
file="$(pwd)/$file_name"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All three of these commands should operate on ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if it is set.


if [ -n "$asdf_version" ]; then
printf "%s\\n" "$asdf_version|$search_path/.tool-versions"
printf "%s\\n" "$asdf_version|$search_path/$file_name"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get_version_in_dir function should also read ASDF_DEFAULT_TOOL_VERSIONS_FILENAME if it is set.

@Stratus3D Stratus3D force-pushed the tb/default-tool-versions-filename-fix branch from ed27d4d to 1276e2f Compare May 26, 2022 13:07
@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"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests were incorrectly setting ASDF_DEFAULT_TOOL_VERSIONS_FILENAME to a file path, but the docs state this must be a file name:

The filename of the file storing the tool names and versions. Defaults to .tool-versions. Can be any valid filename.

https://asdf-vm.com/manage/configuration.html#environment-variables

@Stratus3D
Copy link
Member Author

@vic just wanted to point out that I'm changing unit tests I believe you wrote for the version commands as they didn't use ASDF_DEFAULT_TOOL_VERSIONS_FILENAME correctly and were failing with this fix.

@Stratus3D Stratus3D merged commit 711ad99 into master May 27, 2022
@Stratus3D Stratus3D deleted the tb/default-tool-versions-filename-fix branch May 27, 2022 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: asdf uses .tool-versions instead of configured ASDF_DEFAULT_TOOL_VERSIONS_FILENAME
1 participant