asdf-vm / asdf

Extendable version manager with support for Ruby, Node.js, Elixir, Erlang & more
https://asdf-vm.com/
MIT License
22.08k stars 786 forks source link

bug: Incorrect global tool-versions file location parsing when using ASDF_DEFAULT_TOOL_VERSIONS_FILENAME #1301

Closed jmromer closed 2 years ago

jmromer commented 2 years ago

Describe the Bug

Given a customized path for the global tool-versions file, When attempting to change the global version used for a given plugin Then ASDF fails to find the tool-versions file

Steps to Reproduce

  1. Set $ASDF_DEFAULT_TOOL_VERSIONS_FILENAME (e.g. /Users/home/.dotfiles/config/asdf/tool-versions)
  2. Issue asdf global <plugin> <version>
  3. Observe an error message:
asdf global ruby 3.1.2
# /Users/home/.dotfiles/share/asdf-manager/lib/functions/versions.bash: line 67: /Users/home//Users/home/.dotfiles/config/asdf/tool-versions: No such file or directory

Expected Behaviour

The global version of the plugin updated to the requested version

Actual Behaviour

Failure message

Environment

% asdf info
OS:
Darwin home-mac.local 21.5.0 Darwin Kernel Version 21.5.0: Tue Apr 26 21:08:22 PDT 2022; root:xnu-8020.121.3~4/RELEASE_X86_64 x86_64

SHELL:
zsh 5.9 (x86_64-apple-darwin21.3.0)

ASDF VERSION:
v0.10.2

ASDF ENVIRONMENT VARIABLES:
ASDF_DEFAULT_TOOL_VERSIONS_FILENAME=/Users/home/.dotfiles/config/asdf/tool-versions
ASDF_DATA_DIR=/Users/home/.dotfiles/share/asdf-versions
ASDF_DIR=/Users/home/.dotfiles/share/asdf-manager
ASDF_CONFIG_FILE=/Users/home/.dotfiles/config/asdf/config

ASDF INSTALLED PLUGINS:
elixir                       https://github.com/asdf-vm/asdf-elixir.git master d08f506
erlang                       https://github.com/asdf-vm/asdf-erlang.git master 0463971
gohugo                       https://github.com/nklmilojevic/asdf-hugo.git main 1f2df75
golang                       https://github.com/kennyp/asdf-golang.git master cc8bc47
java                         https://github.com/halcyon/asdf-java.git master 9490cdc
mysql                        https://github.com/iroddis/asdf-mysql.git master cdf86f4
nodejs                       https://github.com/asdf-vm/asdf-nodejs.git master 05f99c3
postgres                     https://github.com/smashedtoatoms/asdf-postgres.git master e0cb84c
python                       https://github.com/danhper/asdf-python.git master 57ef777
redis                        https://github.com/smashedtoatoms/asdf-redis.git master bf1276e
ruby                         https://github.com/asdf-vm/asdf-ruby.git master e061b75
rust                         https://github.com/code-lever/asdf-rust.git master 0c88f99
spark                        https://github.com/joshuaballoch/asdf-spark.git master 6fe49de
sqlite                       https://github.com/cLupus/asdf-sqlite.git master 1516e37
tmux                         https://github.com/aphecetche/asdf-tmux.git master eb8deee
yarn                         https://github.com/twuni/asdf-yarn.git main 376c540


### asdf plugins affected (if relevant)

_No response_
jthegedus commented 2 years ago

This isn't a bug. Setting ASDF_DEFAULT_TOOL_VERSIONS_FILENAME is meant to be filename change, not full file path change as you show in your example.

Global .tool-versions is not special from local except it is always $HOME/.tool-versions. Setting ASDF_DEFAULT_TOOL_VERSIONS_FILENAME just changes this to: $HOME/$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME.

From the docs:

ASDF_DEFAULT_TOOL_VERSIONS_FILENAME - The filename of the file storing the tool names and versions. Defaults to .tool-versions. Can be any valid filename. Typically you should not override the default value unless you know you want asdf to ignore .tool-versions files.

asfd global<name> <version> will always try to write to $HOME/$ASDF_DEFAULT_TOOL_VERSIONS_FILENAME.

The reason for this is that versions are resolved by walking up the directory tree from the current, and $HOME is likely in that PATH.

1295 may change this, but it is different from ASDF_DEFAULT_TOOL_VERSIONS_FILENAME