Skip to content

nested nonmergeable lists from config cli got merged with file configs #16209

@weihanglo

Description

@weihanglo

Problem

From my observation, this only happens to nested non-mergeable list like registries.*.credential-provider. It doesn't happen to doc.browser (see #16208).

Reproducible example

#[cargo_test]
fn nonmergeable_lists() {
    let cli_arg = "registries.example.credential-provider=['cli', 'cli-arg']";
    let gctx = GlobalContextBuilder::new()
        .config_arg(cli_arg)
        .cwd("foo")
        .build();
    let provider = gctx
        .get::<Option<RegistryConfig>>("registries.example")
        .unwrap()
        .unwrap()
        .credential_provider
        .unwrap();
    assert_eq!(provider.path.raw_value(), "cli");
    assert_eq!(provider.args, ["cli-arg"]);

    // Now create a file-based config
    write_config_at(
        &paths::root().join("foo/.cargo/config.toml"),
        "\
[registries.example]
credential-provider = ['c', 'd']
",
    );

    let gctx = GlobalContextBuilder::new()
        .config_arg(cli_arg)
        .cwd("foo")
        .build();
    let provider = gctx
        .get::<Option<RegistryConfig>>("registries.example")
        .unwrap()
        .unwrap()
        .credential_provider
        .unwrap();
    // This seems wrong and shouldn't merge
    assert_eq!(provider.path.raw_value(), "c");
    assert_eq!(provider.args, ["d", "cli", "cli-arg"]);
}

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

latest master: 0f14d9d

I haven't checked if it was buggy since #15066 or it is a recent regression.

Metadata

Metadata

Assignees

Labels

A-config-cliArea: --config CLI optionA-configurationArea: cargo config files and env varsC-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions