fix: guard label-rename against a stale repo index

A background refresh (bulk-import/create-repo/profile-pull all replace
state.repos wholesale) could complete while the 'Set label' modal was
still open, so its captured index either panicked (out-of-bounds) or
silently relabeled the wrong repo. Now degrades gracefully via .get().
This commit is contained in:
dualfroz committed 2026-07-23 07:24:27 +02:00
1 parent 1a7e606d39
commit a87db8433c
1 file changed
+10 -3
+10 -3
View File
@@ -13,12 +13,19 @@ use crate::todos::{self, Todo, TodoStatus};
pub fn try_confirm(state: &mut HubState, modal: Modal) -> Option<Modal> { pub fn try_confirm(state: &mut HubState, modal: Modal) -> Option<Modal> {
match modal { match modal {
Modal::Text { value, tag: TextTag::Label(ri), .. } => { Modal::Text { value, tag: TextTag::Label(ri), .. } => {
// `ri` was captured when the modal opened; a background refresh
// (bulk import / create-repo / profile-pull all replace
// `state.repos` wholesale) may have completed since then, so this
// must degrade gracefully instead of indexing straight in.
if let Some(repo) = state.repos.get(ri) {
let display = if value.trim().is_empty() { let display = if value.trim().is_empty() {
state.repos[ri].path.file_name().unwrap_or_default().to_string_lossy().to_string() repo.path.file_name().unwrap_or_default().to_string_lossy().to_string()
} else { value.clone() }; } else { value.clone() };
state.repos[ri].name = display.clone(); let path = repo.path.clone();
let _ = crate::labels::save_label(&state.repos[ri].path.clone(), &value, &state.workspace_root); state.repos[ri].name = display;
let _ = crate::labels::save_label(&path, &value, &state.workspace_root);
state.rebuild_display(); state.rebuild_display();
}
None None
} }