{"record":{"id":"1158ce66f5a1019e","repo":"GitoxideLabs/gitoxide","slug":"copy-insert-requires-a-worktree","errorCode":null,"errorMessage":"copy-insert requires a worktree","messagePattern":"copy-insert requires a worktree","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"gix-tix/src/lib.rs","lineNumber":2093,"sourceCode":"                                    distance += 1;\n                                }\n                                next => {\n                                    pending_terminal_event = Some(next);\n                                    break;\n                                }\n                            }\n                        }\n                    }\n                    let Some(action) = mouse_scroll_action(kind, modifiers, distance, app.changes_focus.is_some())\n                    else {\n                        continue;\n                    };\n                    let repeats_history = app.changes_focus.is_none() && repeats_viewport(&action);\n                    (Some(action), repeats_history, true, true)\n                }\n                TerminalEvent::Paste(pasted) => {\n                    let action = (|| {\n                        anyhow::ensure!(!repository_is_bare, \"copy-insert requires a worktree\");\n                        let target = app\n                            .paste_insert_target()\n                            .context(\"copy-insert paste requires an editable history selection\")?;\n                        let repository = open_repository(&repository_path, repository_is_bare, false)\n                            .context(\"could not open repository for pasted commit\")?;\n                        let source = resolve_pasted_commit(&repository, &pasted)?;\n                        Ok::<_, anyhow::Error>(Action::PasteInsert { source, target })\n                    })();\n                    match action {\n                        Ok(action) => (Some(action), false, false, false),\n                        Err(err) => {\n                            app.leave_attention(format!(\"paste: {err:#}\"));\n                            dirty = true;\n                            urgent = true;\n                            continue;\n                        }\n                    }\n                }","sourceCodeStart":2075,"sourceCodeEnd":2111,"githubUrl":"https://github.com/GitoxideLabs/gitoxide/blob/e73179060badf27222d790981fac3f84c1830a7e/gix-tix/src/lib.rs#L2075-L2111","documentation":"The paste-insert feature inserts a pasted commit into history, which requires a writable working tree to check out and modify files. When the application was started against a bare repository, `anyhow::ensure!` aborts the paste handler with this message.","triggerScenarios":"Pasting (TerminalEvent::Paste) while `repository_is_bare` is true; the app's paste-insert path calls `open_repository`/`resolve_pasted_commit` only after this guard, so any paste action in a bare-repo session hits it.","commonSituations":"Running the TUI against `--bare` repos or `~/.git` style metadata dirs; remote-style repositories opened locally without a worktree; users expecting paste to work like a non-worktree commit amendment.","solutions":["Open the repository with an associated worktree (non-bare clone) before using paste-insert.","Use a different editing action that works without a worktree (e.g. pure history rewrite APIs), if available.","Check how the app was launched: pass a worktree checkout path, not the bare repo dir."],"exampleFix":"// before\nlet action = (|| {\n    anyhow::ensure!(!repository_is_bare, \"copy-insert requires a worktree\");\n// after\nif repository_is_bare {\n    eprintln!(\"paste-insert unavailable in a bare repository\");\n    return Ok(Action::None);\n}\nlet action = (|| {\n    anyhow::ensure!(!repository_is_bare, \"copy-insert requires a worktree\");","handlingStrategy":"validation","validationCode":"if repository_is_bare {\n    eprintln!(\"paste-insert requires a non-bare repository with a worktree\");\n    return;\n}","typeGuard":"fn has_worktree(repo: &gix::Repository) -> bool { repo.work_dir().is_some() }","tryCatchPattern":"match paste_action() {\n    Err(e) if e.to_string().contains(\"requires a worktree\") => show_unavailable_notice(),\n    Err(e) => return Err(e),\n    Ok(v) => v,\n}","preventionTips":["Disable paste-insert UI affordances when the session repository is bare.","Check `repo.work_dir()` at startup and record capability flags.","Document that history-editing operations needing checkout require a worktree."],"tags":["git","bare-repository","worktree"],"backgroundTag":"unsupported-operation","analyzedSha":"e73179060badf27222d790981fac3f84c1830a7e","analyzedAt":"2026-09-08T11:26:50.865Z","contentChangedAt":"2026-09-08T11:26:50.865Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}