Skip to content

fix(git): convert SCP-like submodule URLs to ssh:// format#16727

Merged
weihanglo merged 2 commits intorust-lang:masterfrom
cibil47:fix/scp-like-submodule
Mar 12, 2026
Merged

fix(git): convert SCP-like submodule URLs to ssh:// format#16727
weihanglo merged 2 commits intorust-lang:masterfrom
cibil47:fix/scp-like-submodule

Conversation

@cibil47
Copy link
Contributor

@cibil47 cibil47 commented Mar 10, 2026

What does this PR try to resolve?

PR #16246 introduced a regression where submodules using SCP-like URLs fail because child_remote_url.into_url() requires WHATWG-parsable URLs.

This commit fixes the issue by detecting SCP-like URLs in absolute_submodule_url() and converting them to the equivalent ssh:// format.

How to test and review this PR?

  1. Add a dependency to Cargo.toml and configure the dependency repository to pull its submodules using the following .gitmodules entry:
[submodule "common/path/apis"]
	path = third_party/apis
	url = git@github.com:common/apis.git
  1. cargo fetch should succeed

@rustbot rustbot added A-git Area: anything dealing with git S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 10, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 10, 2026

r? @weihanglo

rustbot has assigned @weihanglo.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ehuss, @epage, @weihanglo
  • @ehuss, @epage, @weihanglo expanded to ehuss, epage, weihanglo
  • Random selection from ehuss, epage, weihanglo

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking a stab. This is indeed a regression.

Since Cargo doesn't support SCP-like git dependency URL in Cargo.toml, this case was overlooked. However, libgit2 supports SCP-like URL, so we should follow if it is in .gitmodules not in Cargo.toml. I think it is fine we scope this for supporting submodule only. For general SCP-like URL support, we track in #1851.

@weihanglo weihanglo added the regression-from-stable-to-stable Regression in stable that worked in a previous stable release. label Mar 11, 2026
@cibil47 cibil47 force-pushed the fix/scp-like-submodule branch from 55580eb to 22c81c7 Compare March 11, 2026 18:36
@cibil47 cibil47 requested a review from weihanglo March 11, 2026 18:48
@cibil47
Copy link
Contributor Author

cibil47 commented Mar 11, 2026

@weihanglo One task failed because the CI runner was unable to verify the SSH host key. I could disable host key checking inside the test case using the GIT_SSH_COMMAND environment variable, but I am not sure if that is the right way to fix this. What is your suggestion?

@weihanglo
Copy link
Member

@weihanglo One task failed because the CI runner was unable to verify the SSH host key. I could disable host key checking inside the test case using the GIT_SSH_COMMAND environment variable, but I am not sure if that is the right way to fix this. What is your suggestion?

Sure, we could try it. The best case is that we don't need to diverge our snapshot based on different platforms. The other alternative here would be we only run this test on certain platform that is guaranteed to pass.

@cibil47 cibil47 force-pushed the fix/scp-like-submodule branch from 22c81c7 to 8afd44e Compare March 11, 2026 22:39
cibil47 added 2 commits March 11, 2026 23:41
Signed-off-by: Cibil Pankiras <cibil.pankiras@egym.com>
PR rust-lang#16246 introduced a regression where submodules using SCP-like URLs
fail because `child_remote_url.into_url()` requires WHATWG-parsable URLs.

This commit fixes the issue by detecting SCP-like URLs in `absolute_submodule_url()`
and converting them to the equivalent `ssh://` format.

Signed-off-by: Cibil Pankiras <cibil.pankiras@egym.com>
@cibil47 cibil47 force-pushed the fix/scp-like-submodule branch from 8afd44e to dbb2b56 Compare March 11, 2026 22:44
@cibil47
Copy link
Contributor Author

cibil47 commented Mar 11, 2026

Sure, we could try it. The best case is that we don't need to diverge our snapshot based on different platforms. The other alternative here would be we only run this test on certain platform that is guaranteed to pass.

I updated the commit, and the test case now passes on all platforms

Copy link
Member

@weihanglo weihanglo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working with us!

One thing to note that the path semantic is a bit different between the two forms

  • In SCP-like git@host:path/repo.git, path is relative to the user's home directory (~git/path/repo.git)
  • In SSH 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.

That said, this conversion is as same as the suggestion in IntoUrl::into_url, and also this is a regression already a hard error, so this change is still better than nothing.

We may probably want a way to track the original Git submodule URL and use that during fetching, if possible.

View changes since this review

@weihanglo weihanglo added this pull request to the merge queue Mar 11, 2026
Merged via the queue into rust-lang:master with commit 17627c4 Mar 12, 2026
29 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 12, 2026
github-merge-queue bot pushed a commit that referenced this pull request Mar 13, 2026
## What does this PR try to resolve?

This is a follow-up of #16727 to fix more edge cases.

This decouples the fetch URL from the `SourceId` URL for submodules:

* The conversion only happens in `update_submodule`
  for creating a `SourceId`, which requires a WHATWG URL.
* The original URL is preserved in `GitRemote`
  and used for the actual git fetch and user-facing messages.

Fixes #16740

## How to test and review this PR?

Commit by commit.

However, there is still a limitation about cache collision.
See
<#16740 (comment)>
rust-bors bot pushed a commit to rust-lang/rust that referenced this pull request Mar 13, 2026
Update cargo submodule

21 commits in 90ed291a50efc459e0c380d7b455777ed41c6799..cbb9bb8bd0fb272b1be0d63a010701ecb3d1d6d3
2026-03-05 15:11:25 +0000 to 2026-03-13 14:34:16 +0000
- fix(git): preserve SCP-like submodule URLs for fetch (rust-lang/cargo#16744)
- Fix 16732 (rust-lang/cargo#16746)
- fix(rustdoc): switch to new `--emit` options (rust-lang/cargo#16739)
- fix(git): convert SCP-like submodule URLs to ssh:// format (rust-lang/cargo#16727)
- fix(core): typo (rust-lang/cargo#16738)
- CARGO_TARGET_DIR doesn't have to be relative (rust-lang/cargo#16735)
- chore(ci): Detect user changes to src/etc/man (rust-lang/cargo#16736)
- util: Exclude from iCloud Drive sync on macOS (rust-lang/cargo#16728)
- fix(compile): Stop on denying warnings without --keep-going  (rust-lang/cargo#16725)
- feat(shell): Support OSC 9;4 progress on ptyxis (rust-lang/cargo#16730)
- Let git decide when to run gc (rust-lang/cargo#16459)
- chore(deps): update cargo-semver-checks to v0.47.0 (rust-lang/cargo#16723)
- fix(compile): Turn warning summaries into errors also (rust-lang/cargo#16721)
- fix(fix): Switch from ad-hoc to structured warnings (rust-lang/cargo#16711)
- fix: ignore implicit std dependencies in `unused-crate-dependencies` lint (rust-lang/cargo#16677)
- chore(deps): update msrv (3 versions) to v1.92 (rust-lang/cargo#16716)
- chore(deps): update msrv (1 version) to v1.94 (rust-lang/cargo#16710)
- fix(script): surpress `unused_features` lint for embedded (rust-lang/cargo#16714)
- Split `build-dir` lock into dedicated lock  (rust-lang/cargo#16708)
- Add missing truncate when writing .crate files (rust-lang/cargo#16688)
- refactor(fix): Prep for annotate-snippets (rust-lang/cargo#16702)
@rustbot rustbot added this to the 1.96.0 milestone Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-git Area: anything dealing with git regression-from-stable-to-stable Regression in stable that worked in a previous stable release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants