sdkman / sdkman-cli

The SDKMAN! Command Line Interface
https://sdkman.io
Apache License 2.0
5.97k stars 629 forks source link

Bug: Restoring default env breaks when `.sdkmanrc` is gone on folder exit #1241

Open Philzen opened 9 months ago

Philzen commented 9 months ago

Bug report When i cd into a directory with an .sdkmanrc, it fails to restore the defaults when leaving the directory again when the .sdkmanrc file doesn't exist anymore by then (for instance b/c i switched to a git branch where it didn't exist yet).

To reproduce

I'm using sdkman with sdkman_auto_env=true

  1. cd ~/cool-project where cool-project folder currently contains an .sdkmanrc (→ sdkman loads correct i.e. maven & java version)
  2. delete .sdkmanrc
  3. cd..
    → :boom: Could not find /home/user/cool-project/.sdkmanrc.

Now checking sdk current reveals that the default versions have not been restored – the shell still uses the versions that SDKMAN! loaded after entering the cool-project directory.

System info

→ Linux mymachine-user 6.1.53-1-MANJARO #1 SMP PREEMPT_DYNAMIC Wed Sep 13 14:10:57 UTC 2023 x86_64 GNU/Linux
→ GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
→ SDKMAN!  
    script: 5.18.2
    native: 0.4.2
Philzen commented 9 months ago

BTW it would be really nice in this situation to be able to easily load the defaults, maybe using something such as sdk use defaults.

helpermethod commented 9 months ago

Hi @Philzen

The clear mechanism currently

I wonder if the whole restoring defaults mechanism wouldn't be fixed by introducing a global .sdkmanrc file in the $HOME directory, like other tools do.

The env command could then walk up the directory tree until it hits "$HOME" and look in each parent directory for an .sdkmanrc file.

AFAIK other tools like nvm etc. also do it that way.