Skip to content

SCP-like submodule URLs converted to ssh:// may change path semantics #16740

@weihanglo

Description

@weihanglo

Problem

Re-posted #16727 (review) here in case I don't have time to fix it.

PR #16727 fixed a regression from #16246 (1.94.0) where submodules using SCP-like URLs in .gitmodules caused cargo fetch to fail with:

invalid url `[email protected]:user/repo.git`: relative URL without a base

The fix converts SCP-like URLs to ssh:// format before passing them to Url::parse.
However, the two URL forms have different path semantics:

  • In SCP-like git@host:path/repo.git, path is relative to the user's home directory (~git/path/repo.git)
  • In SSH ssh://git@host/path/repo.git, path is absolute from root (/path/repo.git)

For like GitHub and GitLab, this doesn't really matter as they intercept the path and resolve it. But for a self-hosted git server this might be an issue after the conversion.

Steps

(In theory. I haven't yet tried)

  1. Set up a self-hosted git server where repos are at ~<user>/repos/foo.git (under your home directory)
  2. Create a git dependency with .gitmodules containing:
    [submodule "sub"]
        path = sub
        url = <user>@<host>:repos/foo.git
  3. Run cargo fetch
  4. Observer that Cargo converts the URL to ssh://<user>@<host>/repos/foo.git, which the path is absolute /repos/foo.git instead of the correct relative path ~<user>/repos/foo.git

Possible Solution(s)

Changing SourceId to support SCP-like URLs would be overkill for fixing a regression. That would be a feature request for the manifest in terms of general SCP-like URL support, which is tracked in #1851

We should focus on fixing submodule fetch failure first.

We could probably store the original URL alongside the converted one in GitSource, and use the original URL to when invoking the actual fetch. (sounds bad, right?)

Notes

No response

Version

cargo 1.96.0-nightly (90ed291a5 2026-03-05)
release: 1.96.0-nightly
commit-hash: 90ed291a50efc459e0c380d7b455777ed41c6799
commit-date: 2026-03-05
host: aarch64-apple-darwin
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.7.1 (sys:0.4.83+curl-8.15.0 system ssl:(SecureTransport) LibreSSL/3.3.6)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Mac OS 26.3.0 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-gitArea: anything dealing with gitC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.regression-from-stable-to-stableRegression in stable that worked in a previous stable release.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions