Skip to content

Cargo does not normalize relative urls for submodules in ssh git dependencies #12404

@liss-h

Description

@liss-h

Problem

Github does not like relative repository names if you use ssh to download repositories.
I.e. according to github the following is not a valid url to fetch a repo: ssh://git@github.com/owner/repo/../sub
Cargo does not normalize such relative paths for submodules and therefore fails to fetch the submodule if using ssh.

Steps

If you have a crate that depends on a git repo via ssh. E.g.

Cargo.toml

crate = { git = "ssh://git@github.com/owner/repo" }

And that repo has a submodule specified with a relative path. E.g.

.gitmodules

[submodule "sub"]
    path = sub
    url = ../sub

Cargo is not able to fetch the submodule because it doesn't normalize the path; github doesn't like that.
Cargo tries the following:

Updating git repository `ssh://git@github.com/owner/repo`
Updating git submodule `ssh://git@github.com/owner/repo/../sub`

Github then throws an error because owner/repo/../sub is not a valid repository name.

Btw, if you enter this manually in the commandline, i.e. git clone ssh://git@github.com/owner/repo/../sub it doesn't work either, but it does work with http, seems to be a github server-side thing, although I don't know if this is indended or not. Git itself seems to do this normalization so relative submodules using ssh work fine there.

Possible Solution(s)

I guess normalize the repo path if using ssh and hope nothing breaks 😅

Notes

No response

Version

cargo 1.73.0-nightly (7ac9416d8 2023-07-24)
release: 1.73.0-nightly
commit-hash: 7ac9416d82cd4fc5e707c9ec3574d22dff6466e5
commit-date: 2023-07-24
host: x86_64-unknown-linux-musl
libgit2: 1.6.4 (sys:0.17.2 vendored)
libcurl: 8.1.2-DEV (sys:0.4.63+curl-8.1.2 vendored ssl:OpenSSL/1.1.1u)
ssl: OpenSSL 1.1.1u  30 May 2023
os: Alpine Linux 3.17.4 [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-gitArea: anything dealing with gitC-bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or reviewregression-from-stable-to-betaRegression in beta that previously worked in stable.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions