Skip to content

Commit aa9d3e4

Browse files
committed
fix(config): non-mergeable list from cli should take priority
Before, config value from environment variable won over those from `--config` CLI for non-mergeable list This was an oversight when implementing non-mergeable list.
1 parent e0aa8fc commit aa9d3e4

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/cargo/util/context/mod.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,11 +1039,29 @@ impl GlobalContext {
10391039
return Ok(());
10401040
};
10411041

1042+
let env_def = Definition::Environment(key.as_env_key().to_string());
1043+
10421044
if is_nonmergeable_list(&key) {
1043-
output.clear();
1045+
assert!(
1046+
output
1047+
.windows(2)
1048+
.all(|cvs| cvs[0].definition() == cvs[1].definition()),
1049+
"non-mergeable list must have only one definition: {output:?}",
1050+
);
1051+
1052+
// Keep existing config if higher priority than env (e.g., --config CLI),
1053+
// otherwise clear for env
1054+
if output
1055+
.first()
1056+
.map(|o| o.definition() > &env_def)
1057+
.unwrap_or_default()
1058+
{
1059+
return Ok(());
1060+
} else {
1061+
output.clear();
1062+
}
10441063
}
10451064

1046-
let env_def = Definition::Environment(key.as_env_key().to_string());
10471065
if self.cli_unstable().advanced_env && env_val.starts_with('[') && env_val.ends_with(']') {
10481066
// Parse an environment string as a TOML array.
10491067
let toml_v = env_val.parse::<toml::Value>().map_err(|e| {

tests/testsuite/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,8 +2252,8 @@ credential-provider = ['c', 'd']
22522252
.credential_provider
22532253
.unwrap();
22542254
// expect: no merge happens; cli takes precedence over files and env
2255-
assert_eq!(provider.path.raw_value(), "env");
2256-
assert_eq!(provider.args, ["env-arg"]);
2255+
assert_eq!(provider.path.raw_value(), "cli");
2256+
assert_eq!(provider.args, ["cli-arg"]);
22572257
}
22582258

22592259
#[cargo_test]

0 commit comments

Comments
 (0)