feat: owner-scoped import listing, ssh protocol, robust import

- providers: list_owner_repos (org/user endpoints), ssh_url, Send+Sync
- import: parallel sides, case-insensitive/origin-based presence check,
  continue after failed clones and report them
- config: per-provider protocol (https|ssh); GUI settings, onboarding
- gui: import scan on its own thread, per-group cache, Rescan, failures

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
dasemuandClaude Sonnet 5.5 committed 2026-11-16 18:09:34 +01:00
1 parent 5aeb7b2077
commit 28e07aab56
14 files changed
+580 -119

No files matched your search

+1
View File
@@ -97,6 +97,7 @@ fn flag_spec(sub: &str) -> (&'static [&'static str], &'static [&'static str]) {
"--root",
"--provider",
"--kind",
"--protocol",
"--group",
"--config-repo",
"--url",
+71 -33
View File
@@ -126,6 +126,10 @@ struct UiState {
filter: String,
pending: Option<Vec<String>>,
picks: Rc<VecModel<Pick>>,
/// Last successful scan per import group, for the session (names still to import).
import_cache: HashMap<String, Vec<String>>,
/// The group whose scan the list on screen belongs to.
import_current: String,
toast_gen: u32,
last_groups: Vec<String>,
last_providers: Vec<String>,
@@ -142,6 +146,8 @@ thread_local! {
filter: String::new(),
pending: None,
picks: Rc::new(VecModel::default()),
import_cache: HashMap::new(),
import_current: String::new(),
toast_gen: 0,
last_groups: Vec::new(),
last_providers: Vec::new(),
@@ -499,41 +505,67 @@ fn out(ok: bool, text: String) -> Out {
}
}
fn scan(ctx: &Ctx, ui: &MainWindow, group: String) {
ui.set_import_note("Scanning…".into());
fn show_picks(ui: &MainWindow, names: Vec<String>, note: Option<String>) {
let empty = names.is_empty();
ST.with(|st| {
st.borrow().picks.set_vec(
names
.into_iter()
.map(|n| Pick {
name: n.into(),
checked: false,
})
.collect::<Vec<_>>(),
)
});
ui.set_import_scanned(true);
ui.set_import_note(match note {
Some(n) => n.into(),
None if empty => {
"Nothing to import: every remote repository is already on this machine.".into()
}
None => "".into(),
});
}
/// Lists the group's remote repos still to import. The scan runs on its own thread (never queued
/// behind status polling) and its result is cached per group; `force` rescans.
fn scan(ctx: &Ctx, ui: &MainWindow, group: String, force: bool, note: Option<String>) {
ST.with(|st| st.borrow_mut().import_current = group.clone());
ui.set_import_out(out(true, String::new()));
if !force && let Some(names) = ST.with(|st| st.borrow().import_cache.get(&group).cloned()) {
show_picks(ui, names, note);
return;
}
ui.set_import_scanning(true);
ui.set_import_note("Scanning…".into());
ST.with(|st| st.borrow().picks.set_vec(vec![]));
run_cli(
ctx,
ui,
None,
vec!["import".into(), group],
String::new(),
|ui, ok, text| {
ui.set_import_note("".into());
let (core, weak) = (ctx.core.clone(), ctx.weak.clone());
std::thread::spawn(move || {
let r = core.bridge.cli(&["import".to_string(), group.clone()], "");
let ok = r["ok"] == true;
let text = r["output"].as_str().unwrap_or("").to_string();
let _ = slint::invoke_from_event_loop(move || {
let Some(ui) = weak.upgrade() else { return };
ui.set_import_scanning(false);
if !ok {
ui.set_import_note("".into());
ui.set_import_out(out(false, text));
return;
}
let names = model::parse_import_listing(&text);
if names.is_empty() {
ui.set_import_note(
"Nothing to import: every remote repository is already on this machine.".into(),
);
}
ST.with(|st| {
st.borrow().picks.set_vec(
names
.into_iter()
.map(|n| Pick {
name: n.into(),
checked: false,
})
.collect::<Vec<_>>(),
)
st.borrow_mut()
.import_cache
.insert(group.clone(), names.clone())
});
},
);
if ST.with(|st| st.borrow().import_current == group) {
show_picks(&ui, names, note);
} else {
ui.set_import_note("".into());
}
});
});
}
fn first_or(v: &str, list: &ModelRc<SharedString>) -> String {
@@ -604,10 +636,10 @@ fn wire(ui: &MainWindow, ctx: &Ctx) {
ui.on_scan_import({
let c = ctx.clone();
move |group| {
move |group, force| {
let Some(ui) = c.weak.upgrade() else { return };
let group = model::group_name(&first_or(group.as_str(), &ui.get_groups())).to_string();
scan(&c, &ui, group);
scan(&c, &ui, group, force, None);
}
});
ui.on_pick_toggled(|i, checked| {
@@ -639,10 +671,14 @@ fn wire(ui: &MainWindow, ctx: &Ctx) {
args.extend(picked);
let c2 = c.clone();
run_cli(&c, &ui, None, args, String::new(), move |ui, ok, text| {
ui.set_import_out(out(ok, text));
if ok {
scan(&c2, ui, group);
}
ui.set_import_out(out(ok, text.clone()));
// Rescan either way: what was cloned must leave the list.
let failed = model::parse_import_failures(&text);
let note = (!failed.is_empty()).then(|| {
toast(ui, &format!("{} import(s) failed", failed.len()), true);
format!("Failed to import: {}", failed.join(", "))
});
scan(&c2, ui, group, true, note);
});
}
});
@@ -790,7 +826,7 @@ fn wire(ui: &MainWindow, ctx: &Ctx) {
ui.on_onboard({
let c = ctx.clone();
move |machine, root, kind, provider, url, group, crepo, token| {
move |machine, root, kind, protocol, provider, url, group, crepo, token| {
let Some(ui) = c.weak.upgrade() else { return };
let mut init: Vec<String> = [
"init",
@@ -802,6 +838,8 @@ fn wire(ui: &MainWindow, ctx: &Ctx) {
&provider,
"--kind",
&kind,
"--protocol",
&protocol,
"--group",
&group,
"--config-repo",
+25 -4
View File
@@ -196,6 +196,15 @@ pub fn parse_import_listing(output: &str) -> Vec<String> {
names
}
/// Repository names of the `FAILED <name>: <reason>` lines `grove import` prints per failed clone.
pub fn parse_import_failures(output: &str) -> Vec<String> {
output
.lines()
.filter_map(|l| l.strip_prefix("FAILED "))
.filter_map(|l| l.split_once(':').map(|(n, _)| n.trim().to_string()))
.collect()
}
fn names(v: Option<&Value>) -> Vec<String> {
v.and_then(Value::as_array)
.map(|a| {
@@ -288,7 +297,12 @@ pub fn settings_sections(cfg: &Value) -> Vec<Section> {
} else {
format!(" · {url}")
};
(id.clone(), format!("{}{url}", str_of(p, "kind")))
// `protocol` is how git talks to the forge; https when the key is absent.
let proto = match str_of(p, "protocol") {
"" => "https",
p => p,
};
(id.clone(), format!("{} · {proto}{url}", str_of(p, "kind")))
})
.collect()
})
@@ -405,6 +419,13 @@ mod tests {
assert!(parse_import_listing("nothing to import").is_empty());
}
#[test]
fn failed_imports_are_listed() {
let out = "imported a -> /x/a\nFAILED b: git clone failed: boom\nFAILED c: nope";
assert_eq!(parse_import_failures(out), ["b", "c"]);
assert!(parse_import_failures("imported a").is_empty());
}
#[test]
fn outputs_are_dropped_when_the_state_changes() {
let rec = |t: &str| OutRec {
@@ -453,7 +474,7 @@ mod tests {
fn settings_show_public_route_and_owners() {
let cfg = json!({
"machine": {"name": "pca"}, "root": {"path": "/w"},
"providers": {"gitea": {"kind": "gitea", "url": "https://g.example"}, "gh": {"kind": "github"}},
"providers": {"gitea": {"kind": "gitea", "protocol": "ssh", "url": "https://g.example"}, "gh": {"kind": "github"}},
"groups": [{"name": "work", "primary": "gitea", "mirror_to": ["gh"],
"owners": {"gitea": "Org", "gh": "org-gh"},
"snapshots": "none",
@@ -468,8 +489,8 @@ mod tests {
("Snapshots (default)".into(), "private-only".into())
);
// Providers come out sorted by id.
assert_eq!(s[1].1[0].1, "github");
assert_eq!(s[1].1[1].1, "gitea · https://g.example");
assert_eq!(s[1].1[0].1, "github · https");
assert_eq!(s[1].1[1].1, "gitea · ssh · https://g.example");
assert_eq!(
s[2].1[0].1,
"primary gitea · mirrors: gh · public: gh → gitea · snapshots: none · owners: gh=org-gh, gitea=Org · bare-worktrees"