Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions e2e/config/test_hooks_config_root
Original file line number Diff line number Diff line change
@@ -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 <<EOF >.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"
6 changes: 4 additions & 2 deletions src/config/config_file/mise_toml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Loading