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: regression with env overriding #4421

Merged
merged 1 commit into from
Feb 16, 2025
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
9 changes: 9 additions & 0 deletions e2e/env/test_env_profiles
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

echo 'env.AAA = "main"' >.mise.toml
echo 'env.AAA = "override-1"' >mise.override1.toml
echo 'env.AAA = "override-2"' >mise.override2.toml

assert "mise env --json | jq -r .AAA" "main"
MISE_ENV=override1 assert "mise env --json | jq -r .AAA" "override-1"
MISE_ENV=override1,override2 assert "mise env --json | jq -r .AAA" "override-2"
6 changes: 3 additions & 3 deletions e2e/tools/test_path_order
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

cat <<EOF >mise.toml
[env]
_.path = ["bin"]
_.path = ["bin", "bin2"]
[tools]
dummy = "1.0.0"
jq = "1.7.1"
Expand All @@ -11,7 +11,7 @@ EOF
mkdir bin subdir subdir/bin
cat <<EOF >subdir/mise.toml
[env]
_.path = ["bin"]
_.path = ["bin", "bin2"]
[tools]
dummy = "2.0.0"
pitchfork = "0.1.5"
Expand All @@ -24,4 +24,4 @@ assert "mise bin-paths" "$MISE_DATA_DIR/installs/dummy/2.0.0/bin
$MISE_DATA_DIR/installs/pitchfork/0.1.5
$MISE_DATA_DIR/installs/jq/1.7.1"

assert "mise env | grep PATH" "export PATH='$HOME/workdir/subdir/bin:$HOME/workdir/bin:$MISE_DATA_DIR/installs/dummy/2.0.0/bin:$MISE_DATA_DIR/installs/pitchfork/0.1.5:$MISE_DATA_DIR/installs/jq/1.7.1:$PATH'"
assert "mise env | grep PATH" "export PATH='$HOME/workdir/subdir/bin:$HOME/workdir/subdir/bin2:$HOME/workdir/bin:$HOME/workdir/bin2:$MISE_DATA_DIR/installs/dummy/2.0.0/bin:$MISE_DATA_DIR/installs/pitchfork/0.1.5:$MISE_DATA_DIR/installs/jq/1.7.1:$PATH'"
15 changes: 11 additions & 4 deletions src/config/env_directive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::path_env::PathEnv;
use crate::tera::{get_tera, tera_exec};
use eyre::{eyre, Context};
use indexmap::IndexMap;
use itertools::Itertools;
use serde_json::Value;
use std::cmp::PartialEq;
use std::collections::{BTreeSet, HashMap};
Expand Down Expand Up @@ -335,18 +336,24 @@ impl EnvResults {
}
// trace!("resolve: paths: {:#?}", &paths);
// trace!("resolve: ctx.env: {:#?}", &ctx.get("env"));
for (p, source) in paths {
// trace!("resolve: entry: {:?}, source: {}", &entry, display_path(source));
for (source, paths) in &paths.iter().chunk_by(|(_, source)| source) {
let config_root = source
.parent()
.map(Path::to_path_buf)
.or_else(|| dirs::CWD.clone())
.unwrap_or_default();
env::split_paths(&p)
let paths = paths.map(|(p, _)| p).collect_vec();
let paths = paths
.iter()
.rev()
.flat_map(|path| env::split_paths(path))
.map(|s| normalize_path(&config_root, s))
.for_each(|p| r.env_paths.push(p.clone()));
.collect::<Vec<_>>();
r.env_paths.extend(paths);
}

r.env_paths.reverse();

Ok(r)
}

Expand Down
6 changes: 3 additions & 3 deletions src/config/env_directive/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ mod tests {
results.env_paths.into_iter().map(|p| replace_path(&p.display().to_string())).collect::<Vec<_>>(),
@r#"
[
"/path/1",
"/path/2",
"~/foo/1",
"~/cwd/rel/1",
"~/cwd/rel2/2",
"~/cwd/rel/1",
"/path/1",
"/path/2",
]
"#
);
Expand Down
1 change: 1 addition & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ impl Config {
let entries = self
.config_files
.iter()
.rev()
.map(|(source, cf)| {
cf.env_entries()
.map(|ee| ee.into_iter().map(|e| (e, source.clone())))
Expand Down
Loading