Fix submodule URL resolution for JihuLab esp-mirror (EIM-885)#913
Fix submodule URL resolution for JihuLab esp-mirror (EIM-885)#913ceerqingtingml wants to merge 1 commit into
Conversation
Relative submodule paths in .gitmodules are defined against the GitHub layout. Resolving them directly against a mirror parent URL drops the esp-mirror prefix (e.g. esp32-bt-lib becomes jihulab.com/espressif/... instead of jihulab.com/esp-mirror/espressif/...). Resolve relative URLs against the logical GitHub parent, then rewrite to the mirror prefix (equivalent to git url.insteadOf). Apply the same behavior in the git CLI fallback path and add unit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
Code Review
This pull request introduces support for an optional GitHub mirror prefix when cloning repositories and updating submodules. It adds helper functions to rewrite URLs to and from the mirror, configures local git settings using insteadOf, and updates the submodule update logic to resolve relative URLs correctly. The review feedback suggests robustly handling trailing slashes when comparing mirror URLs to the default GitHub URL across several helper functions, and using prefix-based replacement instead of global string replacement in apply_github_mirror to prevent accidental replacements elsewhere in the URL.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if mirror == "https://github.com" { | ||
| return url.to_string(); | ||
| } | ||
| let mirror_prefix = format!("{}/", mirror.trim_end_matches('/')); |
There was a problem hiding this comment.
Normalizing the mirror URL by trimming trailing slashes before comparing it to "https://github.com" makes the check robust. If mirror is configured with a trailing slash (e.g., "https://github.com/"), the current check will evaluate to false, leading to redundant string formatting and replacement operations.
let mirror_base = mirror.trim_end_matches('/');
if mirror_base == "https://github.com" {
return url.to_string();
}
let mirror_prefix = format!("{}/", mirror_base);| if mirror == "https://github.com" { | ||
| return url.to_string(); | ||
| } | ||
| let mirror_base = mirror.trim_end_matches('/'); | ||
| let mirror_prefix = format!("{}/", mirror_base); | ||
| url.replace("https://github.com/", &mirror_prefix) | ||
| .replace("https://github.com", mirror_base) |
There was a problem hiding this comment.
Using global replace on the URL can lead to unexpected bugs if the string "https://github.com/" or "https://github.com" appears elsewhere in the URL (for example, in a repository name, branch name, or path). It is much safer to only replace the prefix at the start of the URL using starts_with and replacen with a limit of 1, similar to how reverse_github_mirror is implemented. Additionally, normalizing the mirror URL by trimming trailing slashes first ensures that the GitHub check is robust.
let mirror_base = mirror.trim_end_matches('/');
if mirror_base == "https://github.com" {
return url.to_string();
}
let mirror_prefix = format!("{}/", mirror_base);
if url.starts_with("https://github.com/") {
url.replacen("https://github.com/", &mirror_prefix, 1)
} else if url == "https://github.com" {
mirror_base.to_string()
} else {
url.to_string()
}| if mirror == "https://github.com" { | ||
| return None; | ||
| } | ||
| let mirror_prefix = format!("{}/", mirror.trim_end_matches('/')); |
There was a problem hiding this comment.
Normalize the mirror URL by trimming trailing slashes before comparing it to "https://github.com" to ensure that a mirror configured as "https://github.com/" is correctly identified and skipped, avoiding the generation of redundant git config pairs.
let mirror_base = mirror.trim_end_matches('/');
if mirror_base == "https://github.com" {
return None;
}
let mirror_prefix = format!("{}/", mirror_base);
Description
Fix incorrect submodule URL resolution when using the JihuLab mirror (
https://jihulab.com/esp-mirror).Relative paths in
.gitmodules(e.g.../../espressif/esp32-bt-lib.git) were resolved against the mirror parent URL, which dropped theesp-mirrorprefix and produced incorrect URLs likehttps://jihulab.com/espressif/esp32-bt-lib.gitinstead ofhttps://jihulab.com/esp-mirror/espressif/esp32-bt-lib.git.This PR resolves relative URLs against the logical GitHub parent URL first, then rewrites to the mirror prefix — equivalent to
git config url.https://jihulab.com/esp-mirror/.insteadOf https://github.com/. The same behavior is applied in the gix submodule path and the git CLI fallback path. Unit tests are included.Related
N/A (no existing issue filed)
Testing
cargo test mirror_url_tests --libinsrc-tauri/idf_mirror = "https://jihulab.com/esp-mirror":esp32-bt-libresolves tohttps://jihulab.com/esp-mirror/espressif/esp32-bt-lib.gitand submodules fetch successfullyChecklist