Skip to content

Git resolver looses custom registry url #15502

Open
@rlejeune74

Description

@rlejeune74

Problem

When depending on custom registries over Git, the URL to the registry is lost, forcing the user to redefine it in its own .cargo/config.toml.
This put the responsibility on the consumer to know about the custom registries of its Git dependencies.
This also allow some "man on the middle" trick by providing another second level dependency by defining same registry name with different URL in the consumer .cargo/config.toml.

Steps

  1. crate-a containing:
$ cat Cargo.toml
[package]
name = "crate-a"
version = "0.1.0"
edition = "2021"

[dependencies]
some-crate = { version = "0.1", registry = "some-registry" }

$ cat .cargo/config.toml
[registries]
some-registry = { index = "ssh://registry.x.com/path/to/some-registry" }
  1. crate-b containing:
$ cat Cargo.toml
[package]
name = "crate-b"
version = "0.1.0"
edition = "2021"

[dependencies]
crate-a = { version = "0.1", git = "https://git.x.com/path/to/crate-a" }

$ cat .cargo/config.toml
cat: .cargo/config.toml: No such file or directory
  1. Compiling crate-b gives the cryptic error:
error: no matching package named `crate-a` found
location searched: https://git.x.com/path/to/crate-a

Possible Solution(s)

One possible solution will be to resolve dependency url using the .cargo/config.toml at the level the dependency is defined.

Notes

If crate-b -> crate-a -> some-crate only involves Git resolver or custom registry there is no issue.
Only happens when Git and Custom registry are mixed.

Version

cargo 1.86.0 (adf9b6ad1 2025-02-28)
release: 1.86.0
commit-hash: adf9b6ad14cfa10ff680d5806741a144f7163698
commit-date: 2025-02-28
host: x86_64-unknown-linux-gnu
libgit2: 1.9.0 (sys:0.20.0 vendored)
libcurl: 8.12.0-DEV (sys:0.4.79+curl-8.12.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Debian 12.0.0 (bookworm) [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-configurationArea: cargo config files and env varsA-gitArea: anything dealing with gitC-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