fix: never use a read-only pull mirror as origin

`grove add` repoints an origin that is a Gitea/GitHub pull mirror to the
mirror's writable source (on a configured provider) and fetches it;
`grove import` clones the source instead of the mirror, keeping the
mirror's name and refusing a visibility mismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Opus 5.5 committed 2026-11-16 21:11:24 +01:00
1 parent f150f778c3
commit 6720390e3f
7 files changed
+123 -3

No files matched your search

+5
View File
@@ -32,6 +32,11 @@ fn repo(v: &Value) -> RemoteRepo {
clone_url: s("clone_url"),
ssh_url: s("ssh_url"),
default_branch: v["default_branch"].as_str().unwrap_or("main").to_string(),
mirror_of: v["mirror"]
.as_bool()
.unwrap_or(false)
.then(|| s("original_url"))
.filter(|u| !u.is_empty()),
}
}
+4
View File
@@ -31,6 +31,10 @@ fn repo(v: &Value) -> RemoteRepo {
clone_url: v["clone_url"].as_str().unwrap_or_default().to_string(),
ssh_url: v["ssh_url"].as_str().unwrap_or_default().to_string(),
default_branch: v["default_branch"].as_str().unwrap_or("main").to_string(),
mirror_of: v["mirror_url"]
.as_str()
.filter(|u| !u.is_empty())
.map(str::to_string),
}
}
+2
View File
@@ -57,6 +57,8 @@ pub struct RemoteRepo {
/// SSH clone URL (empty when the forge did not report one).
pub ssh_url: String,
pub default_branch: String,
/// Where the repo is mirrored from when it is a read-only pull mirror (pushes are refused).
pub mirror_of: Option<String>,
}
impl RemoteRepo {
+21
View File
@@ -367,6 +367,27 @@ fn get_repo_reports_visibility_on_both_forges() {
);
}
#[test]
fn pull_mirrors_report_their_source() {
let (url, _rx) = mock(vec![
(
200,
r#"{"name":"r","private":false,"mirror":true,"original_url":"https://github.com/o/r","owner":{"login":"o"}}"#,
),
(
200,
r#"{"name":"r","private":false,"mirror":false,"original_url":"https://github.com/o/r","owner":{"login":"o"}}"#,
),
]);
let g = Gitea::new(ProviderKind::Gitea, &url, "t".into());
assert_eq!(
g.get_repo("o", "r").unwrap().mirror_of.as_deref(),
Some("https://github.com/o/r")
);
// A migrated (no longer mirroring) repo keeps `original_url` but is writable.
assert_eq!(g.get_repo("o", "r").unwrap().mirror_of, None);
}
const REPO_A: &str = r#"{"name":"a","private":false,"clone_url":"https://h/o/a.git","ssh_url":"git@h:o/a.git","default_branch":"main","owner":{"login":"Org"}}"#;
const REPO_B: &str = r#"{"name":"b","private":true,"clone_url":"https://h/me/b.git","ssh_url":"ssh://gitea@h:2222/me/b.git","default_branch":"main","owner":{"login":"me"}}"#;
const REPO_C: &str = r#"{"name":"c","private":true,"clone_url":"https://h/x/c.git","ssh_url":"","default_branch":"main","owner":{"login":"x"}}"#;