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:
1 parent
1a7e606d39
commit
a87db8433c
1 file changed
+13
-6
@@ -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), .. } => {
|
||||||
let display = if value.trim().is_empty() {
|
// `ri` was captured when the modal opened; a background refresh
|
||||||
state.repos[ri].path.file_name().unwrap_or_default().to_string_lossy().to_string()
|
// (bulk import / create-repo / profile-pull all replace
|
||||||
} else { value.clone() };
|
// `state.repos` wholesale) may have completed since then, so this
|
||||||
state.repos[ri].name = display.clone();
|
// must degrade gracefully instead of indexing straight in.
|
||||||
let _ = crate::labels::save_label(&state.repos[ri].path.clone(), &value, &state.workspace_root);
|
if let Some(repo) = state.repos.get(ri) {
|
||||||
state.rebuild_display();
|
let display = if value.trim().is_empty() {
|
||||||
|
repo.path.file_name().unwrap_or_default().to_string_lossy().to_string()
|
||||||
|
} else { value.clone() };
|
||||||
|
let path = repo.path.clone();
|
||||||
|
state.repos[ri].name = display;
|
||||||
|
let _ = crate::labels::save_label(&path, &value, &state.workspace_root);
|
||||||
|
state.rebuild_display();
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user