diff --git a/e2e/config/test_hooks_config_root b/e2e/config/test_hooks_config_root new file mode 100644 index 0000000000..80eba323da --- /dev/null +++ b/e2e/config/test_hooks_config_root @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +# Test that config_root in hooks correctly points to the project root +# even when the config file is in a .mise/ subdirectory +# See: https://github.com/jdx/mise/discussions/6531 + +# Create project structure with .mise/config.toml +mkdir -p .mise +cat <.mise/config.toml +[hooks] +enter = 'echo CONFIG_ROOT={{config_root}}' +EOF + +# Initialize mise and go to home first +eval "$(mise hook-env)" + +# Leave the workdir (go home) +cd ~ || exit 1 +eval "$(mise hook-env)" + +# Now re-enter the workdir to trigger the enter hook +cd ~/workdir || exit 1 + +# The config_root should be ~/workdir, not ~/workdir/.mise +assert_contains "mise hook-env 2>&1" "CONFIG_ROOT=$HOME/workdir" +assert_not_contains "mise hook-env 2>&1" "CONFIG_ROOT=$HOME/workdir/.mise" diff --git a/src/config/config_file/mise_toml.rs b/src/config/config_file/mise_toml.rs index e6c522b752..e062752b5b 100644 --- a/src/config/config_file/mise_toml.rs +++ b/src/config/config_file/mise_toml.rs @@ -167,8 +167,10 @@ impl MiseToml { } }; rf.context = BASE_CONTEXT.clone(); - rf.context - .insert("config_root", path.parent().unwrap().to_str().unwrap()); + rf.context.insert( + "config_root", + config_root::config_root(path).to_str().unwrap(), + ); rf.update_context_env(env::PRISTINE_ENV.clone()); rf.path = path.to_path_buf(); let project_root = rf.project_root().map(|p| p.to_path_buf());